Guest User

Berlingske ip block workaround

a guest
May 9th, 2025
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | Source Code | 0 0
  1.  
  2.  
  3. // ==UserScript==
  4. // @name Berlingske Content Unhider (More Aggressive)
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.4
  7. // @description Attempts more aggressively to make hidden article content visible on Berlingske by repeatedly overriding body/content styles and removing potential overlays. May significantly break other site functionality.
  8. // @author Your Name
  9. // @match https://www.berlingske.dk/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. console.log('Berlingske Content Unhider (Aggressive) script started.');
  17.  
  18. // Function to apply unhiding styles and hide/remove potential overlays
  19. function applyUnhideStyles() {
  20. const body = document.body;
  21. const html = document.documentElement;
  22.  
  23. if (body) {
  24. // 1. Ensure Body and HTML are visible and scrollable
  25. // Use !important and try to override styles directly
  26. body.style.setProperty('display', 'block', 'important');
  27. body.style.setProperty('visibility', 'visible', 'important');
  28. body.style.setProperty('overflow', 'auto', 'important');
  29. body.style.setProperty('position', 'static', 'important'); // Sometimes fixed positioning is used
  30. body.style.setProperty('pointer-events', 'auto', 'important'); // Ensure mouse events work
  31.  
  32. html.style.setProperty('overflow', 'auto', 'important');
  33. html.style.setProperty('pointer-events', 'auto', 'important');
  34.  
  35.  
  36. // Remove any classes that might prevent scrolling or hide content
  37. body.classList.remove('no-scroll', 'overflow-hidden', 'modal-open');
  38. html.classList.remove('no-scroll', 'overflow-hidden', 'modal-open');
  39.  
  40. console.log('Applied unhide styles and enabled scrolling on body and html.');
  41.  
  42. // 2. Attempt to hide and remove common overlay/paywall elements
  43. // Added more common selectors and targeting specific IDs/classes
  44. const overlaySelectors = [
  45. '.ap_modal_wrapper', // Identified in your HTML
  46. '.modal',
  47. '.paywall',
  48. '.paywall-overlay',
  49. '[id*="modal"]', // Elements with "modal" in ID
  50. '[class*="modal"]', // Elements with "modal" in class
  51. '[id*="paywall"]', // Elements with "paywall" in ID
  52. '[class*="paywall"]', // Elements with "paywall" in class
  53. '.article-paywall',
  54. '.logged-out-nag',
  55. '.overlay', // More generic
  56. '.dialog-container',
  57. '#fusion-paywall-overlay', // Specific ID example (might vary)
  58. '.tp-modal', // Example based on common third-party paywalls
  59. '.tp-backdrop' // Example based on common third-party paywalls
  60. // **IMPORTANT:** You might need to inspect the live page source
  61. // (using browser developer tools, F12) to find the exact
  62. // class names or IDs of the overlay elements specific to Berlingske.
  63. // Add them to this list.
  64. ];
  65.  
  66. let hiddenCount = 0;
  67. overlaySelectors.forEach(selector => {
  68. document.querySelectorAll(selector).forEach(element => {
  69. // Hide very aggressively
  70. element.style.setProperty('display', 'none', 'important');
  71. element.style.setProperty('visibility', 'hidden', 'important');
  72. element.style.setProperty('opacity', '0', 'important');
  73. element.style.setProperty('pointer-events', 'none', 'important'); // Disable interaction
  74. element.style.setProperty('z-index', '-9999', 'important'); // Send behind everything
  75. element.setAttribute('aria-hidden', 'true'); // For accessibility
  76.  
  77. // Attempt to remove from DOM - this is the most aggressive step
  78. if (element.parentNode) {
  79. try {
  80. element.parentNode.removeChild(element);
  81. } catch (e) {
  82. // Handle potential errors if element is part of a complex structure
  83. console.warn("Could not remove overlay element:", element, e);
  84. }
  85. }
  86. hiddenCount++;
  87. });
  88. });
  89. if (hiddenCount > 0) {
  90. console.log(`Attempted to hide and remove ${hiddenCount} potential overlay elements.`);
  91. }
  92.  
  93. // 3. Sometimes a semi-transparent background overlay is added separately
  94. const backgroundOverlaySelectors = [
  95. '.modal-backdrop',
  96. '.ap_modal_backdrop',
  97. '.tp-backdrop'
  98. ];
  99. backgroundOverlaySelectors.forEach(selector => {
  100. document.querySelectorAll(selector).forEach(element => {
  101. if (element.parentNode) {
  102. try {
  103. element.parentNode.removeChild(element);
  104. } catch(e) {
  105. console.warn("Could not remove backdrop element:", element, e);
  106. }
  107. }
  108. });
  109. });
  110.  
  111. // 4. Ensure main content area is visible (speculative - might need specific selector)
  112. // This part is harder without knowing the exact structure.
  113. // If you can identify the div/article holding the main text, add its selector here.
  114. // Example: const contentArea = document.querySelector('.article-content');
  115. // if (contentArea) {
  116. // contentArea.style.setProperty('display', 'block', 'important');
  117. // contentArea.style.setProperty('visibility', 'visible', 'important');
  118. // contentArea.style.setProperty('opacity', '1', 'important');
  119. // console.log('Applied styles to potential content area.');
  120. // }
  121.  
  122.  
  123. } else {
  124. console.log('Body element not found yet.');
  125. }
  126. }
  127.  
  128. // --- Execution Strategy ---
  129. // Run immediately and then repeatedly for a few seconds to counter dynamic changes.
  130. // A MutationObserver would be more precise but is more complex.
  131. // Repeated attempts are a simpler, though less efficient, way to fight re-hiding.
  132.  
  133. applyUnhideStyles(); // Run once immediately
  134.  
  135. // Run periodically to catch elements added or styles reapplied by site scripts
  136. let attempts = 0;
  137. const maxAttempts = 50; // Run for about 5 seconds (50 * 100ms)
  138. const intervalTime = 100; // Check every 100 milliseconds
  139.  
  140. const interval = setInterval(() => {
  141. if (attempts < maxAttempts) {
  142. applyUnhideStyles();
  143. attempts++;
  144. // console.log(`Unhide attempt ${attempts}/${maxAttempts}`); // Uncomment for debugging logs
  145. } else {
  146. clearInterval(interval);
  147. console.log('Stopped repeated unhiding attempts after max attempts.');
  148. }
  149. }, intervalTime);
  150.  
  151.  
  152. // Optional: Clean up interval if the user navigates away
  153. window.addEventListener('beforeunload', () => {
  154. clearInterval(interval);
  155. console.log('Cleared unhiding interval on page unload.');
  156. });
  157.  
  158.  
  159. })();
  160.  
Advertisement
Add Comment
Please, Sign In to add comment