Skip to content

Instantly share code, notes, and snippets.

@itouhiro
Last active November 4, 2015 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itouhiro/1b3780c8453f26028800 to your computer and use it in GitHub Desktop.
Save itouhiro/1b3780c8453f26028800 to your computer and use it in GitHub Desktop.
RemoveSrcset.user.js : Remove URL in <img srcset="..." src="..."> for Firefox Addon 'Image Block' problem https://addons.mozilla.org/ja/firefox/addon/image-block/reviews/
// ==UserScript==
// @name RemoveSrcset
// @version 2015.11.05
// @namespace http://webaborn.herokuapp.com
// @description Remove URL in <img srcset="..." src="...">
// @include *
// ==/UserScript
(function () {
var removeSrcset = function(node){
var i, len, imgNode;
imgNode = document.evaluate('.//img/@srcset/..', node, null, 6, null);
for (i=0, len=imgNode.snapshotLength; i<len; i++) {
imgNode.snapshotItem(i).removeAttribute('srcset');
imgNode.snapshotItem(i).setAttribute('src', '');
}
};
removeSrcset(document);
document.addEventListener('DOMNodeInserted', function(e){ removeSrcset(e.target); }, false);
document.addEventListener('DOMCharacterDataModified', function(e){ removeSrcset(e.target); }, false);
document.addEventListener('DOMAttrModified', function(e){ removeSrcset(e.target); }, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment