Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Berlingske Content Unhider (More Aggressive)
- // @namespace http://tampermonkey.net/
- // @version 0.4
- // @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.
- // @author Your Name
- // @match https://www.berlingske.dk/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- console.log('Berlingske Content Unhider (Aggressive) script started.');
- // Function to apply unhiding styles and hide/remove potential overlays
- function applyUnhideStyles() {
- const body = document.body;
- const html = document.documentElement;
- if (body) {
- // 1. Ensure Body and HTML are visible and scrollable
- // Use !important and try to override styles directly
- body.style.setProperty('display', 'block', 'important');
- body.style.setProperty('visibility', 'visible', 'important');
- body.style.setProperty('overflow', 'auto', 'important');
- body.style.setProperty('position', 'static', 'important'); // Sometimes fixed positioning is used
- body.style.setProperty('pointer-events', 'auto', 'important'); // Ensure mouse events work
- html.style.setProperty('overflow', 'auto', 'important');
- html.style.setProperty('pointer-events', 'auto', 'important');
- // Remove any classes that might prevent scrolling or hide content
- body.classList.remove('no-scroll', 'overflow-hidden', 'modal-open');
- html.classList.remove('no-scroll', 'overflow-hidden', 'modal-open');
- console.log('Applied unhide styles and enabled scrolling on body and html.');
- // 2. Attempt to hide and remove common overlay/paywall elements
- // Added more common selectors and targeting specific IDs/classes
- const overlaySelectors = [
- '.ap_modal_wrapper', // Identified in your HTML
- '.modal',
- '.paywall',
- '.paywall-overlay',
- '[id*="modal"]', // Elements with "modal" in ID
- '[class*="modal"]', // Elements with "modal" in class
- '[id*="paywall"]', // Elements with "paywall" in ID
- '[class*="paywall"]', // Elements with "paywall" in class
- '.article-paywall',
- '.logged-out-nag',
- '.overlay', // More generic
- '.dialog-container',
- '#fusion-paywall-overlay', // Specific ID example (might vary)
- '.tp-modal', // Example based on common third-party paywalls
- '.tp-backdrop' // Example based on common third-party paywalls
- // **IMPORTANT:** You might need to inspect the live page source
- // (using browser developer tools, F12) to find the exact
- // class names or IDs of the overlay elements specific to Berlingske.
- // Add them to this list.
- ];
- let hiddenCount = 0;
- overlaySelectors.forEach(selector => {
- document.querySelectorAll(selector).forEach(element => {
- // Hide very aggressively
- element.style.setProperty('display', 'none', 'important');
- element.style.setProperty('visibility', 'hidden', 'important');
- element.style.setProperty('opacity', '0', 'important');
- element.style.setProperty('pointer-events', 'none', 'important'); // Disable interaction
- element.style.setProperty('z-index', '-9999', 'important'); // Send behind everything
- element.setAttribute('aria-hidden', 'true'); // For accessibility
- // Attempt to remove from DOM - this is the most aggressive step
- if (element.parentNode) {
- try {
- element.parentNode.removeChild(element);
- } catch (e) {
- // Handle potential errors if element is part of a complex structure
- console.warn("Could not remove overlay element:", element, e);
- }
- }
- hiddenCount++;
- });
- });
- if (hiddenCount > 0) {
- console.log(`Attempted to hide and remove ${hiddenCount} potential overlay elements.`);
- }
- // 3. Sometimes a semi-transparent background overlay is added separately
- const backgroundOverlaySelectors = [
- '.modal-backdrop',
- '.ap_modal_backdrop',
- '.tp-backdrop'
- ];
- backgroundOverlaySelectors.forEach(selector => {
- document.querySelectorAll(selector).forEach(element => {
- if (element.parentNode) {
- try {
- element.parentNode.removeChild(element);
- } catch(e) {
- console.warn("Could not remove backdrop element:", element, e);
- }
- }
- });
- });
- // 4. Ensure main content area is visible (speculative - might need specific selector)
- // This part is harder without knowing the exact structure.
- // If you can identify the div/article holding the main text, add its selector here.
- // Example: const contentArea = document.querySelector('.article-content');
- // if (contentArea) {
- // contentArea.style.setProperty('display', 'block', 'important');
- // contentArea.style.setProperty('visibility', 'visible', 'important');
- // contentArea.style.setProperty('opacity', '1', 'important');
- // console.log('Applied styles to potential content area.');
- // }
- } else {
- console.log('Body element not found yet.');
- }
- }
- // --- Execution Strategy ---
- // Run immediately and then repeatedly for a few seconds to counter dynamic changes.
- // A MutationObserver would be more precise but is more complex.
- // Repeated attempts are a simpler, though less efficient, way to fight re-hiding.
- applyUnhideStyles(); // Run once immediately
- // Run periodically to catch elements added or styles reapplied by site scripts
- let attempts = 0;
- const maxAttempts = 50; // Run for about 5 seconds (50 * 100ms)
- const intervalTime = 100; // Check every 100 milliseconds
- const interval = setInterval(() => {
- if (attempts < maxAttempts) {
- applyUnhideStyles();
- attempts++;
- // console.log(`Unhide attempt ${attempts}/${maxAttempts}`); // Uncomment for debugging logs
- } else {
- clearInterval(interval);
- console.log('Stopped repeated unhiding attempts after max attempts.');
- }
- }, intervalTime);
- // Optional: Clean up interval if the user navigates away
- window.addEventListener('beforeunload', () => {
- clearInterval(interval);
- console.log('Cleared unhiding interval on page unload.');
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment