AO3: [Wrangling] Rainbow Home Page

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

当前为 2022-05-31 提交的版本,查看 最新版本

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴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.0
// @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').on("click", resetRainbow);
        $('#fandom-filter a').on("click", resetRainbow);
        $('#setup-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, #fandom-filter, #setup-filter, #fandom_search').children('a').on("click", resetRainbow);

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

    });

})(jQuery);