djizus / SDDDSDSDSDSDDSDDSDSDSDSDSSDDSDS

// ==UserScript==
// @name         SDDDSDSDSDSDDSDDSDSDSDSDSSDDSDS
// @version      1.3
// @description  Automate the sending of the SorareData GW projections
// @license      MIT
// @namespace    https://github.com/djizus
// @author       djizus
// @icon		 https://www.google.com/s2/favicons?domain=soraredata.com
// @match        https://www.soraredata.com/SO5Results/sections/community-lineups
// @match        https://soraredata.com/SO5Results/sections/community-lineups
// @match        https://www.soraredata.com/SO5-community-lineups
// @connect      data.mongodb-api.com
// @grant        GM_xmlhttpRequest
// @updateURL    https://openuserjs.org/meta/djizus/SDDDSDSDSDSDDSDDSDSDSDSDSSDDSDS.meta.js
// @downloadURL  https://openuserjs.org/install/djizus/SDDDSDSDSDSDDSDDSDSDSDSDSSDDSDS.user.js
// @copyright    2024, djizus (https://openuserjs.org/users/djizus)
// ==/UserScript==

(function() {
    'use strict';

    const apiKey = 'AElNvb1hmiOA4lhBRPNdZZgEcMLKhEAjeu2TDIIwSEmn0wkNOcFEazn2ywrmQK7B';

    function sendHttpRequest(data) {
        GM_xmlhttpRequest({
            method: "POST",
            url: "https://www.soraredata.com/projections-api/SO5/changeStartingStatus",
            headers: {
                "Content-Type": "application/json",
            },
            data: JSON.stringify(data),
            onload: function(response) {
                console.log(response.responseText);
            },
            onerror: function(error) {
                console.error(error);
            },
        });
    }

    function fetchDataFromAPI() {
        GM_xmlhttpRequest({
            method: "POST",
            url: "https://data.mongodb-api.com/app/data-qlzhh/endpoint/projections",
            headers: {
                "Content-Type": "application/json",
                "api-key": apiKey,
            },
            data: JSON.stringify({ foo: "bar" }),
            onload: function(response) {
                try {
                    const responseData = JSON.parse(response.responseText);
                    // Boucle à travers chaque élément du JSON
                    responseData.result.forEach(game => {
                        sendHttpRequest(game);
                    });
                    alert("Successfully uplodaded projections")
                } catch (error) {
                    console.error('Error parsing JSON:', error);
                }
            },
            onerror: function(error) {
                console.error('Request error:', error);
                return error;
            },
        });
    }

    // Fonction à exécuter lorsque le bouton est cliqué
    function onClickButton() {
        var predictions = fetchDataFromAPI();
    }

    // Créer le bouton
    var button = document.createElement('button');
    var br = document.createElement("br");
    button.innerHTML = 'Send 🤖 projections';
    button.addEventListener('click', onClickButton);
    button.class = 'text-base border-b-4 border-brand py-2 px-6 font-medium focus:outline-none';

    // Sélectionner la div spécifique
    var targetDiv = document.querySelector('.mb-8');

    // Ajouter le bouton à la div spécifique
    if (targetDiv) {
        targetDiv.appendChild(br);
        targetDiv.appendChild(button);
    }
})();