Greasy Fork

来自缓存

Greasy Fork is available in English.

Rateyourmusic Movie Genre Chart Button

Adds a button to the movie genre page to open the chart, and redirects "genre" links to the corresponding "film_genre" page.

当前为 2024-10-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Rateyourmusic Movie Genre Chart Button
// @description  Adds a button to the movie genre page to open the chart, and redirects "genre" links to the corresponding "film_genre" page.
// @version      1.3
// @namespace    http://greasyfork.icu/users/908137
// @match        *://rateyourmusic.com/charts/*/film/*
// @match        *://rateyourmusic.com/film_genre/*
// @run-at       document-start
// @license      GPLv3
// ==/UserScript==

const formatGenreName = (path, toFilmGenre = false) => {
    const genre = path.split('/')[2].toLowerCase();
    return toFilmGenre ? genre.replace('-', '+') : genre.replace('+', '-');
};

(() => {
    const GENRES_NEEDING_SUFFIX = new Set(['comedy', 'experimental', 'satire']);
    const { pathname } = window.location;

    // Handle chart pages: redirect genre links
    if (pathname.startsWith('/charts/')) {
        document.addEventListener('DOMContentLoaded', () =>
            document.querySelectorAll('a.genre').forEach(link => {
                link.href = `/film_genre/${formatGenreName(link.pathname, true)}`;
            })
        );
    }

    // Handle genre pages: add chart button
    if (pathname.startsWith('/film_genre/')) {
        const genre = formatGenreName(pathname);
        const suffix = GENRES_NEEDING_SUFFIX.has(genre) ? '-1' : '';
        const button = Object.assign(document.createElement('a'), {
            textContent: 'View genre chart',
            href: `/charts/top/film/all-time/g:${genre}${suffix}`,
            style: 'display: inline-block; float: right;'
        });
        document.getElementById('page_breadcrumb')?.appendChild(button);
    }
})();