Toggle Anilist Scores Script

21/10/2025, 13.21.43

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Toggle Anilist Scores Script
// @namespace   Violentmonkey Scripts
// @match       https://anilist.co/search/*
// @grant       none
// @version     1.2.1
// @author      AnzoDK
// @license     MIT
// @description 21/10/2025, 13.21.43
// ==/UserScript==
var state = localStorage.getItem("anilist_toggleScoresState") === "true" ? true : false;
var styleNode = null;
var stateCss = ".score:not(.form) {display:none!important;}";
var targetNode = document.getElementsByClassName("filters")[0];
var toggleBtn = null;
function toggleScoresAndSaveState()
{
  toggleScores();
  localStorage.setItem("anilist_toggleScoresState", state);
}
function toggleScores()
{
  if(state)
  {
    styleNode.innerHTML = "";
    state = false;
    toggleBtn.style.backgroundColor = "#182a34";
    return;
  }
  styleNode.innerHTML = stateCss;
  toggleBtn.style.backgroundColor = "#3db4f2";
  state = true;
}
function createToggleButton()
{
  var btn = document.createElement("button");
  btn.id = "toggleScoresBtn";
  btn.appendChild(document.createTextNode("Toggle Scores!!"));
  btn.onclick = toggleScoresAndSaveState;
  btn.style.backgroundColor = "#182a34";
  btn.style.color = "white";
  btn.style.borderRadius = "6px";
  targetNode.appendChild(btn);
  toggleBtn = btn;

}
function createStyleNode()
{
  styleNode = document.createElement("style");
  styleNode.id = "toggleScoresStyles";
  document.getElementsByTagName("head")[0].appendChild(styleNode);
  styleNode = document.getElementById("toggleScoresStyles");

}
function Init_ScoreToggle()
{
  createStyleNode();
  createToggleButton();
  console.log("Toggle Anilist Scores: Button initilized");
  console.log("Syncing button state with localStorage...");
  if(state)
  {
    styleNode.innerHTML = stateCss;
    toggleBtn.style.backgroundColor = "#3db4f2";
  }
}

function CheckForTarget(mutationList, observer)
{
  for (const mutation of mutationList)
    {
      if(document.getElementsByClassName("filters")[0])
        {
          targetNode = document.getElementsByClassName("filters")[0];
          Init_ScoreToggle();
          observer.disconnect();
          return;
        }
    }
}

const mo = new MutationObserver(CheckForTarget);
if(!targetNode)
  {
    console.log("Toggle Anilist Scores: Failed to locate filters - Observing page for changes...")
    mo.observe(document.body, { attributes: false, childList: true, subtree: true });
  }
else
  {
    Init_ScoreToggle();
  }