Greasy Fork

Greasy Fork is available in English.

MT论坛

为导航栏新添加一个最新发表标签和点亮url

目前为 2020-04-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         MT论坛
// @namespace    http://tampermonkey.net/
// @version      0.5.3
// @description  为导航栏新添加一个最新发表标签和点亮url
// @author       MT-戒酒的李白染
// @match        *://bbs.binmt.cc/*
// @icon         https://bbs.binmt.cc/favicon.ico
// @grant        none

// ==/UserScript==

(function() {
    'use strict';

   //$.unique(yearArray);
        var ele = document.createElement('li');
    var url = window.location.href;
    ele.id = "latest_publication"
    ele.innerHTML = '<a href="https:\/\/bbs.binmt.cc\/forum.php?mod=guide&view=newthread" hidefocus="true" title="最新发表">最新发表<\/a>';
    document.getElementsByClassName("wp comiis_nvbox cl")[0].children[1].appendChild(ele);
    if(url=='https:\/\/bbs.binmt.cc\/forum.php?mod=guide&view=newthread')
    {
        ele.style.cssText='background: url("https:\/\/cdn2.bbs.binmt.cc\/template\/comiis_mi\/img\/nv_a.png") repeat-x 50% -50px;';

    }

   var clearLink, excludedTags, filter, linkMixInit, linkPack, linkify, observePage, observer, setLink, url_regexp, xpath;
    url_regexp = /((https?:\/\/|www\.)[\x21-\x7e]+[\w\/]|(\w[\w._-]+\.(com|cn|org|net|info|tv|cc))(\/[\x21-\x7e]*[\w\/])?|ed2k:\/\/[\x21-\x7e]+\|\/|thunder:\/\/[\x21-\x7e]+=)/gi;
    clearLink = function(a) {
        var b;
        a = null != (b = a.originalTarget) ? b: a.target;
        if (null != a && "a" === a.localName && -1 !== a.className.indexOf("texttolink") && (b = a.getAttribute("href"), 0 !== b.indexOf("http") && 0 !== b.indexOf("ed2k://") && 0 !== b.indexOf("thunder://"))) return a.setAttribute("href", "http://" + b)
    };
    document.addEventListener("mouseover", clearLink);
    setLink = function(a) {
    if (null != a && -1 === a.parentNode.className.indexOf("texttolink") && "#cdata-section" !== a.nodeName) {
        var b = a.textContent.replace(url_regexp, '<a target="_blank" href="$1" style="text-decoration:none;border: 1px solid #e74c3c;color: #c0392b;">$1</a>');
        if (a.textContent.length !== b.length) {
            var c = document.createElement("span");
            c.innerHTML = b;
            return a.parentNode.replaceChild(c, a)
        }
    }
};
    excludedTags = "a svg canvas applet input button area pre embed frame frameset head iframe img option map meta noscript object script style textarea code".split(" ");
    xpath = "//text()[not(ancestor::" + excludedTags.join(") and not(ancestor::") + ")]";
    filter = new RegExp("^(" + excludedTags.join("|") + ")$", "i");
    linkPack = function(a, b) {
        var c, d;
        if (b + 1E4 < a.snapshotLength) {
            var e = c = b;
            for (d = b + 1E4; b <= d ? c <= d: c >= d; e = b <= d ? ++c: --c) setLink(a.snapshotItem(e));
            setTimeout(function() {
                return linkPack(a, b + 1E4)
                },
            15)
        } else for (e = c = b, d = a.snapshotLength; b <= d ? c <= d: c >= d; e = b <= d ? ++c: --c) setLink(a.snapshotItem(e))
    };
    linkify = function(a) {
        a = document.evaluate(xpath, a, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        return linkPack(a, 0)
    };
    observePage = function(a) {
        for (a = document.createTreeWalker(a, NodeFilter.SHOW_TEXT, {
            acceptNode: function(a) {
                if (!filter.test(a.parentNode.localName)) return NodeFilter.FILTER_ACCEPT
            }
        },
    !1); a.nextNode();) setLink(a.currentNode)
    };
    observer = new window.MutationObserver(function(a) {
        var b, c;
        var d = 0;
        for (b = a.length; d < b; d++) {
            var e = a[d];
            if ("childList" === e.type) {
                var g = e.addedNodes;
                var f = 0;
                for (c = g.length; f < c; f++) e = g[f],
                    observePage(e)
            }
        }
    });
    linkMixInit = function() {
        if (window === window.top && "" !== window.document.title) return linkify(document.body),
            observer.observe(document.body, {
            childList: !0,
            subtree: !0
        })
    };
    var clearlinkF = function(a) {
        url = a.getAttribute("href");
        if (0 !== url.indexOf("http") && 0 !== url.indexOf("ed2k://") && 0 !== url.indexOf("thunder://")) return a.setAttribute("href", "http://" + url)
    },
    clearlinkE = function() {
        for (var a = document.getElementsByClassName("texttolink"), b = 0; b < a.length; b++) clearlinkF(a[b])
    };
    setTimeout(clearlinkE, 1500);
    setTimeout(linkMixInit, 100);
    for(var doms = document.getElementsByClassName("pls favatar"), ol = 0 ; ol < doms.length ; ol++){
         var online = doms[ol].getElementsByClassName("i y")[0].textContent

         if(online.match('当前在线')){
             var imi = document.createElement('img');
             imi.src='https:\/\/cdn2.bbs.binmt.cc\/static\/image/smiley\/doge\/35.png';
             imi.smilied='1384';
             imi.border="0";
             imi.style='float:right';
             doms[ol].insertAdjacentElement('afterbegin',imi);
         }else
         {
             var imi2 = document.createElement('img');
             imi2.src='https:\/\/cdn2.bbs.binmt.cc\/static\/image\/smiley\/doge\/54.png';
             imi2.smilied='1353';
             imi2.border="0";
             imi2.style='float:right';
             doms[ol].insertAdjacentElement('afterbegin',imi2);
         }
    }
})();