JavDB Trailers

在 JavDB 页面上显示预告片信息

Verze ze dne 19. 01. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         JavDB Trailers
// @namespace    http://tampermonkey.net/
// @version      2025-01-03
// @description  在 JavDB 页面上显示预告片信息
// @author       Haoyinhaoyin
// @match        https://javdb.com/v/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=javdb.com
// @grant        GM_xmlhttpRequest
// @connect      javtrailers.com
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // 在 JavDB 页面上获取包含视频 ID 的元素
    const spanElement = document.querySelector('.panel-block.first-block .value a');
    if (spanElement != null) {
        // 获取视频 ID
        const javId = spanElement.parentElement.textContent.trim();
        fetchPreview(javId);
    } else {
        console.log("JavDB 页面中未找到视频 ID。");
    }

    // 通过 API 获取预告片信息并插入页面
    function fetchPreview(javId) {
        const url = `https://search.javtrailers.com/indexes/videos/search?q=${javId}&page=1&sort=releaseDate:desc&hitsPerPage=1`;

        doGet(url).then(data => {
            try {
                const result = JSON.parse(data);
                if (result.hits && result.hits.length > 0) {
                    const hit = result.hits[0];
                    const contentId = hit['contentId'];
                    const matchedId = hit['id'] || hit['title'];

                    // 确认匹配结果是否与请求的 javId 一致
                    if (matchedId && matchedId.toLowerCase().includes(javId.toLowerCase().replace('-', ''))) {
                        insertTrailerLink(javId, contentId);
                    } else {
                        insertNoTrailerMessage(javId);
                    }
                } else {
                    insertNoTrailerMessage(javId);
                }
            } catch (error) {
                console.error("解析 API 响应失败:", error);
                insertNoTrailerMessage(javId);
            }
        });
    }

    // 在页面中插入预告片链接
    function insertTrailerLink(javId, contentId) {
        const trailerUrl = `https://javtrailers.com/video/${contentId}`;
        const existingDiv = document.querySelector('.panel-block.first-block');

        if (existingDiv) {
            const trailerHTML = `
                <div class="panel-block">
                    <strong>预览:</strong>
                    &nbsp;<span class="value"><a href="${trailerUrl}" target="_blank">${javId}</a></span>
                </div>
            `;
            existingDiv.insertAdjacentHTML('afterend', trailerHTML);
        } else {
            console.warn("页面中未找到插入位置。");
        }
    }

    // 如果没有预告片,插入提示信息
    function insertNoTrailerMessage(javId) {
        const existingDiv = document.querySelector('.panel-block.first-block');

        if (existingDiv) {
            const noTrailerHTML = `
                <div class="panel-block">
                    <strong>预览:</strong>
                    &nbsp;<span class="value">未找到与 <strong>${javId}</strong> 对应的预告片。</span>
                </div>
            `;
            existingDiv.insertAdjacentHTML('afterend', noTrailerHTML);
        } else {
            console.warn("页面中未找到插入位置。");
        }
    }

    // 封装 GET 请求
    async function doGet(url) {
        return new Promise(resolve => {
            GM.xmlHttpRequest({
                method: "GET",
                headers: { "authorization": "Bearer 6b4bd3e560e994a5b009023e1d21f51e95dbb86ca3f47cb03f34f8a2cb9a93f2" },
                url,
                onload: response => resolve(response.responseText),
            });
        });
    }
})();