Thursday, March 2, 2017

My ad-block script

Why not using an add-on/extension like adblock etc.? Because many sites now block them! And they tend to block some wanted content while leave some unwanted unblocked.

You'll need to install the Greasemonkey (Firefox) or Violent Monkey (Chrome, Yandex and Opera). Then add a new script and copy & paste. All dynamic contents are removed; so be sure to add to the "NOT_TO_REMOVE" list the iframe src's that you do want to see! Or you may add exceptional line(s) like this within metadata block:

// @exclude     http://www.example.com/foo/baz

Now your browsers should be totally quiet without any unwanted moving stuff. Timers are removed too!

Related article: KoT's Dynamic Content BlockerMy script for blocking GIF

This script has been (on 03/09/2017) and will be updated without notice

// ==UserScript==
// @name         Block Marquee
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      http*://*/*
// @exclude      https://xfinity.nnu.com/xfinitywifi/main
// @exclude      https://www.blogger.com/*
// @exclude      https://groups.google.com/forum/*
// @grant        none
// ==/UserScript==
    
/* add your items to be not blocked */

var NOT_TO_REMOVE = 'iframe' +
':not([src*=\'youtu\'])' +
':not([src*=\'dailymotion\'])' +
':not([src*=\'youku\'])' +
':not([src*=\'tudou\'])' +
':not([src*=\'powermv\'])' +
':not([src*=\'dramafever\'])' +
':not([src*=\'vimeo\'])' +
':not([src*=\'liveguidestationplayer\'])' +
':not([src*=\'RoutePositionET\'])' +
':not([src*=\'blogger.com\'])' +
':not([src*=\'chase.com\'])' +
':not([src*=\'/tob/live/usp-core\'])'
;

/* add your items to be blocked */

var TO_REMOVE = 'div[id*=\'carousel\']' +
',div[id*=\'Carousel\']' 
;

function doRemove() {

  var m, i;
  
  if (window.top == window.self) {
      m = document.querySelectorAll(NOT_TO_REMOVE);
      for (var i = 0; i < m.length; i++) {
        m[i].parentNode.removeChild(m[i]);
      }
  }
  
  m = document.querySelectorAll(TO_REMOVE);
  for (i = 0; i < m.length; i++) {
    m[i].parentNode.removeChild(m[i]);
  }
  
  // Thanks to http://stackoverflow.com/a/8345837
  // Set a fake timeout to get the highest timeout id
  var highestTimeoutId = setTimeout(";");
  for (i = 0 ; i < highestTimeoutId ; i++) {
      clearTimeout(i); 
  }

}

var m, i;

/* block Special items */

m = document.getElementById('scrollWrap');
if (m !== null) {
  m.id = 'scrollWrap_';
  m = document.getElementById('scrollMsg');
  if (m !== null) {
    m.parentNode.removeChild(m);
  }
}

/* block common items */

m = document.getElementsByTagName('marquee');
for (i = 0; i < m.length; i++) {
  var p = document.createElement('div');
  p.innerHTML = m[0].innerHTML;
  p.setAttribute('style', 'width: 100%; clear: both;');
  m[0].parentNode.insertBefore(p, m[0]);
  m[0].parentNode.removeChild(m[0]);
}

//Don't run on frames or iframes
if (window.top !== window.self) 
    return;

doRemove(); window.addEventListener('load', doRemove, false);

No comments:

Post a Comment