Skip to content

Instantly share code, notes, and snippets.

@joshuapack
Last active March 29, 2022 15:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuapack/b13eadb53dee68a4ac40984439e8cc9b to your computer and use it in GitHub Desktop.
Save joshuapack/b13eadb53dee68a4ac40984439e8cc9b to your computer and use it in GitHub Desktop.
Paywall Removal
// ==UserScript==
// @name Paywall removal
// @namespace https://www.joshuapack.com
// @updateURL https://gist.githubusercontent.com/joshuapack/b13eadb53dee68a4ac40984439e8cc9b/raw/paywallremoval.user.js
// @downloadURL https://gist.githubusercontent.com/joshuapack/b13eadb53dee68a4ac40984439e8cc9b/raw/paywallremoval.user.js
// @version 0.1.18
// @description I hate paywalls
// @author Joshua Pack
// @match https://*.forbes.com/*
// @match https://*.latimes.com/*
// @match https://*.thewebflash.com/*
// @match https://*.charlotteobserver.com/*
// @match https://*.businessinsider.com/*
// @match https://*.usatoday.com/*
// @match https://*.kbb.com/*
// @match https://*.baltimoresun.com/*
// @match https://*.washingtonpost.com/*
// @match https://*.nytimes.com/*
// @match https://*.annistonstar.com/*
// @match https://*.wyomingnews.com/*
// @match https://*.victoriaadvocate.com/*
// @match https://*.heraldpalladium.com/*
// @match https://*.miamiherald.com/*
// @match https://*.metro.co.uk/*
// @match https://*.telegraph.co.uk/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
addJQuery(main);
function main(loopAmount) {
if (!loopAmount) loopAmount = 0;
loopAmount++;
if (loopAmount > 10) return;
var $ = window.jQ;
var currentHostname = window.location.hostname;
$(document).ready(function() {
let articleBody = '';
// for https://www.forbes.com/
if (currentHostname == 'www.forbes.com' || currentHostname == 'forbes.com') {
$('#view-offer').hide();
$('.tp-modal').hide();
$('.tp-backdrop').hide();
$('body').removeClass('adblock-on');
$('body').removeClass('tp-modal-open');
}
// for https://www.latimes.com/
if (currentHostname == 'www.latimes.com' || currentHostname == 'latimes.com') {
$('.fc-ab-root').remove();
$('.met-flyout').hide();
$('body').css('overflow', 'auto');
$('metering-modal').hide();
}
// for https://www.thewebflash.com/
if (currentHostname == 'www.thewebflash.com' || currentHostname == 'thewebflash.com') {
$('html').removeClass('swal2-shown');
$('body').removeClass('swal2-shown');
$('.swal2-container').remove();
}
// for https://www.charlotteobserver.com/
if (currentHostname == 'www.charlotteobserver.com' || currentHostname == 'charlotteobserver.com') {
$('body').removeClass('paywalled');
$('body').css('overflow', 'auto');
$('.fc-ab-root').remove();
}
// for https://www.businessinsider.com/
if (currentHostname == 'www.businessinsider.com' || currentHostname == 'businessinsider.com') {
$('body').removeClass('tp-modal-slide-up');
$('body').removeClass('tp-modal-open');
$('.tp-modal').remove();
$('.tp-backdrop').remove();
// thanks cmlock for the catch
$('#piano-inline-content-wrapper').show();
}
// for https://www.usatoday.com/
if (currentHostname == 'www.usatoday.com' || currentHostname == 'usatoday.com') {
$('html').css('overflow-y', 'auto');
$('body').css('overflow-y', 'auto');
$("div[class^='sp_veil']").remove();
$("div[class^='sp_message_container']").remove();
}
// for https://www.kbb.com/
if (currentHostname == 'www.kbb.com' || currentHostname == 'kbb.com') {
$(".whitelist-overlay-modal-background").remove();
$('html').removeClass('whitelist-overlay-on');
}
// for https://www.baltimoresun.com/
if (currentHostname == 'www.baltimoresun.com' || currentHostname == 'baltimoresun.com') {
$('html').css('overflow', 'auto');
$('body').css('overflow', 'auto');
$(".meter-modal").remove();
$("#zephr-overlay").remove();
}
// for https://www.washingtonpost.com/
if (currentHostname == 'www.washingtonpost.com' || currentHostname == 'washingtonpost.com') {
$('.paywall-overlay').hide();
$('body').css('overflow', 'auto');
}
// for https://www.nytimes.com/
if (currentHostname == 'www.nytimes.com' || currentHostname == 'nytimes.com') {
$('#gateway-content').hide();
$('.css-1bd8bfl').hide();
$('.css-mcm29f').css('position', 'initial');
}
// for https://www.miamiherald.com/
if (currentHostname == 'www.miamiherald.com' || currentHostname == 'miamiherald.com') {
$('.fc-dialog-overlay').remove();
$('.fc-dialog-container').remove();
$('body').removeClass('paywalled');
$('html').css('overflow', 'auto');
$('body').css('overflow', 'auto');
}
// for https://metro.co.uk/
if (currentHostname == 'www.metro.co.uk' || currentHostname == 'metro.co.uk') {
$('[class*=overlay-]').remove();
$('[class*=wrapper-]').remove();
$('body').removeClass('mol-fe-ab-dialog');
}
// for https://telegraph.co.uk/
if (currentHostname == 'www.telegraph.co.uk' || currentHostname == 'telegraph.co.uk') {
$('.martech-modal-component-overlay').remove();
$('html').removeClass('martech-overlay-not-visible articleRendererHTML logged-in--false is-subscriber--false app-tmg-subscriber--false');
$('html').attr("style","overflow-y:auto !important");
}
// for any other possible websites with paywalls
// if you find any of these are causing issues, you can comment it out below
// or you can let me know and I can target specific websites instead
if ($('.redacted-overlay').length) {
$('#subscription-modal').remove();
$('.modal-backdrop').remove();
$('body').css('overflow', 'auto');
$('.redacted-overlay').hide();
$('.subscription-required').hide();
$('.subscriber-only').hide();
}
setTimeout(function() { main(loopAmount); }, 1000);
});
}
})();
@joshuapack
Copy link
Author

@vidpro2006 Thanks I added washington post! I was unable to see any of the elements on nytimes.com. unsure if they changed, but I also was unable to get any paywall to come up. I did get the bottom thing every once in awhile, but I could just close it manually on screen. The classes you gave me look to be generated as well, which usually means it is different for every person.

@vidpro2006
Copy link

vidpro2006 commented Jun 24, 2021

@joshuapack, the nytimes is not a generated class, not sure why it didn't show but I have been using my own extension with that code for well over a year now and it does still work, google "css-mcm29f" and you will find a greasyfork link that talks about it.
"https://greasyfork.org/en/scripts/395019-the-new-york-times-paywall-bypass/code"

also here is another one that could use some clean up but it works for many local news papers such as annistonstar.com.

var genCheck = document.getElementsByClassName('redacted-overlay')[0]; if(genCheck !=undefined){
  modifyDOMgen();
}

    function modifyDOMgen() {
		document.querySelector('#subscription-modal').remove();
		document.querySelector('.modal-backdrop').remove();
		document.getElementsByTagName('body')[0].style.overflow ='auto';
		
		var x = document.getElementsByClassName('redacted-overlay');
		for (i = 0; i < x.length; i++) 
			{
				x[i].style = "display:none;";
			}
		
		var y = document.getElementsByClassName('subscription-required');
		for (i = 0; i < y.length; i++) 
			{
				y[i].style = "display:none;";
			}
		
		var z = document.getElementsByClassName('subscriber-only');
		for(var i = 0; i < z.length; i++)
			{
				 z[i].classList.remove('hide')
			}
			
		return;
	}


It will remove the nagging modal popup and both the redacted overly as well as un-hiding the article. It works on hundreds of local news paper sites:
annistonstar.com
wyomingnews.com/
victoriaadvocate.com
heraldpalladium
and hundreds more using that same subscription model

@joshuapack
Copy link
Author

joshuapack commented Jul 6, 2021

also here is another one that could use some clean up but it works for many local news papers such as annistonstar.com.

It will remove the nagging modal popup and both the redacted overly as well as un-hiding the article. It works on hundreds of local news paper sites:
annistonstar.com
wyomingnews.com/
victoriaadvocate.com
heraldpalladium
and hundreds more using that same subscription model

@vidpro2006 I went ahead and added it and added a wild card to all domains, hopefully it don't break anything (having the wild card, lol) 0.0

I ended up removing the wild card on the domains. It was causing more issues on websites I don't want it running on. So, I'm going to limit it to the websites we find, which I have included all we have so far.

@cmlock
Copy link

cmlock commented Jul 24, 2021

Nice script @joshuapack! I too hate paywalls... and it looks like Business Insider updated their site to also hide the original content. Add $('#piano-inline-content-wrapper').show(); as shown below to bring it back:

            // for https://www.businessinsider.com/
            if (currentHostname == 'www.businessinsider.com' || currentHostname == 'businessinsider.com') {
                $('body').removeClass('tp-modal-slide-up');
                $('body').removeClass('tp-modal-open');
                $('.tp-modal').remove();
                $('.tp-backdrop').remove();
                $('#piano-inline-content-wrapper').show();
            }

Cheers!

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