如何加速脚本?

时间:2021-10-12 02:44:25

I'm using drupal and I got this script for finding comments. 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. 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?

我正在使用drupal,我得到了这个脚本来寻找评论。如果你知道drupal然后你知道臭名昭着的问题,如果你点击评论的链接并且评论不在第1页,那么你将无法到达任何地方。该脚本通过查找评论并将您带到正确的页面来解决这个问题,但是主要是它很慢..我的问题:有没有办法加快它的速度?

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<a.l;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{a.H(b,c,I)}v(w){u{a.J("K"+b,c)}v(w){}}}6 s(){3(!/#g-\\d+$/.m(5.o))4;2 a;3(a=9.x(5.o.h(1)))4;2 b=5.L.h(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+""?"&"+b.P("&"):"")+5.o;3(c)5.t(f);Q 5=f}}6 p(a){k(2 b R a.C){2 c=a.C[b];3(c.q&&c.q.h(0,8)==="g-")4+c.q.h(8);2 n=p(c);3(n)4 n}}6 j(a,b){k(2 i=0;i<b.l;i++){2 c=b[i].y("=");3(c[0]===a){b.S(i,1);4(c.l>=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, {}))

1 个解决方案

#1


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. Basically you are traversing the entire DOM structure looking for a comment number.

函数getFirstCommentNumber是递归的,它在它收到的参数的所有子节点上调用它自己,函数commentLink使用document.body调用它。基本上,您正在遍历整个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 ""
	}
}
	());

#1


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. Basically you are traversing the entire DOM structure looking for a comment number.

函数getFirstCommentNumber是递归的,它在它收到的参数的所有子节点上调用它自己,函数commentLink使用document.body调用它。基本上,您正在遍历整个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 ""
	}
}
	());