TF.TV Thread Title Hider

Hides thread titles you don't want to see immediately

目前為 2016-04-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name        TF.TV Thread Title Hider
// @namespace   epi
// @description Hides thread titles you don't want to see immediately
// @include     http://www.teamfortress.tv/*
// @version     1
// @grant       none
// ==/UserScript==

(function (){
    "use strict";
    var hidden = localStorage.getItem("user-hidden"),
        def = [
            'esea',
            'etf2l',
            'ozf',
            'lan'
        ],
        navbar = document.querySelector("nav"),
        link = document.createElement("a"),
        linkdiv = document.createElement("div"),
        linkicon = document.createElement("i"),
        container = document.createElement("div"),
        add = document.createElement("span"),
        savetext = document.createElement("span"),
        firstrow = document.createElement("div"),
        shown = false,
        before;

    if (hidden === null) {
        hidden = def;
    } else {
        hidden = JSON.parse(hidden);
    }

    function reveal(event) {
        var link = (event.target.tagName.toLowerCase() === "a") ? event.target : event.target.parentNode,
            span = link.querySelector(".module-item-title");
        
        console.log(event);
        console.log(link);
        event.preventDefault();
        event.stopPropagation();
        link.classList.remove("user-hidden");
        link.setAttribute("title", link.dataset.oldTitle);
        link.setAttribute("href", link.dataset.oldHref);
        span.textContent = link.dataset.oldTitle;
        span.style.fontStyle = "";

        link.removeEventListener("click", reveal);
    }

    if (NodeList.prototype.forEach === undefined) {
        NodeList.prototype.forEach = function (f) {
            var i;
            for (i = 0; i < this.length; i += 1) {
                f.call(this[i], this[i], i, this);
            }
        };
    }

    document.getElementById("sidebar-left").querySelectorAll(".module").forEach(function (module) {
        module.querySelectorAll(".module-item").forEach(function (link) {
            var span = link.querySelector(".module-item-title"),
                title;
            if (span.classList.contains("mod-event")) {
                return; // event posts generally do not have spoilers
            }
            title = span.textContent.trim();
            hidden.forEach(function (keyword) {
                var newtitle = "[" + keyword + " thread]";
                if (link.classList.contains("user-hidden")) {
                    return;
                }
                if (title.toLowerCase().indexOf(keyword) !== -1) {
                    link.classList.add("user-hidden");
                    link.dataset.oldTitle = title;
                    link.dataset.oldHref = link.getAttribute("href");
                    link.setAttribute("href", link.dataset.oldHref.split("/").slice(0, -1).join("/")); // remove slug from href
                    link.setAttribute("title", "Click to reveal");
                    span.textContent = newtitle;
                    span.style.fontStyle = "italic";

                    link.addEventListener("click", reveal);
                }
            });
        });
    });

    function createrow(word) {
        var row = document.createElement("div"),
            input = document.createElement("input"),
            remove = document.createElement("span");

        if (word === undefined) {
            word = "";
        }

        input.style.height = "30px";
        input.style.marginTop = "5px";
        input.style.fontSize = "11px";
        input.style.lineHeight = "30px";
        input.style.width = "100px";
        input.value = word;

        remove.style.float = "right";
        remove.classList.add("btn");
        remove.textContent = "Remove";
        remove.addEventListener("click", function () {
            row.parentNode.removeChild(row);
        });

        row.style.height = "40px";
        row.style.padding = "5px 0";
        row.style.clear = "both";
        row.appendChild(input);
        row.appendChild(remove);
        return row;
    }

    link.classList.add("header-nav-item-wrapper");
    link.classList.add("mod-last");
    link.setAttribute("href", "#");
    link.style.overflow = "visible";
    link.addEventListener("click", function (event) {
        event.preventDefault(); // # causes "scroll jump" to top otherwise
        var newhidden = [];
        if (shown) {
            container.style.display = "none";
            linkicon.classList.remove("fa-caret-up");
            linkicon.classList.add("fa-caret-down");
            shown = false;
            container.querySelectorAll("input").forEach(function (input) {
                newhidden.push(input.value.toLowerCase());
            });
            localStorage.setItem("user-hidden", JSON.stringify(newhidden));
        } else {
            container.style.display = "";
            linkicon.classList.remove("fa-caret-down");
            linkicon.classList.add("fa-caret-up");
            shown = true;
        }
    });

    linkdiv.classList.add("header-nav-item");
    linkdiv.classList.add("mod-solo");
    linkdiv.textContent = "Spoilers ";

    linkicon.classList.add("fa");
    linkicon.classList.add("fa-caret-down");

    container.style.backgroundColor = "#f5f5f5";
    container.style.position = "absolute";
    container.style.top = "40px";
    container.style.display = "none";
    container.style.zIndex = "99";
    container.style.width = "200px";
    container.style.padding = "5px";
    container.style.border = "1px solid #b4b4b4";
    container.addEventListener("click", function (event) {
        event.preventDefault(); // # causes "scroll jump" to top otherwise
        event.stopPropagation();
    });

    firstrow.style.height = "40px";
    firstrow.style.padding = "5px 0";
    firstrow.style.clear = "both";

    savetext.style.fontSize = "11px";
    savetext.style.color = "#555555";
    savetext.style.lineHeight = "40px";
    savetext.textContent = "Close to save";

    add.classList.add("btn");
    add.textContent = "Add";
    add.style.float = "right";
    add.addEventListener("click", function () {
        container.appendChild(createrow());
    });

    firstrow.appendChild(savetext);
    firstrow.appendChild(add);
    container.appendChild(firstrow);
    hidden.forEach(function (keyword) {
        container.appendChild(createrow(keyword));
    });
    linkdiv.appendChild(linkicon);
    link.appendChild(linkdiv);
    link.appendChild(container);

    before = navbar.querySelector("#user-actions");
    if (before === null) {
        before = navbar.querySelector("a:last-child");
    }
    navbar.insertBefore(link, before);
}());

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址