Greasy Fork

Greasy Fork is available in English.

dm1080直接跳转

转换编号为直达链接,并不知道站长知道了这东西会不会做出什么应对措施.

当前为 2019-03-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         dm1080直接跳转
// @namespace    http://tampermonkey.net/
// @version      0.0.0.0.0.0.2
// @description   转换编号为直达链接,并不知道站长知道了这东西会不会做出什么应对措施.
// @homepage		http://greasyfork.icu/zh-CN/scripts/29313-dm1080%E7%9B%B4%E6%8E%A5%E8%B7%B3%E8%BD%AC
// @author       You
// @match        https://dm1080p.com/archives/*
// @match        https://52kbd.com/archives/*
// @grant        none
// ==/UserScript==

var urlRegex = /([0-9a-z]{7})(?=-)/ig;

var snapTextElements = document.evaluate("//text()[not(ancestor::a) " + 

                                         "and not(ancestor::script) and not(ancestor::style) and "+ 

                                        "contains(.,'资料编码:') or contains(.,'资料编号:')]", 

                                         document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i <snapTextElements.snapshotLength; i++) {

    var elmText = snapTextElements.snapshotItem(i);
    if (urlRegex.test(elmText.nodeValue)) {

        var elmSpan = document.createElement("span");

        var sURLText = elmText.nodeValue;

        elmText.parentNode.replaceChild(elmSpan, elmText);

        urlRegex.lastIndex = 0;

        for (var match = null, lastLastIndex = 0;

             (match = urlRegex.exec(sURLText)); ) { 

            elmSpan.appendChild(document.createTextNode(

                sURLText.substring(lastLastIndex, match.index))); 

            var elmLink = document.createElement("a"); 

            elmLink.setAttribute("href",'https://zzzpan.com/?/file/view-'+match[0]+'.html'); 
            elmLink.setAttribute("target", "_blank");
            elmLink.appendChild(document.createTextNode(match[0])); 

            elmSpan.appendChild(elmLink); 

            lastLastIndex = urlRegex.lastIndex;

        }

        elmSpan.appendChild(document.createTextNode(

            sURLText.substring(lastLastIndex)));

        elmSpan.normalize();
        
        
    }

}