vivalemuc / FUTBIN - Vivalemuc Advanced List with error price

// ==UserScript==
// @name        FUTBIN - Vivalemuc Advanced List with error price
// @version     1.0.1
// @description Advanced mode from player list
// @license     MIT
// @author      Vivalemuc
// @match       https://www.futbin.com/players*
// @match       https://www.futbin.com/22/players*

// @grant       none
// ==/UserScript==

(function() {
    'use strict';
        var divPrice = document.createElement('div');

    var a = document.createElement('button');
     // Create the text node for anchor element.
    var link = document.createTextNode("PS advanced");
    // Append the text node to anchor element.
    a.appendChild(link);
    a.setAttribute('onclick','createCsv("PS");'); // for FF
    a.onclick = function() {createCsv("PS");}; // for IE
    a.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');


    var aX = document.createElement('button');
     // Create the text node for anchor element.
    var linkX = document.createTextNode("XB advanced");
    // Append the text node to anchor element.
    aX.appendChild(linkX);
    aX.setAttribute('onclick','createCsv("XB");'); // for FF
    aX.onclick = function() {createCsv("XB");}; // for IE
    aX.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');

    var aP = document.createElement('button');
    // Create the text node for anchor element.
    var linkP = document.createTextNode("PC advanced");
    // Append the text node to anchor element.
    aP.appendChild(linkP);
    aP.setAttribute('onclick','createCsv("PC");'); // for FF
    aP.onclick = function() {createCsv("PC");}; // for IE
    aP.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');
    divPrice.appendChild(aP);
    divPrice.appendChild(aX);
    divPrice.appendChild(a);
    $('.row.mb-2')[0].style="flex-direction: column-reverse;align-items: start;";
       function createCsv(platform){
        const queryString =window.location.search;
        const urlParams = new URLSearchParams(queryString);
        const page = urlParams.get('page')
        var ids = "";

        var rows = $(".table.table-bordered.table-hover tbody").find('tr').each(function( index ) {
            ids+=$($(this)[0]).find('.player_name_players_table')[0].dataset.siteId;
            ids+=",";
        });

           var futbinIds = ids.slice(0, -1);

        var link = document.createElement('a');
        link.id = 'getAdvanced-'+platform+'-'+Date.now();

        link.setAttribute('target', '_blank');
        link.setAttribute('href', 'https://vivalemuc.vercel.app/api/futbinInfo?futbinId='+futbinIds+'&platform='+platform);
        document.body.appendChild(link);
        document.querySelector('#'+link.id).click();

    }

          $('.row.mb-2')[0].prepend(divPrice);

    var divError = document.createElement('div');

    var aPrice = document.createElement('button');
    // Create the text node for anchor element.
    var linkPrice = document.createTextNode("Error price PS");
    // Append the text node to anchor element.
    aPrice.appendChild(linkPrice);
    aPrice.setAttribute('onclick','errorPrice("PS);'); // for FF
    aPrice.onclick = function() {errorPrice("PS");}; // for IE
    aPrice.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');
    var aPriceX = document.createElement('button');
    // Create the text node for anchor element.
    var linkPriceX = document.createTextNode("Error price XB");
    // Append the text node to anchor element.
    aPriceX.appendChild(linkPriceX);
    aPriceX.setAttribute('onclick','errorPrice("XB");'); // for FF
    aPriceX.onclick = function() {errorPrice("XB");}; // for IE
    aPriceX.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');
var aPriceP = document.createElement('button');
    // Create the text node for anchor element.
    var linkPriceP = document.createTextNode("Error price PC");
    // Append the text node to anchor element.
    aPriceP.appendChild(linkPriceP);
    aPriceP.setAttribute('onclick','errorPrice("PC");'); // for FF
    aPriceP.onclick = function() {errorPrice("PC");}; // for IE
    aPriceP.setAttribute('class','btn-csv btn btn-sm btn-primary submit-comment waves-effect waves-light float-right');
    divError.appendChild(aPriceP);
    divError.appendChild(aPriceX);
    divError.appendChild(aPrice);








      $('.row.mb-2')[0].prepend(divError);


    function errorPrice(platform){

        var ids =[];

        var rows = $(".table.table-bordered.table-hover tbody").find('tr').each(function( index ) {
            ids+=$($(this)[0]).find('.player_name_players_table')[0].dataset.siteId;
            ids+=",";
        });


        var futbinIds = ids.slice(0, -1);

        var link = document.createElement('a');
        link.id = 'getError-'+Date.now();

        link.setAttribute('target', '_blank');
        link.setAttribute('href', 'https://vivalemuc.vercel.app/api/error?futbinId='+futbinIds+'&platform='+platform);
        document.body.appendChild(link);
        document.querySelector('#'+link.id).click();

    }

})();