// ==UserScript==
// @name Linkify·改
// @version 1.1.3
// @author 极品小猫
// @description 文本转超链接
// @en:description Looks for things in the page that look like URLs but aren't hyperlinked, and converts them to clickable links.
// @include *://*/*
// @exclude http*://www.baidu.com/*
// @exclude http*://www.google.com/*
// @exclude http*://note.sdo.com/*
// @require https://code.jquery.com/jquery-2.1.4.min.js
// @run-at document-idle
// @grant GM_addStyle
// @grant GM_notification
// @grant GM_registerMenuCommand
// @grant unsafeWindow
// @namespace https://greasyfork.org/users/3128
// @downloadURL none
// ==/UserScript==
function Linkify() {
GM_addStyle('.newhref{border:2px dashed red!important;display:inline-block!important;padding:5px!important;margin:5px 0!important;}.newhref:hover{border-color:#E9aa2f!important;}');
//const urlRegex = /\b(https?:\/\/[^\s+\"\'\<\>,]+|ed2k:\/\/\|file\|[^\|]+\|\d{9}\|\w{32}\|h=\w{32}\|\/)/ig;
//const urlRegex = /\b(https?:\/\/[^\s+\"\\'<\>,]+|magnet:\?xt=urn:btih:\w{40}|ed2k:\/\/\|file\|[^\|]+\|\d+\|\w{32}\|(?:h=\w{32}\|)?\/)/ig;
var urlRegex=new RegExp(//协议规则,正则模式,\需要转义\\
'\\b('
+
'https?:\\/\\/[^\\s+"\\\'<>,\\[\\]()\:\\*\\u4E00-\\u9FFF]+' //https?:\/\/[^\s+"\\'<>,\[\]()\:\*\u4E00-\u9FFF]+
+'|'+
'https?:\\/\\/mega.nz\\/#!\w+![^\\s+"\'<>,\\]]+' //mega 专用规则
+'|'+
'ed2k:\\/\\/\\|file\\|[^\\|]+\\|\\d+\\|\\w{32}\\|(?:h=\\w{32}\\|)?\\/' //ed2k专用规则
+'|'+
'magnet:\\?xt=urn:btih:\\w{40}(&[\\w\\s]+)?' //magnet 专用规则
+')','ig');
//console.log(urlRegex);
//ed2k://|file|mura-041616_381.mp4|1874185231|E7D60A7A854CF7AE0FF77AC306808760|h=SYGOH7KKTWHJNA4OBVAEOANW27FT5RJE|/
// tags we will scan looking for un-hyperlinked urls
var allowedParents = [ //允许处理的文本的父标签
"body",
"code","blockquote",
"abbr", "acronym", "address", "applet", "b", "bdo", "big",
"caption", "center", "cite", "dd", "del", "div", "dfn", "dt", "em",
"fieldset", "font", "form", "i", "iframe",
"ins", "kdb", "li", "object", "pre", "p", "q", "samp", "small", "span", "strike", "font",
"s", "strong", "sub", "sup", "td", "th", "tt", "u", "var",
"h1", "h2", "h3", "h4", "h5", "h6",
'url','img'
];
/*
var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ") and " +
"contains(translate(., 'HTTP', 'http'), 'http')]";
*/
var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ") and " +
"(contains(translate(., 'HTTP', 'http'), 'http')"+" or " +
"contains(translate(., 'MAGNET', 'magnet'), 'magnet')"+" or " +
"contains(translate(., 'ED2K', 'ed2k'), 'ed2k'))]";
//console.log(xpath);
var candidates = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var t0 = new Date().getTime();
for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) {
if (urlRegex.test(cand.nodeValue)) {
var span = document.createElement("span"); //为超链接创建span标签作为容器
var source = cand.nodeValue;
//console.log(cand);
cand.parentNode.replaceChild(span, cand);
urlRegex.lastIndex = 0;
for (var match = null, lastLastIndex = 0; (match = urlRegex.exec(source)); )
{
span.appendChild(document.createTextNode(source.substring(lastLastIndex, match.index)));
//console.log(match);
if(/\.(?:gif|jpg|png|bmp)(?:\?.+?)?$/.test(match[0])){//如果是图片链接,则创建有图片地址的连接
span.innerHTML='
';
}
var Mtxt=match[0]; //取得链接
var Rtxt=/paco-\d{6}_\d{3}/i.test(Mtxt)?Mtxt.replace(/paco-(\d{6}_\d{3})/i,'pacopacomama $1'):Mtxt; //替换链接内容
var a = document.createElement("a");
a.href=Rtxt;
a.className='newhref';
a.target="blank";
a.appendChild(document.createTextNode(decodeURIComponent(Rtxt)));
span.appendChild(a);
lastLastIndex = urlRegex.lastIndex;
}
span.appendChild(document.createTextNode(source.substring(lastLastIndex)));
span.normalize();
}
}
var t1 = new Date().getTime();
//alert((t1 - t0) / 1000);
}
function ViewIMG(){
var oA=document.getElementsByTagName('a');
for(var i in oA){
console.log(oA[i].href);
if(/\.(?:jpg|png|gif)$/i.test(oA[i].href)){
oA[i].innerHTML+='
';
}
}
}
function ViewVideo(){
$('a[href*=".mp4"], a[href*=".m3u8"]').each(function(){
$('