Greasy Fork

Greasy Fork is available in English.

Filmaffinity clickable search

Makes new (2023) quick search results clickable

目前为 2024-01-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         Filmaffinity clickable search
// @namespace    https://github.com/antoniocambados
// @version      0.1
// @description  Makes new (2023) quick search results clickable
// @author       Antonio Cambados
// @match        https://www.filmaffinity.com*
// @match        https://www.filmaffinity.com/*
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==

/*jshint esversion: 6*/

(function() {
    'use strict';

    function makeMovieLink(movieId) {
        return `https://www.filmaffinity.com/es/film${movieId}.html`;
    }

    function makeNameLink(nameId) {
        return `https://www.filmaffinity.com/es/name.php?name-id=${nameId}`;
    }

    function makeTheaterLink(theaterId) {
        return `https://www.filmaffinity.com/es/theater-showtimes.php?id=${theaterId}`
    }

    function replaceMovieElement(element) {
        let movieId = element.getAttribute("data-movie-id");

        if (movieId) {
            element.setAttribute("href", makeMovieLink(movieId));
            element.outerHTML = element.outerHTML.replace(/^<div/g,"<a");
            element.outerHTML = element.outerHTML.replace(/div>$/g,"a>");
        }
    }

    function replacePersonElement(element) {
        let nameId = element.getAttribute("data-name-id");

        if (nameId) {
            element.setAttribute("href", makeNameLink(nameId));
            element.outerHTML = element.outerHTML.replace(/^<div/g,"<a");
            element.outerHTML = element.outerHTML.replace(/div>$/g,"a>");
        }
    }

    function replaceTheaterElement(element) {
        let theaterId = element.getAttribute("data-theater-id");

        if (theaterId) {
            element.setAttribute("href", makeTheaterLink(theaterId));
            element.outerHTML = element.outerHTML.replace(/^<div/g,"<a");
            element.outerHTML = element.outerHTML.replace(/div>$/g,"a>");
        }
    }

    function process() {
        document.querySelectorAll(`div.movie-card-acf`).forEach(card => {
            replaceMovieElement(card);
        });

        document.querySelectorAll(`div.name-ac`).forEach(card => {
            replacePersonElement(card);
        });

        document.querySelectorAll(`div.theater-ac`).forEach(card => {
            replaceTheaterElement(card);
        });
    }

    process();
    setInterval(process, 300);
})();