Last active
July 13, 2018 08:04
-
-
Save hemulin/8fb3e73eac755850c7c55eb108bd240e to your computer and use it in GitHub Desktop.
Bookmarklet for hiding DOM header, footer and cookies based on simple regex match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var patterns = [ | |
/.*?[hH]eader[\s\S]?/, | |
/.*?[fF]ooter[\s\S]?/, | |
// /.*?[Nn]av[\s\S]?/, | |
/.*?[Cc]ookie[\s\S]?/ | |
] | |
// (?<![cC]ontext).*?[hH]eader[\s\S]*(?![Cc]ontext) | |
// (?<![cC]ontext).*?[hH]eader[\s\S]*?(?![Cc]ontext) | |
var contextPattern = /[cC]ontext/ | |
var allTags = document.getElementsByTagName('*') | |
for (let i = allTags.length - 1; i >= 0; --i) { | |
patterns.some((p) => { | |
let cur = allTags[i] | |
let foundElem = p.test(cur.id) || p.test(cur.className) || p.test(cur.tagName) | |
if ( | |
foundElem && | |
!( | |
contextPattern.test(cur.id) || | |
contextPattern.test(cur.className) || | |
contextPattern.test(cur.tagName) | |
) | |
) { | |
// console.log( | |
// `hiding node ${allTags[i]}, ${allTags[i].id}, ${allTags[i].className}, ${allTags[i] | |
// .tagName}` | |
// ) | |
allTags[i].style.display = 'none' | |
// debugger | |
} | |
}) | |
} | |
// Bookrmarklet uglified form: | |
// javascript:var patterns=[/.*?[hH]eader[\s\S]?/,/.*?[fF]ooter[\s\S]?/,/.*?[Cc]ookie[\s\S]?/],contextPattern=/[cC]ontext/,allTags=document.getElementsByTagName("*");for(let t=allTags.length-1;t>=0;--t)patterns.some(e=>{let a=allTags[t];(e.test(a.id)||e.test(a.className)||e.test(a.tagName))&&!(contextPattern.test(a.id)||contextPattern.test(a.className)||contextPattern.test(a.tagName))&&(allTags[t].style.display="none")}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment