Fotmob - JSON Data Pull

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

});