Skip to content

Instantly share code, notes, and snippets.

@rwilson
Last active November 14, 2018 03:51
Show Gist options
  • Save rwilson/502465ffb1c66dc7d48cf78459901213 to your computer and use it in GitHub Desktop.
Save rwilson/502465ffb1c66dc7d48cf78459901213 to your computer and use it in GitHub Desktop.
Unmodalify Bookmarklet
// Use to remove modals that some sites add when they detect
// an ad blocker or unauthenticated client.
// Minify with: https://skalman.github.io/UglifyJS-online/
// Add as bookmarklet with: javascript:<minified-code>
(function() {
// Remove elements
[
'modal',
'modal-backdrop',
'paywall__overlay',
'pico-overlay',
'pico-content'
]
.map(cn => document.getElementsByClassName(cn))
.forEach((elems) => {
for (let i=0; i<elems.length; i++) {
const elem = elems.item(i);
elem.parentNode.removeChild(elem);
}
});
// Remove body class names
[
/modal-open/
].forEach((re) => {
document.body.className = document.body.className.replace(re, '');
});
// Remove class names
[
'blurred',
'truncate-text',
'rb'
]
.forEach((cn) => {
const elems = document.getElementsByClassName(cn);
const re = new RegExp(cn);
while (elems.length > 0) {
const elem = elems.item(0);
elem.className = elem.className.replace(re, '');
if (cn === 'truncate-text') {
elem.style.height = '';
elem.style.maxHeight = '';
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment