Greasy Fork - Analyze from posted scripts

Shows the total amount for each rating, total/daily installs, and scripts posted on any user profile and search pages.

目前為 2023-12-17 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Greasy Fork - Analyze from posted scripts
// @namespace    ScriptAnalyzer
// @version      6
// @description  Shows the total amount for each rating, total/daily installs, and scripts posted on any user profile and search pages.
// @author       hacker09
// @match        https://greasyfork.org/en/users/*
// @match        https://greasyfork.org/*/scripts?q=*
// @match        https://greasyfork.org/*/scripts/by-site/*
// @icon         https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://greasyfork.org/&size=64
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';
  var select, dateresponse, dateDocument, date, ok = 0, bad = 0, Dailytotal = 0, total = 0, good = 0, DocList = [], Scriptposts = 0; //Create new variables

  function Calc(select) { //Create a selector function to calculate values
    select.querySelectorAll(".ok-rating-count").forEach(el => ok += parseInt(el.innerText)); //Add the ratings
    select.querySelectorAll(".bar-rating-count").forEach(el => bad += parseInt(el.innerText)); //Add the ratings
    select.querySelectorAll(".good-rating-count").forEach(el => good += parseInt(el.innerText)); //Add the ratings
    select.querySelectorAll("dd.script-list-total-installs").forEach(el => total += parseInt(el.innerText.replaceAll(',',''))); //Add the total installs
    select.querySelectorAll("dd.script-list-daily-installs").forEach(el => Dailytotal += parseInt(el.innerText.replaceAll(',',''))); //Add the daily installs
  } //Finishes the Calc function

    if (location.href.match('sort=created') === null) { //If the current page is not already being sorted by the created date
      dateresponse = await (await fetch(document.querySelector('a[href$="sort=created"]').href)).text(); //Fetch
      dateDocument = new DOMParser().parseFromString(dateresponse, "text/html"); //Parses the fetch response
      date = dateDocument.querySelector("span > relative-time").textContent; //Save the newest created date
    } //Finishes the if condition
    else //If the current page is already being sorted by the created date
    { //Starts the else condition
      date = document.querySelector("span > relative-time").title; //Save the newest created date
    } //Finishes the else condition

  if (location.href.match('users') !== null && location.href.match('page=') === null) //If the current page is a user profile and isn't a user profile page >= 2
  { //Starts the if condition
    [...document.querySelectorAll(".pagination a:not(.next_page)"), { href: location.href }].forEach(async (el) => { //For each page link including the currently opened one
      await new Promise(r => setTimeout(r, 1000)); //Wait 1 sec before continuing
      const response = await (await fetch(el.href)).text(); //Fetch
      const newDocument = new DOMParser().parseFromString(response, 'text/html'); //Parses the fetch response
      DocList.push(newDocument); //Add the fetched page to an array
    }); //Finishes the forEach loop

    await new Promise(r => setTimeout(r, 2000)); //Wait 2 secs before continuing

    document.head.insertAdjacentHTML('beforeend', '<style>.list-option:not(.list-current) {display: flex; flex-direction: row; align-items: center;} .list-option:not(.list-current) > span {position: relative; left: -7px;} .list-option.list-current > span {position: relative; left: 5px;}</style>'); //Add a space before (

    DocList.forEach(async (docs, i) => { //ForEach page we fetched
      await Calc(docs); //Call the Calc function
      Scriptposts += docs.querySelectorAll("#user-script-list > li").length; //Add the total Script posts

      if (i+1 === DocList.length) { //If it's the last loop
        document.querySelector("#user-script-sets-section,#user-script-list-section").insertAdjacentHTML("afterbegin", `<section><header><h3>Total</h3></header><section class="text-content"><ul><li><b>Script posts</b>: ${Scriptposts}</li><li><b>Daily installs</b>: ${Dailytotal.toLocaleString()}</li><li><b>Total installs</b>: ${total.toLocaleString()}</li><li><b>Total ok ratings</b>: ${ok.toLocaleString()}</li><li><b>Total bad ratings</b>: ${bad.toLocaleString()}</li><li><b>Total good ratings</b>: ${good.toLocaleString()}</li><li><b>Latest created</b>: ${date}</li></ul></section></section>`); //Add the user information on the page
        document.querySelector(".list-option").innerHTML += `<span>(${Dailytotal.toLocaleString()})</span>`; //Add the Dailytotal information on the sidebar
        document.querySelector(".list-option:nth-child(2)").innerHTML += `<span>(${total.toLocaleString()})</span>`; //Add the total information on the sidebar
        document.querySelector(".list-option:nth-child(3)").innerHTML += `<span>(${parseInt(ok+bad+good).toLocaleString()})</span>`; //Add the ratings information on the sidebar
      } //Finishes the if condition
    }); //Finishes the forEach loop
  } //Finishes the if condition

  if (location.href.match(/org\/.*\/scripts/)) //If the current page is a script search page
  { //Starts the else condition
    await Calc(document); //Call the Calc function
    document.querySelector(".width-constraint:nth-child(2)").insertAdjacentHTML("afterbegin", `<section><header><h3>Total</h3></header><section class="text-content"><ul><li><b>Script posts</b>: ${document.querySelectorAll("#browse-script-list > li").length}</li><li><b>Daily installs</b>: ${Dailytotal.toLocaleString()}</li><li><b>Total installs</b>: ${total.toLocaleString()}</li><li><b>Total ok ratings</b>: ${ok.toLocaleString()}</li><li><b>Total bad ratings</b>: ${bad.toLocaleString()}</li><li><b>Total good ratings</b>: ${good.toLocaleString()}</li><li><b>Latest created</b>: ${date}</li></ul></section></section>`); //Add the information on the page
    document.querySelector(".list-option").innerHTML += `<span>(${Dailytotal.toLocaleString()})</span>`; //Add the Dailytotal information on the sidebar
    document.querySelector(".list-option:nth-child(2)").innerHTML += `<span>(${total.toLocaleString()})</span>`; //Add the total information on the sidebar
    document.querySelector(".list-option:nth-child(3)").innerHTML += `<span>(${parseInt(ok+bad+good).toLocaleString()})</span>`; //Add the ratings information on the sidebar
  } //Finishes the else condition
})();