mz count players by age on other team's player pages

Count players by age on other teams' player pages

目前為 2023-06-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         mz count players by age on other team's player pages
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Count players by age on other teams' player pages
// @author       You
// @match        https://www.managerzone.com/?p=players&tid=*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  let ageCount = new Map();

  document
    .querySelectorAll("#players_container .playerContainer")
    .forEach((player) => {
      let ageElement = Array.from(player.querySelectorAll("td")).find((td) =>
        td.textContent.includes("Age:")
      );
      if (ageElement) {
        let age = parseInt(ageElement.textContent.replace("Age:", "").trim());

        if (ageCount.has(age)) {
          ageCount.set(age, ageCount.get(age) + 1);
        } else {
          ageCount.set(age, 1);
        }
      }
    });

  let filtersElement = document.querySelector("#player_filters");
  if (filtersElement) {
    let table = document.createElement("table");
    table.id = "ageTable";
    let thead = document.createElement("thead");
    let tbody = document.createElement("tbody");
    let headerRow = document.createElement("tr");
    let ageHeader = document.createElement("th");
    ageHeader.textContent = "Age";
    let countHeader = document.createElement("th");
    countHeader.textContent = "Count";
    headerRow.appendChild(ageHeader);
    headerRow.appendChild(countHeader);
    thead.appendChild(headerRow);
    table.appendChild(thead);

    let tableTitle = document.createElement("h2");
    tableTitle.textContent = "Player Age Count";
    tableTitle.style.textAlign = "left";
    tableTitle.style.color = "#FF1493";
    tableTitle.style.fontFamily = "Montserrat";
    filtersElement.appendChild(tableTitle);

    let entries = Array.from(ageCount.entries());
    entries.sort((a, b) => a[0] - b[0]);

    entries.forEach(([age, count]) => {
      let row = document.createElement("tr");
      let ageCell = document.createElement("td");
      ageCell.textContent = age;
      let countCell = document.createElement("td");
      countCell.textContent = count;
      row.appendChild(ageCell);
      row.appendChild(countCell);
      tbody.appendChild(row);
    });

    table.appendChild(tbody);
    filtersElement.appendChild(table);
  }
})();
GM_addStyle(`
  #ageTable {
      border-collapse: separate;
      border-spacing: 0;
      color: white;
      width: 30%;
  }

  #ageTable th,
  #ageTable td {
      padding: 5px 10px;
      color: white;  /* Adding this line to ensure white font */
  }

  #ageTable thead tr {
      background-color: #000080; /* Navy */
      color: #FFFF00; /* Yellow */
  }

  #ageTable tbody tr:nth-child(even) {
      background-color: #000080; /* Navy */
  }

  #ageTable tbody tr:nth-child(odd) {
      background-color: #FF1493; /* Pinky Red */
  }

  #ageTable tbody tr:hover {
      background-color: #00BFFF;
      color: black;
  }

  #ageTable th, #ageTable td {
      font-weight: normal;
      border: 1px solid #1E90FF;
      text-align: center;
  }

  #ageTable th {
      border-top: 2px solid #00BFFF;
      border-bottom: 2px solid #0000FF;
  }

  @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap');
  `);