SubsPlease Keep Track of Watched Episodes

Keep track of which episodes have been clicked on on subsplease.org

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SubsPlease Keep Track of Watched Episodes
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Keep track of which episodes have been clicked on on subsplease.org
// @author       lord_ne
// @license      MIT
// @match        https://subsplease.org/shows/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=subsplease.org
// @run-at       document-idle
// @require      https://update.greasyfork.org/scripts/502635/1422101/waitForKeyElements-CoeJoder-fork.js
// @grant        unsafeWindow
// ==/UserScript==

/* global waitForKeyElements */

(function() {
    'use strict';
    waitForKeyElements('label.episode-title', applyToElement, false);

    addGlobalStyle(`
        label.episode-title.clicked {
            color: #aa05aa !important;
        }
        label.episode-title.clicked:hover {
            color: #ff00ff !important;
        }
    `);

    function applyToElement(el) {
        markIfClicked(el);
        el.addEventListener('click', onClick);
        el.addEventListener('mouseover', onMouseOver);
    }

    function onClick(event) {
        unsafeWindow.localStorage.setItem(event.target.textContent, 'clicked');
        event.target.classList.add('clicked');
    }

    function onMouseOver(event) {
        markIfClicked(event.target);
    }

    function markIfClicked(el) {
        if (unsafeWindow.localStorage.getItem(el.textContent)) {
            el.classList.add('clicked');
        } else {
            el.classList.remove('clicked');
        }
    }

    function addGlobalStyle(css) {
        const head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        const style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }

})();