What's wrong with my script

in Script development
Subscribe to What's wrong with my script 12 posts, 6 voices



userscriptfa... Scriptwright
FirefoxWindows

could someomne help me with my script becuase it's not working.

it's http://userscripts.org/scripts/show/58056

 
kooks Scriptwright
FirefoxWindows

Your syntax is wrong. The script should be:

(function() {

Array.forEach(document.images,function(image){if (image.src.indexOf("1x1_trans.gif")!=-1) image.parentNode.removeChild(image);})
})
();

The problem is you have too many brackets at the end of your script.

 
JoeSimmons Scriptwright
FirefoxWindows

They made a new for each() function, this is how it's used.

(function() {
for each(var image in document.images) if(image.src.indexOf("1x1_trans.gif")!=-1) image.parentNode.removeChild(image);
})();

But if I was you, I'd use XPath.
(function() {
var array=document.evaluate("//img[contains(@src,'1x1_trans.gif')]",document,null,6,null);
for(var i=0,item; (item=array.snapshotItem(i)); i++) item.parentNode.removeChild(item);
})();

 
userscriptfa... Scriptwright
FirefoxWindows

thanks everyone for the help.

 
userscriptfa... Scriptwright
FirefoxWindows

tried all of them but it doesn't work

 
IRoll11!~s Scriptwright
FirefoxWindows

For a site that requires a login, you need to save and post the html for the page you are trying to modify. Nobody is going to sign up for a website just to troubleshoot a script.

 
userscriptfa... Scriptwright
FirefoxWindows

bumped

 
Tim Smart Scriptwright
FirefoxX11

IRoll11!~s wrote:
For a site that requires a login, you need to save and post the html for the page you are trying to modify. Nobody is going to sign up for a website just to troubleshoot a script.

Or you can put the source code of the web page on http://pastie.org/ or http://pastebin.com/

 
JoeSimmons Scriptwright
FirefoxWindows

userscriptfa... wrote:
bumped
I'm not signing up, please give a login.
 
kooks Scriptwright
FirefoxWindows

Edit: Opps, this post is wrong ignore it.

Saved for prosperity:
You are using for...each incorrectly, for..each iterates over all an objects properties. Therefore it will iterate over document.images.length and other properties of document.images

 
JoeSimmons Scriptwright
FirefoxWindows

kooks wrote:
You are using for...each incorrectly,
Actually no he is not. It works perfectly.
kooks wrote:
for..each iterates over all an objects properties.
Wrong. for() does... for each() does not.
 
smk Scriptwright
FirefoxWindows

I like python's for ... in so much
js should learn from that one too :)
saves the typing

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel