Skip to content

Instantly share code, notes, and snippets.

@mgng
Last active April 4, 2019 08:25
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 mgng/5410160 to your computer and use it in GitHub Desktop.
Save mgng/5410160 to your computer and use it in GitHub Desktop.
meta refresh blocker クローム用拡張
{
"manifest_version": 2,
"name" : "meta refresh blocker",
"version" : "0.1",
"description" : "meta refresh タグを無効にする拡張です。",
"content_scripts" : [{
"matches" : ["*://*/*"],
"run_at" : "document_idle",
"all_frames" : true,
"js" : [ "metarefreshblocker.js" ]
}]
}
/** metarefreshblocker.js */
(function(){
var nodes = document.querySelectorAll( 'meta[HTTP-EQUIV="refresh"]' );
if ( nodes.length > 0 ) {
var blocked = document.createElement('div');
blocked.setAttribute('style', 'display:block;background-color:#FDA;color:#000;border:1px solid #333;padding:.5em;');
for( var i=0,l=nodes.length; i<l; i++ ) {
var a = document.createElement('a');
var elm = document.createElement('div');
var url = nodes[i]['content'].replace(/.*url=/i, '');
a.setAttribute( 'href', url );
//a.setAttribute( 'target', 'blank' );
a.appendChild( document.createTextNode( 'jump to ' + url ) )
elm.appendChild( a );
blocked.appendChild( elm );
}
document.documentElement.insertBefore( blocked, document.documentElement.firstChild );
document.write( document.documentElement.outerHTML );
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment