Skip to content

Instantly share code, notes, and snippets.

@casbeebc
Last active February 22, 2024 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save casbeebc/503c338d210790049421230280908175 to your computer and use it in GitHub Desktop.
Save casbeebc/503c338d210790049421230280908175 to your computer and use it in GitHub Desktop.
Wall Street Journal Paywall bypass
/* jshint esversion: 6 */
// ==UserScript==
// @name WSJ and Barrons Paywall Hack - No Popup Confirmation
// @description Paywall bypass for WSJ and Barrons without any confirmation popup
// @match https://www.wsj.com/*
// @match https://www.barrons.com/*
// @run-at document-end
// @grant none
// @version 1
// ==/UserScript==
let pageURL = window.location.href;
let host = window.location.host;
let isWSJ = host.includes('wsj');
let isBarrons = host.includes('barrons');
let isArticle = pageURL.match(/^https?:\/\/(www.)?(wsj|barrons).com\/articles\//);
let protocol = window.location.protocol;
let doBypass = (protocol == 'https:' && isArticle);
let isAMP = pageURL.includes('/amp/');
function returnAMPURL(arg) {
if (isWSJ) {
return 'https://www.wsj.com/amp/' + arg.slice(20);
} else if (isBarrons) {
return 'https://www.barrons.com/amp/' + arg.slice(24);
}
}
let AMPArticlealternateURL = returnAMPURL(pageURL);
function doAMPRedirect() {
window.location.href = AMPArticlealternateURL;
}
// do not add listener unless needed
if(doBypass && !isAMP) {
document.onreadystatechange = function() {
if (document.readyState === "complete") {
doAMPRedirect();
}
};
}
// unhide hidden text and hide nags
if (isAMP) {
document.querySelectorAll('[subscriptions-section="content-not-granted"], [subscriptions-display="NOT granted"]').forEach(function(el) {
el.remove();
});
document.querySelectorAll('[subscriptions-section="content"], [subscriptions-display="granted"]').forEach(function(el) {
el.style = 'display: block!important';
});
if (isWSJ) {
document.querySelector('#mainBody').style.maxWidth = "75vw";
}
document.querySelectorAll('.articleBody h6').forEach(function(el) {
el.style = 'margin: 25px 10px 0';
});
}
@casbeebc
Copy link
Author

casbeebc commented May 8, 2022

  • Removed confirmation popup
  • Enlarged the width.
  • Does not add the listener onreadystatechange until needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment