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.9
// @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.10 - Add video Id xvFZjo5PgG0
// 0.9 - Add video Id rTgj1HxmUbg; Switch to a method that's easier to expand upon
// 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 basicFilter = [
/(?:youtu\.be\/|youtube(?:-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))([\w\-]{11})/i,
/(?:youtu\.be\/|youtube(?:-nocookie)?.com\/(?:attribution_link\?.*))([\w\-])/i
];
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
var ids = [
"dQw4w9WgXcQ",
"oHg5SJYRHA0",
"DLzxrzFCyOs",
"ub82Xb1C8os",
"rTgj1HxmUbg",
"xvFZjo5PgG0"
];
ids = ids.map(function (v) {
var base = v.substring(0, v.length - 1);
var last = b64.indexOf(v.substring(v.length - 1));
if (last < 0) {
return [v];
}
return [
base + b64.substr(last, 1),
base + b64.substr(last + 1, 1),
base + b64.substr(last + 2, 1),
base + b64.substr(last + 3, 1)
];
}).reduce(function (a, b) {
return a.concat(b);
}, []);
var isMatch = function (str) {
return basicFilter.filter(function (v) {
var m = str.match(v);
return (m instanceof Array) && ids.indexOf(m[1]) >= 0;
}).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.
*/
User Script Managers
A userscript manager is the browser extension that injects scripts into websites
to change their behavior to your liking.
Recommendation
All scripts on this site have been developed and tested with Tampermonkey on firefox.
Try other browsers and other script managers at your own risk.
No script should use firefox or chrome specific features,
which means they should also work in other modern browsers.
If you prefer, you can use greasemonkey.
Get Tampermonkey,
Get Greasemonkey (Firefox only)
Script Installation
Once you have obtained a user script manager,
clicking on the install button will pop up an installation prompt.
To allow script manager detection,
you can install this helper script.
It's not necessary but simplifies your future visits to this site.
Script Installation
We detected, that you have a script manager installed and active.
Click the "Install Script" button to obtain the script.