Sleazy Fork is available in English.

JAVBUS & JAVLibrary 本地视频匹配

匹配本地视频文件名并标记 JavBus 和 JavLibrary 网站上的电影。

// ==UserScript==
// @name         JAVBUS & JAVLibrary 本地视频匹配
// @version      1.3.0
// @author       WANG & Squirtle
// @description  匹配本地视频文件名并标记 JavBus 和 JavLibrary 网站上的电影。
// @license      MIT
// @icon         https://www.javbus.com/favicon.ico
// @include      /^https:\/\/(\w*\.)?JavBus(\d)*\.com.*$/
// @match        *://*.javbus.com/*
// @match        *://*.javlibrary.com/*
// @namespace https://greasyfork.org/users/439255
// ==/UserScript==

(function() {
    'use strict';

    let button = document.createElement('button');
    button.innerHTML = '仓';
    button.style.position = 'fixed';
    button.style.bottom = '1px';
    button.style.left = '1px';
    button.style.zIndex = '1000';

    button.addEventListener('click', function() {
        btnClick();
    });

    document.body.appendChild(button);

    async function btnClick() {
        const fileInput = document.createElement('input');
        fileInput.type = 'file';
        fileInput.accept = '.txt';
        fileInput.onchange = async () => {
            const file = fileInput.files[0];
            if (file) {
                const movieCodes = await readFile(file);
                localStorage.setItem("movieCodes", JSON.stringify(movieCodes));
                console.log("电影代码设置成功");
                start();
            }
        };
        fileInput.click();
    }

    async function readFile(file) {
        return new Promise((resolve, reject) => {
            const reader = new FileReader();
            reader.onload = (event) => {
                const content = event.target.result;
                let movieCodes = [];
                if (file.name.endsWith('.txt')) {
                    movieCodes = content.split('\n')
                        .map(line => line.trim())
                        .filter(line => line)
                        .map(extractMovieCode)
                        .filter(code => code);
                }
                resolve(movieCodes);
            };
            reader.onerror = (error) => reject(error);
            reader.readAsText(file);
        });
    }

    function extractMovieCode(filename) {
        let code = filename.replace(/^hhd800\.com@/, '');
        code = code.replace(/\.\w+$/, '');
        code = code.replace(/\.265/i, '');
        code = code.replace(/-4K|-C|-uncensored/gi, '');
        return code;
    }

    async function start() {
        const movieCodesStr = localStorage.getItem('movieCodes');
        if (!movieCodesStr) {
            return;
        }
        const movieCodes = JSON.parse(movieCodesStr);

        if (location.href.includes('javbus.com')) {
            $('#waterfall .movie-box').each((index, ele) => {
                const movieBox = $(ele);
                const url = movieBox.attr('href');
                const code = url.substring(url.lastIndexOf('/') + 1);
                if (movieCodes.includes(code)) {
                    movieBox.css('background-color', 'red');
                }
            });

            const url = location.href;
            const code = url.substring(url.lastIndexOf('/') + 1);
            if (movieCodes.includes(code)) {
                $('div.row.movie').css('background-color','gold');
            }
        } else if (location.href.includes('javlibrary.com')) {
             $('.video').each((index, ele) => {
                const video = $(ele);
                const code = video.find('.id').text();
                if (movieCodes.includes(code)) {
                    video.css('background-color', 'red');
                }
            });
        }
    }

    start();
})();