AO3: [Wrangling] Rainbow Home Page

adds CSS classes .rainbow0 through .rainbow5, updates dynamically when filters are applied

当前为 2022-09-11 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AO3: [Wrangling] Rainbow Home Page
// @namespace    https://greasyfork.org/en/users/906106-escctrl
// @description  adds CSS classes .rainbow0 through .rainbow5, updates dynamically when filters are applied
// @author       escctrl
// @version      1.1
// @match        *://*.archiveofourown.org/tag_wranglers/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @license      MIT
// ==/UserScript==

(function($) {
    'use strict';

    function resetRainbow() {
        $('.assigned tbody tr').removeClass('rainbow0 rainbow1 rainbow2 rainbow3 rainbow4 rainbow5');
        $('.assigned tbody tr:visible').each( function(it, row) {
            $(row).addClass('rainbow'+it%6);
        });
    }

    // wait for document to finish loading (seems to be required - events only work properly after other scripts finished writing the filtering links)
    $(document).ready(function(){
        // executes on page load for initial coloring
        resetRainbow();

        // add events for dynamic updates of the CSS classes when filters are applied
        // Redux
        $('#filter-fandoms a').on("click", resetRainbow);
        // N-in-1
        $('#media-filter a').add('#source-filter a').add('#fandom-filter a').add('#setup-filter a').add('#reset-filter a').on("click", resetRainbow);
        // Standard (doesn't specify a p#id so we have to assume it's the second p)
        $('.assigned p:nth-of-type(2)').not('#filter-fandoms, #media-filter, #source-filter, #fandom-filter, #setup-filter, #reset-filter, #fandom_search').children('a').on("click", resetRainbow);

        // Search
        $('#fandom_search').on('keyup', resetRainbow);

    });

})(jQuery);