Fotmob - JSON Data Pull

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

});