DT+ hider

Hides all articles that is hidden behind a paywall

  1. // ==UserScript==
  2. // @name DT+ hider
  3. // @namespace Danielv123
  4. // @version 1.1
  5. // @description Hides all articles that is hidden behind a paywall
  6. // @author Danielv123
  7. // @match https://www.dt.no/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. // remove articles on frontpage
  14. let paidArticles = document.querySelectorAll(".df-skin-paywall");
  15. let numberOfFreeArticles = document.querySelectorAll(".df-article").length - paidArticles.length;
  16. console.log("Removed " + paidArticles.length + " paid articles, " + numberOfFreeArticles + " free articles left.");
  17. for(let i = 0; i < paidArticles.length;i++){
  18. paidArticles[i].style.display = "none";
  19. }
  20.  
  21. // Let's check if the browser supports notifications
  22. if (!("Notification" in window)) {
  23. }
  24.  
  25. // Let's check whether notification permissions have already been granted
  26. else if (Notification.permission === "granted") {
  27. // If it's okay let's create a notification
  28. if(paidArticles.length > 0 && numberOfFreeArticles > 0){
  29. var notification = new Notification("Removed " + paidArticles.length + " paid articles, " + numberOfFreeArticles + " free articles left.");
  30. }
  31. }
  32.  
  33. // Otherwise, we need to ask the user for permission
  34. else if (Notification.permission !== 'denied') {
  35. Notification.requestPermission(function (permission) {
  36. // If the user accepts, let's create a notification
  37. if (permission === "granted") {
  38. if(paidArticles.length > 0 && numberOfFreeArticles > 0){
  39. var notification = new Notification("Removed " + paidArticles.length + " paid articles, " + numberOfFreeArticles + " free articles left.");
  40. }
  41. }
  42. });
  43. }
  44. // remove articles on article pages
  45. // find the + sign and trace article box from parentElements
  46. // timeout apparently required
  47. setTimeout(function(){
  48. paidArticles = document.querySelectorAll(".am-premium-logo--imageoverlay");
  49. for(let i = 0; i < paidArticles.length;i++){
  50. paidArticles[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.display = "none";
  51. }
  52. if(paidArticles && paidArticles.length > 0){
  53. console.log("Removed " + paidArticles.length + " paid articles");
  54. }
  55. },1000);
  56. })();