SC2Casts.com Adblock Nag Screen Remover

Removes the 'disable Adblock' nag screen.

Ekde 2016/05/15. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         SC2Casts.com Adblock Nag Screen Remover
// @namespace    http://lazy.artifact
// @version      0.23
// @description  Removes the 'disable Adblock' nag screen.
// @author       Lazy Artifact
// @match        http://sc2casts.com/*
// @grant        none
// ==/UserScript==

(function() {

    var divs = document.getElementsByTagName('div'),
        adBlockRegex = /Ad[-_\s]*Block/i,
        showSignUpElements = document.querySelectorAll('[onclick="showSignUp()"]'),
        playAllElement,
        char,
        i,
        j,
        youTube =
        {
            url: 'https://www.youtube.com/watch_videos?video_ids=',
            videoIds: [],
            videoElements:  document.querySelectorAll('iframe#ytplayer')
        },
        divParent = null,
        divChildren = null,
        parentRemoved = false;

    //remove nag screen
    for(i = 0; i < divs.length; i++) {
        
        if(divs[i].id === null || divs[i].id === undefined || divs[i].id === "") {
            continue;
        }

        divParent = divs[i];
        divChildren = divs[i].children;

        for(j = 0; j < divChildren.length; j++) {

            if(divChildren[j].innerText !== null &&
               divChildren[j].innerText !== undefined &&
               divChildren[j].innerText !== "" &&
               adBlockRegex.test(divChildren[j].innerText)) {

                divParent.parentElement.removeChild(divParent);

                parentRemoved = true;

                break;
            }
        }

        if (parentRemoved) {
            break;
        }

    }

    

    if(youTube.videoElements.length < 1) {
        return;
    }

    //get YouTube video Ids
    for(i = 0; i < youTube.videoElements.length; i++) {
        
        youTube.videoIds[i] = '';

        for(j = youTube.videoElements[i].src.lastIndexOf('/') + 1, char = youTube.videoElements[i].src[j]; char !== '?'; j++, char = youTube.videoElements[i].src[j]) {

            youTube.videoIds[i] += char;

        }


    }

    //remove signup popup listener and add a new play all click event
    for(i = 0; i < showSignUpElements.length; i++) {

        if(showSignUpElements[i].textContent && showSignUpElements[i].textContent === 'Play all') {

            playAllElement = showSignUpElements[i];
            playAllElement.removeAttribute('onclick');
            
            break;
        }

    }

    youTube.url += youTube.videoIds.join(',');

    playAllElement.addEventListener('click', function() {
        window.open(youTube.url, '_blank');
    }, false);

})();