Advertisement
borlabs

Custom Button

Apr 3rd, 2024 (edited)
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.   const config = {
  3.     referenceButtonClass: 'brlbs-btn-accept-all', // Possible values: brlbs-btn-accept-all, brlbs-btn-save, brlbs-btn-accept-only-essential, brlbs-cmpnt-btn-preferences
  4.     buttonPosition: 'before', // Possible values: after, before
  5.     buttonText: 'Gib Geld',
  6.     buttonUrl: 'https://URL-ZUR-SEITE-BZGL-ABO',
  7.     maxAttempts: 20 // Attempts to find the dialog
  8.   };
  9.  
  10.   function createCustomButton(container, config) {
  11.     const newButton = document.createElement('button');
  12.     newButton.className = 'brlbs-cmpnt-btn brlbs-cmpnt-font-semibold brlbs-cmpnt-w-full';
  13.     Object.assign(newButton.style, {
  14.       '--tw-ring-color': 'var(--dialog-button-accept-all-color-hover)',
  15.       background: 'var(--dialog-button-accept-all-color)',
  16.       color: 'var(--dialog-button-accept-all-text-color)'
  17.     });
  18.     newButton.textContent = config.buttonText;
  19.     newButton.onclick = function() { window.location.href = config.buttonUrl; };
  20.     const newDiv = document.createElement('div');
  21.     newDiv.appendChild(newButton);
  22.    
  23.     if (config.buttonPosition === 'after') {
  24.       container.parentNode.insertBefore(newDiv, container.nextSibling);
  25.     } else {
  26.       container.parentNode.insertBefore(newDiv, container);
  27.     }
  28.   }
  29.  
  30.   function initCustomButton(config, attempts = 0) {
  31.     const dialogReferenceButton = document.querySelector(`.brlbs-cmpnt-dialog-iab-tcf-entrance button.${config.referenceButtonClass}`)?.parentElement;
  32.     if (dialogReferenceButton) {
  33.       createCustomButton(dialogReferenceButton, config);
  34.     } else if (attempts < config.maxAttempts) {
  35.       setTimeout(() => initCustomButton(config, attempts + 1), 50);
  36.     }
  37.   }
  38.  
  39.   document.addEventListener('DOMContentLoaded', () => initCustomButton(config));
  40. })();
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement