Greasy Fork is available in English.

Fotmob - JSON Data Pull

5/16/2023, 11:54:48 AM

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Fotmob - JSON Data Pull
// @namespace    Violentmonkey Scripts
// @match        https://www.fotmob.com/match/*
// @author       Sertalp B. Cay
// @grant        none
// @version      0.1
// @license      MIT
// @description  5/16/2023, 11:54:48 AM
// @require      https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.21/jquery.csv.js
// ==/UserScript==

var $ = window.jQuery;

var saveAsFile = (filename, dataObjToWrite) => {
    const blob = new Blob([JSON.stringify(dataObjToWrite, null, 4)], { type: "application/json" });
    const link = document.createElement("a");

    link.download = filename;
    link.href = window.URL.createObjectURL(blob);
    link.dataset.downloadurl = ["text/json", link.download, link.href].join(":");

    const evt = new MouseEvent("click", {
        view: window,
        bubbles: true,
        cancelable: true,
    });

    link.dispatchEvent(evt);
    link.remove()
};


function download_as_json() {
  let json_data = JSON.parse(document.querySelector("#__NEXT_DATA__").innerText).props.pageProps;
  debugger;
  // data = JSON.stringify(params, null, 4);
  var filename = json_data.general.matchId
  saveAsFile(filename + ".json", json_data)
}

$(document).ready(function() {

  debugger;

  // add a button after MatchFactsWrapper
  let dv = document.createElement("div");
  dv.style = "text-align: center;"
  let btn = document.createElement("button");
  btn.innerHTML = "Download as JSON";
  btn.addEventListener("click", download_as_json);
  let e = document.querySelector("#MatchFactsWrapper");
  btn.style = "color: black; background-color: white; padding: 5px; margin: 5px; border: 1px solid black;"
  dv.append(btn);
  e.prepend(dv);

});