i want to make Greasemonkey script to replace text in html like this:
<img src="http://example.com/image.jpg" data-gifsrc="http://example.com/image.gif">
to
<img src="http://example.com/image.gif">
in website thechive.com
please help me, thanks.
i want to make Greasemonkey script to replace text in html like this:
<img src="http://example.com/image.jpg" data-gifsrc="http://example.com/image.gif">
to
<img src="http://example.com/image.gif">
in website thechive.com
please help me, thanks.
While I cannot find the data-gifsrc
attribute on the mentioned website, youi cannot assume the JQuery would be present and available for Greasemonkey.
// attribute name
var attrName='data-gifsrc';
// list all images
var imgs=document.getElementsByTagName("img");
// loop every images
for(var i=0;i<imgs.length;i++) {
// check for attribute
if(imgs[i].attributes[attrName]) {
// set image source
imgs[i].src=imgs[i].attributes[attrName].value;
// remove attribute
imgs[i].attributes.removeNamedItem(attrName);
}
}