View Single Post
Old 07-30-2012, 11:34 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I don't know how Chrome plugins work. I assumed you knew that part.

I don't understand how you can add buttons to an existing web page just using the plugin. Does it somehow insert new stuff into the existing HTML???

Sorry. You'll have to figure that part out.

Annotating my code:
Code:
// get a collection of *ALL* <img> tags on the page
var images = document.getElementsByTagName("img");

// initialize our "found" variable to indicate not found
var found = false; // or null

// this is the image name (src=".../xxxx.jpg") that you want to look for
// we use a regular exprssion because
// (1) the ending $ means that you want to find xxxx.jpg at the end of the src= attribute
// (2) the /i on the end means "ignore case"
var lookFor = /xxxx.jpg$/i;

// so look through all the <img> tags on the page
for ( var i = 0; i < images.length; ++i )
{
    // if our regular expression matches the .src of any <img>...
    if ( lookFor.test( images[i].src ) 
    {
        // change our "found" flag to indicate we found a match
        found = true; // or found = images[i] if you want a reference to it 
        // ...and exit the for loop
        break;
    }
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote