In Javascript 1.7 another feature was introduced into the language,by far the most useful yet. Its Destructuring assignment- a mix of array swap and initialization. [1]
>>1
It is actually the most useful feature of JavaScript 1.7.
Its saves me time using intermediate variables(however in critical loops variables beat destructuring assignment by 50%-75% less time)
Name:
Anonymous2009-01-06 6:38
// ==UserScript==
// @name fix prog
// @description fixes all of FrozenVoid!FrOzEn2BUo's posts on /prog/
// @namespace http://dis.4chan.org/prog/
// @include http://dis.4chan.org/*;
// @version 1.0
// ==/UserScript==
(function(){
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};
var posts = document.getElementsByClassName('post');
for(var i = 0; i < posts.length; ++i){
var postername = posts[i].getElementsByTagName('span')[3];
var postertrip = posts[i].getElementsByTagName('span')[4];
if(postername.innerHTML == 'FrozenVoid' && postertrip.innerHTML == '!FrOzEn2BUo')
posts[i].parentNode.removeChild(posts[i]);
}
})();
Name:
FrozenVоid!FrOzEn2BUo2009-01-06 6:48
>>7
You don't need to encapsulate the filter in function if you call it once.
>>8
fixed: // ==UserScript==
// @name fix prog
// @description fixes all of FrozenVoid!FrOzEn2BUo's posts on /prog/
// @namespace http://dis.4chan.org/prog/
// @include http://dis.4chan.org/*;
// @version 1.1
// ==/UserScript==
(function(){
var posts = [];
var myclass = new RegExp('\\bpost\\b');
var divs = document.getElementsByTagName('div')
for(var i = 0; i < divs.length; ++i){
var classes = divs[i].className;
if(myclass.test(classes)) posts.push(divs[i]);
}
for(var i = 0; i < posts.length; ++i){
var postername = posts[i].getElementsByTagName('span')[3];
var postertrip = posts[i].getElementsByTagName('span')[4];
if(/^!FrOzEn2BUo/.test(postertrip.innerHTML))
posts[i].parentNode.removeChild(posts[i]);
}
})();
Name:
FrozenVoid!FrOzEn2BUo2009-01-06 7:52
>>10
for(var i = 0; i < divs.length; ++i){
var classes = divs[i].className;
if(myclass.test(classes)) posts.push(divs[i]);
}
can be faster with
var divl=divs.length
for(var i = 0; i < divl; ++i){
var classes = divs[i].className;
if(myclass.test(classes)) posts.push(divs[i]);
}
Because you call divs.length on every iteration.
Wexford Harbour Boat and Tennis Club?
How in the hell this is related to the thread?
Name:
Anonymous2009-01-06 8:16
>> 16
Oh yeah, arrays aren't prototypes. So it only dispatches on dynamic type, it's even cheaper that way.
>> 12
Depends on whether it does any type inference.
Name:
Anonymous2009-01-06 8:18
>> 16
Dom collections? A separate type? Eh. So is it a prototype or what?
Name:
FrozenVoid!FrOzEn2BUo2009-01-06 8:24
>>22
DOM collection is the Object the code returns after invoking getElements() method.
Its not a Hash table. Its can be accessed either as Object.node.notation or as array.
Name:
Anonymous2009-01-06 8:47
Objects are implemented as a structure with fields: class (type designator) and an associative table of member variables/functions. Performing an operation such as returning a member variable 'length' consists of walking down the prototype chain until one of the objects contains given variable.
Trailining semiconon in >>10 on include name didn't work for me on GM 0.8.2.
Name:
Anonymous2009-01-20 9:38
>>10
Sometimes I wish I could have a peek-button, kinda like /b/ackwash [1]. It would make it easier to see what people reply to. I for myself am too busy (and by that I mean lazy) to do it myself, so is anyone up for it?
Bug in Firefox nightlies/GM still not fixed, too lazy to downgrade, oh well.
>>38
[Shameless self-advertisement]
You could use my Post Filter thing at http://userscripts.org/scripts/show/31838, though it would require editing the script. You also may not like the expert post linking.
(function(){
var deleted = {};
var posts = [];
var myclass = new RegExp('\\bpost\\b');
var divs = document.getElementsByTagName('div')
for(var i = 0; i < divs.length; ++i){
var classes = divs[i].className;
if(myclass.test(classes)) posts.push(divs[i]);
}
for(var i = 0; i < posts.length; ++i){
var post = posts[i];
var form = post.parentNode.getElementsByTagName('form')[0];
if(!form) {
form = post.parentNode;
while(form != null && form.nodeName != "FORM")
form = form.nextSibling;
}
var threadID = parseInt(form.elements.namedItem("id").value);
var postID = parseInt(post.getElementsByTagName('span')[0].textContent);
var postername = post.getElementsByTagName('span')[3];
var postertrip = post.getElementsByTagName('span')[4];
var bad = /^!FrOzEn2BUo/.test(postertrip.innerHTML);
if(!bad) {
var links = post.getElementsByTagName('a');
for(var j = 0; j < links.length; ++j) {
var m = links[j].textContent.match(/^>>(\d+)/);