Greasy Fork is available in English.
Adds a button to the movie genre page to open the chart, and redirects "genre" links to the corresponding "film_genre" page.
当前为
// ==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);
}
})();