PatoCh

SoccerProject find captain

Apr 26th, 2021
516
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let highest_percentage = {value: 0, name: ""}
  2. const PLAYERS_MAX = 11
  3. let current_checked_players = 0
  4.  
  5. let observer = new MutationObserver(function (mutations) {
  6.     mutations.forEach(function (mutation) {
  7.         if (mutation.addedNodes.length) {
  8.             player_properties(mutation.addedNodes[0])
  9.         }
  10.     })
  11. })
  12.  
  13. Array.from(document.getElementsByTagName("tr"))
  14.     .filter(function(a) {
  15.         let tds = Array.from(a.children)
  16.         return a.id && tds.length > 1 && tds[1].className && tds[1].className !== "posSUB";
  17.     })
  18.     .forEach(function(tr) {
  19.         let id = tr.id.match(/[0-9]+/g)[0]
  20.         let properties = document.querySelector('#td_id_Player' + id)
  21.         let properties_table = properties.querySelector("table")
  22.         if (!properties_table) {
  23.             observer.observe(properties, {
  24.                 childList: true
  25.             });
  26.             getPlayer(id, 'id_Player')
  27.         } else {
  28.             player_properties(properties_table)
  29.         }
  30.        
  31.     })
  32.    
  33. function player_properties(node) {
  34.     let jersey_name = document.querySelector("#trPlayer" + node.parentNode.id.match(/[0-9]+/g)[0]).children[1].innerText
  35.     let name = jersey_name.match(/[0-9]+\. (.+)/)[1]
  36.     let percentage = parseInt(node.getElementsByTagName("td")[2].innerText)
  37.     if (percentage > highest_percentage["value"]) {
  38.         highest_percentage["value"] = percentage
  39.         highest_percentage["name"] = name
  40.     }
  41.     current_checked_players += 1
  42.     if (current_checked_players === PLAYERS_MAX) {
  43.         console.log("Captain should be " + highest_percentage["name"] + " (" + highest_percentage["value"] + "%)");
  44.     }
  45. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×