简体   繁体   English

如何加速脚本?

[英]How to speed up a script?

I'm using drupal and I got this script for finding comments. 我正在使用drupal,并且得到了用于查找注释的脚本。 If you know drupal then you know about the notorious issue which is that if you click on a link to a comment and that comment is not on page 1 then you won't get anywhere. 如果您了解drupal,那么您将知道一个臭名昭著的问题,即如果您单击注释链接,而该注释不在页面1上,那么您将一事无成。 The script is addressing this issue by finding comment and taking you to the right page but lord is it slow.. My question: Is there any way to speed it up at all? 该脚本通过找到评论并将您带到正确的页面来解决此问题,但是上帝很慢。。我的问题:有什么办法可以加快速度吗?

 eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [ function(e) { return r[e] } ]; e = function() { return '\\\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\\\b' + e(c) + '\\\\b', 'g'), k[c]); return p }('(6(){r(D,"E",6(){s();2 a=9.F("a");k(2 i=0;i<al;i++){2 b=a[i];3(/#g-\\\\d/.m(b.7))b.7=b.7.t("#",(/\\\\?/.m(b.7)?"&":"?")+"G=1#")}});6 r(a,b,c){u{aH(b,c,I)}v(w){u{aJ("K"+b,c)}v(w){}}}6 s(){3(!/#g-\\\\d+$/.m(5.o))4;2 a;3(a=9.x(5.oh(1)))4;2 b=5.Lh(1).y("&");j("z",b);2 c=+j("A",b);3(c&&9.x("g-"+c))4;2 d=+j("B",b);3(d>=M)4;2 e=p(9.N);3(e){2 f=5.7.O(/.*?(?=\\\\?|#|$)/)+"?B="+(d+1)+"&A="+e+(b+""?"&"+bP("&"):"")+5.o;3(c)5.t(f);Q 5=f}}6 p(a){k(2 b R aC){2 c=aC[b];3(cq&&c.qh(0,8)==="g-")4+cqh(8);2 n=p(c);3(n)4 n}}6 j(a,b){k(2 i=0;i<bl;i++){2 c=b[i].y("=");3(c[0]===a){bS(i,1);4(cl>=1)?c[1]:""}}4""}}());', 55, 55, '||var|if|return|location|function|href||document|||||||comment|substr||removeSearchValue|for|length|test||hash|getFirstCommentNumber|id|addEvent|commentLink|replace|try|catch|ignore|getElementById|split||cs|page|childNodes|window|load|getElementsByTagName|cl|addEventListener|false|attachEvent|on|search|99|body|match|join|else|in|splice'.split('|'), 0, {})) 

So here is the unpacked version of your code. 所以这是您的代码的解压缩版本。

The function getFirstCommentNumber is recursive calling itself on all child nodes of the parameter it recieves and the function commentLink calls this using document.body . 函数getFirstCommentNumber是在其收到的参数的所有子节点上递归调用自己的函数,而commentLink函数使用document.body调用。 Basically you are traversing the entire DOM structure looking for a comment number. 基本上,您遍历整个DOM结构以查找注释号。

Is there a better DOM node that just contains the comments you can pass inside commentLink into the getFirstCommentNumber call? 是否有一个更好的DOM节点仅包含可以在commentLink内部传递给getFirstCommentNumber调用的注释?

 (function () { addEvent(window, "load", function () { commentLink(); var a = document.getElementsByTagName("a"); for (var i = 0; i < a.length; i++) { var b = a[i]; if (/#comment-\\d/.test(b.href)) b.href = b.href.replace("#", (/\\?/.test(b.href) ? "&" : "?") + "cl=1#") } }); function addEvent(a, b, c) { try { a.addEventListener(b, c, false) } catch (ignore) { try { a.attachEvent("on" + b, c) } catch (ignore) {} } } function commentLink() { if (!/#comment-\\d+$/.test(location.hash)) return; var a; if (a = document.getElementById(location.hash.substr(1))) return; var b = location.search.substr(1).split("&"); removeSearchValue("z", b); var c = +removeSearchValue("cs", b); if (c && document.getElementById("comment-" + c)) return; var d = +removeSearchValue("page", b); if (d >= 99) return; var e = getFirstCommentNumber(document.body); if (e) { var f = location.href.match(/.*?(?=\\?|#|$)/) + "?page=" + (d + 1) + "&cs=" + e + (b + "" ? "&" + b.join("&") : "") + location.hash; if (c) location.replace(f); else location = f } } function getFirstCommentNumber(a) { for (var b in a.childNodes) { var c = a.childNodes[b]; if (c.id && c.id.substr(0, 8) === "comment-") return +c.id.substr(8); var n = getFirstCommentNumber(c); if (n) return n } } function removeSearchValue(a, b) { for (var i = 0; i < b.length; i++) { var c = b[i].split("="); if (c[0] === a) { b.splice(i, 1); return (c.length >= 1) ? c[1] : "" } } return "" } } ()); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM