Skip to content

Instantly share code, notes, and snippets.

@phocks
Last active May 13, 2023 11:08
Show Gist options
  • Save phocks/64c93a700fb2474821288bb5ab10941b to your computer and use it in GitHub Desktop.
Save phocks/64c93a700fb2474821288bb5ab10941b to your computer and use it in GitHub Desktop.
Removes NYTimes Paywall + restores metered content removed by the NYTimes.com JavaScript (run with Tampermonkey)
// ==UserScript==
// @name NYTimes unpaywall
// @namespace phocks
// @version 0.1.2
// @description no subcribe popover to bother reader on nytimes.com
// @author phocks
// @match *://www.nytimes.com/*
// @grant GM_addStyle
// @run-at document-start
// @licence MIT
// ==/UserScript==
GM_addStyle(`
#site-content,
.css-mcm29f {
position: unset !important;
}
#gateway-content {
display: none;
}
.css-gx5sib {
display: none;
}
`);
(function () {
"use strict";
let mutationsRemoved = [];
let timeoutId;
window.addEventListener("load", function () {
const story = document.querySelector(".meteredContent");
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.removedNodes.length > 0) {
mutationsRemoved.push(mutation);
// Reset the timeout to delay the execution of the function
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
observer.disconnect();
mutationsRemoved.forEach((mutation) => {
mutation.target.appendChild(mutation.removedNodes[0]);
});
}, 3000);
}
});
});
// Start observing changes to the DOM
if (story) observer.observe(story, { childList: true, subtree: true });
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment