|
// ==UserScript== |
|
// @name Read DN |
|
// @namespace http://tampermonkey.net/ |
|
// @version 0.1.0 |
|
// @description I just want to read the news. |
|
// @author Tobias Haugen |
|
// @match *://www.dn.se/* |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
// Collecting the content I need while the page is loading. |
|
const premiumContent = document.querySelector('.article__premium-content'); |
|
const premiumContentText = document.querySelector( |
|
'.article__premium-content .article__content' |
|
); |
|
const articleLead = document.querySelector('.article__lead'); |
|
const articleHeader = document.querySelector('article.article header'); |
|
// Reset the classes here on the premium content so that their js don't hide it. |
|
premiumContent.className = ''; |
|
|
|
// When page is loaded, call my function to make and insert the article. |
|
// Only do this is we actually caught some premium content. Otherwise we just |
|
// leave the page as is. |
|
premiumContentText |
|
? window.addEventListener('load', newArticle, false) |
|
: console.log('No premium content sent to browser'); |
|
|
|
function newArticle() { |
|
// Getting the wrapper of the paywall covered article so we can remove it. |
|
const oldArticle = document.querySelector('.article__content--locked'); |
|
oldArticle.remove(); |
|
|
|
// Resetting classes again. Seams to be nesseccary to make sure no classes are left after page load. |
|
premiumContent.className = ''; |
|
|
|
// Inser the lead in the right place in the article body. |
|
premiumContentText.insertAdjacentElement('afterBegin', articleLead); |
|
|
|
// Create a new wrapper with the article and insert it under the article header. |
|
const newArticleWrapper = document.createElement('div'); |
|
newArticleWrapper.setAttribute('id', 'new-article'); |
|
newArticleWrapper.appendChild(premiumContent); |
|
articleHeader.insertAdjacentElement('afterEnd', newArticleWrapper); |
|
|
|
// First attempt to start removing ads since they don't allow adblock. Not working too great atm. |
|
const ads = document.getElementsByClassName('ad'); |
|
for (let ad of ads) { |
|
ad.remove(); |
|
} |
|
} |
|
})(); |