Guest User

tampermonkey script - heise.de - remove consent elements

a guest
Aug 12th, 2024
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Remove Consent Elements
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2024-08-12
  5. // @description  Remove 'sp-message-open' class and elements with IDs starting with 'sp_message_container'
  6. // @author       Me
  7. // @match        https://www.heise.de/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=heise.de
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.  
  15.     // Function to remove the consent elements
  16.     function remove_consent_elements() {
  17.         // Remove the 'sp-message-open' class from elements
  18.         const elements_with_class = document.querySelectorAll('.sp-message-open');
  19.         elements_with_class.forEach(element => element.classList.remove('sp-message-open'));
  20.  
  21.         // Remove elements with IDs starting with 'sp_message_container'
  22.         const elements_with_id = document.querySelectorAll('[id^="sp_message_container"]');
  23.         elements_with_id.forEach(element => element.remove());
  24.     }
  25.  
  26.     // Initial removal of consent elements when the page loads
  27.     remove_consent_elements();
  28.  
  29.     // Create a MutationObserver to monitor changes in the DOM
  30.     const observer = new MutationObserver((mutations) => {
  31.         mutations.forEach((mutation) => {
  32.             mutation.addedNodes.forEach(node => {
  33.                 if (node.nodeType === 1) { // Ensure the node is an element
  34.                     const node_as_element = node;
  35.                     // Check if the added node matches the selectors
  36.                     if (node_as_element.matches('.sp-message-open') || node_as_element.matches('[id^="sp_message_container"]')) {
  37.                         remove_consent_elements();
  38.                     }
  39.                 }
  40.             });
  41.         });
  42.     });
  43.  
  44.     // Observe the entire document for changes in the DOM
  45.     observer.observe(document.body, {
  46.         childList: true,
  47.         subtree: true
  48.     });
  49.  
  50. })();
  51.  
Advertisement
Add Comment
Please, Sign In to add comment