View revivability

Allow anyone to see if people can be revived.

Per 03-06-2022. Zie de nieuwste versie.

// ==UserScript==
// @name         View revivability
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Allow anyone to see if people can be revived.
// @author       olesien
// @match        https://www.torn.com/factions.php?step=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    //Note on api key: Use an api key from a friend that is not in a faction. Minimal access is fine. Person HAS to have the ability to revive.
    const apiKey = "INSERTAPIKEYHERE";
    const delay = 2000;
    let isRunning = false;
    const checkUser = async (row) => {
        const userElement = row.querySelector(".userStatusWrap___Kp2I9");
        console.log(userElement.id);
        const userId = Number(userElement.id.replace(/\D/g,''));
             fetch(`https://api.torn.com/user/${userId}?selections=&key=${apiKey}`)
   .then(response => response.json())
   .then(data => {
       if (data && "revivable" in data) {
           const revivable = data.revivable === 1;
           if (revivable) {
               row.style.backgroundColor = "rgba(176, 16, 16, 0.35)";
           } else {
              row.style.backgroundColor = "rgba(96, 176, 16, 0.35)";
           }
       } else {
           row.style.backgroundColor = "orange";
       }
   });
    }

    const start = setTimeout(() => {
        const rows = Array.from(document.querySelectorAll(".table-row"));

        const memberIconsEl = document.querySelector(".member-icons");
        console.log(rows);

        const element = document.createElement("button");
        element.innerText = "Check for revivability";
        memberIconsEl.appendChild(element);

        element.addEventListener('click', () => {
            if (isRunning) return;
           rows.forEach((row, index) => {
               isRunning = true;
              const timeout = setTimeout(() => {
                 checkUser(row);
                  if (index + 1 === rows.length) {
                     isRunning = false;
                  }
              }, delay * index)

        })
        })


    }, 2000)


})();