Fotmob - JSON Data Pull

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);

});