Anti Rickroll

Replaces the text of links to a certain video with "Probably rickroll"

Click here to install Browse More Scripts
// ==UserScript==
// @name         Anti Rickroll
// @namespace    415ed0ef1d938ec8976d8999b8ae3edf94db0ab3
// @version      0.8
// @description  Replaces the text of links to a certain video with "Probably rickroll"
// @author       /u/AyrA_ch
// @include      http://*/*
// @include      https://*/*
// @grant        none
// ==/UserScript==


//Changelog
// 0.8 - Add video Id DLzxrzFCyOs
// 0.7 - Add video Id ub82Xb1C8os
// 0.6 - Add video Id oHg5SJYRHA0
// 0.5 - Switch to MutationObserver
// 0.4 - Videos actually have four IDs. Check https://cable.ayra.ch/help/#youtube_id
// 0.3 - Attribution link handling
// 0.2 - Added handling for the fact that each video has two IDs
// 0.1 - Initial Version

(function () {
    'use strict';
    //this matches known youtube URLs for the video or similar videos
    var filters = [
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))(dQw4w9WgXc[QRST])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))(oHg5SJYRHA[0123])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))(DLzxrzFCyO[stuv])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))(ub82Xb1C8o[stuv])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:attribution_link\?.*))(dQw4w9WgXc[QRST])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:attribution_link\?.*))(oHg5SJYRHA[0123])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:attribution_link\?.*))(DLzxrzFCyO[stuv])/i,
        /(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:attribution_link\?.*))(ub82Xb1C8o[stuv])/i
    ];

    var isMatch = function (str) {
        return filters.filter(function (v) {
            return str.match(v);
        }).length > 0;
    };

    //Scan for rickroll links
    var scanRickRoll = function () {
        var a = document.querySelectorAll("a");
        for (var i = 0; i < a.length; i++) {

            if (a[i].href && isMatch(a[i].href)) {
                a[i].innerHTML = "<b>Probably rickroll</b>";
            }
        }
    };
    var scheduleUpdater = function () {
        if (!scheduleUpdater.timer) {
            scheduleUpdater.timer = window.setTimeout(function () {
                scanRickRoll();
                scheduleUpdater.timer = false;
            }, 500);
        }
    };
    scanRickRoll();
    var mo = new MutationObserver(scheduleUpdater);
    mo.observe(document.body, {
        subtree: true,
        attributes: true,
        childList: true
    });
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 3.232.129.123