Raw Source
logicalshrapnel / DN.se remove paywall

// ==UserScript==
// @name            DN.se remove paywall
// @namespace       dn-remove-paywall
// @description     Removes the annoying free articles per week limit
// @icon            https://raw.githubusercontent.com/Denocle/DN.se-paywall-remover/master/assets/icon48.png
// @icon64          https://raw.githubusercontent.com/Denocle/DN.se-paywall-remover/master/assets/icon64.png
// @include         *dn.se*
// @grant           none
// @version         0.5
// @license         GPL-3.0+; http://www.gnu.org/licenses/gpl-3.0.txt
// @updateURL       https://openuserjs.org/meta/Denocle/DN.se_remove_paywall.meta.js
// @downloadURL     https://openuserjs.org/src/scripts/Denocle/DN.se_remove_paywall.user.js
// ==/UserScript==

var boolPaywallRemoved = false;
var intMaxTries = 3;
var intTries = 0;

// Stolen from: http://greasemonkey.win-start.de/patterns/add-css.html
function addGlobalStyle(css) {

	var elHead;
	var elStyle;

	elHead = document.getElementsByTagName('head')[0];

	if (!elHead) {
		return;
	}

	elStyle = document.createElement('style');
	elStyle.type = 'text/css';
	elStyle.innerHTML = css;

	elHead.appendChild(elStyle);

}

function lookForPaywall() {

	// First check
	var arrPaywallContainers = document.getElementsByClassName('paywall--active');

	// If we found the container we know that their script for hiding the article has executed
	if (typeof arrPaywallContainers == 'object' && arrPaywallContainers !== null && arrPaywallContainers.length > 0) {

		var elPaywallContainer = arrPaywallContainers[0];
		// Remove the container
		elPaywallContainer.remove();

		var arrPaywallMask = document.getElementsByClassName('paywall-mask');
		if (arrPaywallMask.length > 0) {
			// Remove the mask
			arrPaywallMask[0].remove();
		}

		var arrPaywallContent = document.getElementsByClassName('paywall-content');
		if (arrPaywallContent.length > 0) {

			// Change the CSS so that the article becomes visible
			arrPaywallContent[0].style.height = 'auto';
			arrPaywallContent[0].style.overflow = 'visible';
		}

		boolPaywallRemoved = true;
	}

	// Second check
	var arrPremiumContent = document.getElementsByClassName('article__premium-content');
	var arrPayWalls = document.getElementsByClassName('paywall');

	if (arrPremiumContent.length > 0) {
		for (var i = 0; i < arrPremiumContent.length; i++) {
			arrPremiumContent[i].style.display = 'block';
			boolPaywallRemoved = true;
		}
	}

	if (arrPayWalls.length > 0) {
		for (var i2 = 0; i2 < arrPayWalls.length; i2++) {
			arrPayWalls[i2].remove();
			boolPaywallRemoved = true;
		}
	}

	addGlobalStyle('.article__body--mask .article__lead { max-height: 1000px !important; }');
	addGlobalStyle('.article__body--mask .article__lead:after { display: none; }');
	addGlobalStyle('.article__body--mask .article__lead { overflow: inherit; max-height: inherit; position: inherit; }');

	// Third check
	var elPayWallOverlay = document.getElementById('pwOverlay');

	if (typeof arrPaywallContainers == 'object' && elPayWallOverlay !== null) {
		elPayWallOverlay.remove();
		boolPaywallRemoved = true;
	}

    //Fourth check 
    var arrTestPayWalls = document.getElementsByClassName('ab-test--paywall');
    if (arrTestPayWalls.length > 0) {
		for (var i3 = 0; i3 < arrY.length; i3++) {
			arrTestPayWalls[i3].classList.remove("ab-test--paywall");
		}
	}

}

var checkInterval = setInterval(function() {

	if (!boolPaywallRemoved && intTries < intMaxTries) {
		lookForPaywall();
		intTries++;
	} else {
		clearInterval(checkInterval);
	}

}, 1000);