Keylistener Primewire TV Shows

Next or previous episodes using keyboard shortcuts.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Keylistener Primewire TV Shows
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Next or previous episodes using keyboard shortcuts.
// @author       Dan6erbond
// @match        https://www.primewire.ag/tv/*
// @grant        none
// ==/UserScript==

function pad(num) {
    const s = "0" + num;
    return s.substr(s.length - Math.max(2, num.toString().length));
}

(function() {
    'use strict';

    document.addEventListener("keyup", (e) => {
        const container = document.querySelector("body > div.container > div.col1 > div.main-body > div.index_container > div.choose_tabs > div.episode_prev_next");
        let hasNext = false, hasPrev = false, foundDivider = false;
        for (let i = 0; i < container.childNodes.length; i++) {
            const node = container.childNodes[i];
            if (node.nodeType === Node.TEXT_NODE && node.data.indexOf("|") !== -1) {
                foundDivider = true;
            } else if (node.nodeType === Node.ELEMENT_NODE) {
                if (foundDivider) {
                    hasNext = true;
                } else {
                    hasPrev = true;
                }
            }
        }
        if (!hasPrev || !hasNext) {
            if (e.code === "KeyP" && hasPrev) {
                const url = container.children[0].getAttribute("href");
                window.location.href = url;
            } else if (e.code === "KeyN" && hasNext) {
                const url = container.children[0].getAttribute("href");
                window.location.href = url;
            }
        } else if (e.code === "KeyP") {
            const url = container.children[0].getAttribute("href");
            window.location.href = url;
        } else if (e.code === "KeyN") {
            const url = container.children[1].getAttribute("href");
            window.location.href = url;
        }
    });

    const season = document.querySelector("body > div.container > div.col1 > div.main-body > div.index_container > div.stage_navigation.movie_navigation > h1 > span > strong:nth-child(2) > a").innerHTML.split(" ")[1];
    const episode = document.querySelector("body > div.container > div.col1 > div.main-body > div.index_container > div.stage_navigation.movie_navigation > h1 > span > strong:nth-child(3)").innerHTML.split(" ")[1];
    const title = document.querySelector("body > div.container > div.col1 > div.main-body > div.index_container > div.movie_info > table > tbody > tr:nth-child(2) > td:nth-child(2)").innerHTML;

    const td = document.querySelector("body > div.container > div.col1 > div.main-body > div.index_container > div.movie_info > table > tbody > tr:nth-child(2) > td:nth-child(2)");
    const button = document.createElement("button");
    button.innerHTML = "📑";
    button.addEventListener("click", async () => {
        await navigator.clipboard.writeText(`S${pad(season)}E${pad(episode)} - ${title}`);
    });
    td.appendChild(document.createTextNode(" "));
    td.appendChild(button);
})();