Rickroll Detect

Highlights rickrolls on the WaniKani forums

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Rickroll Detect
// @version      0.2
// @namespace    http://tampermonkey.net/
// @description  Highlights rickrolls on the WaniKani forums
// @author       BIsTheAnswer
// @include      https://community.wanikani.com/*
// @license      MIT; http://opensource.org/licenses/MIT
// @grant        none
// ==/UserScript==

(function() {
    /* global $ */
    /* eslint curly: off */

    'use strict';

    var rickroll_array = [
        'dQw4w9WgXcQ',
        'doEqUhFiQS4',
        'oHg5SJYRHA0'
    ];

    var rickroll_regex = /(https?:\/\/)?(www\.)?youtube\.[a-z]+\/watch\?v=([a-zA-Z0-9]+)([^a-zA-Z0-9].*)?/i;
    var rickroll_regex_short = /(https?:\/\/)?(www\.)?youtu\.be\/([a-zA-Z0-9]+)([^a-zA-Z0-9].*)?/i

    function mark_rickrolls() {
        $('a').filter(function() {
            var regex_result = this.href.match(rickroll_regex);
            if(regex_result == null) {
                regex_result = this.href.match(rickroll_regex_short);
                if(regex_result == null)
                    return false;
            }
            return rickroll_array.includes(regex_result[3]);
        }).css('background-color', 'rgb(255, 0, 0, 0.5)').css('border-bottom', '1px solid rgb(255,0,0,0.5)');
    }

    mark_rickrolls();

    var dom_watch = new MutationObserver(function() {
        mark_rickrolls();
    });
    dom_watch.observe(document.body, {childList: true, subtree: true});
})();