YouTube Anti-RickRoll

Give a warning alert if video is suspected RickRoll.

目前為 2024-11-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        YouTube Anti-RickRoll
// @match       *://*.youtube.com/watch*
// @grant       none
// @version     1.0
// @author      yodaluca23
// @license      GNU GPLv3
// @description Give a warning alert if video is suspected RickRoll.
// @namespace https://greasyfork.org/users/1315976
// ==/UserScript==

const jsonUrl = 'https://raw.githubusercontent.com/larssieboy18/rickroll-list/refs/heads/main/rickrolls.json';

// Function to fetch JSON and extract YouTube IDs from GitHub database
async function extractYouTubeIDs() {
    try {
        const response = await fetch(jsonUrl);
        const data = await response.json();

        const youtubeRegex = /(?:youtube\.com\/watch\?v=|youtu\.be\/|video_id=)([\w-]+)/g;

        const links = data.rickrolls || [];

        const youtubeIDs = [];
        for (const link of links) {
            let match;
            while ((match = youtubeRegex.exec(link)) !== null) {
                youtubeIDs.push(match[1]);
            }
        }

        return youtubeIDs;
    } catch (error) {
        console.error('Error fetching or processing data:', error);
        return [];
    }
}

// Function to check if the video is a Rickroll
function isRickRoll() {
    try {
        const videoTitle = unsafeWindow.ytInitialPlayerResponse.videoDetails.title.toLowerCase().replace(/\s+/g, '');
        const videoKeywords = unsafeWindow.ytInitialPlayerResponse.videoDetails.keywords.map(keyword => keyword.toLowerCase().replace(/\s+/g, ''));

        const rickrollPattern = /(rickroll|rickastley)/;

        if (videoTitle.match(rickrollPattern) || videoKeywords.some(keyword => keyword.match(rickrollPattern))) {
            return true;
        }
    } catch (e) {
        console.error('Error while checking video details:', e);
    }
    return false;
}

// Function to display warning
function warning() {
    document.querySelector('video').pause();
    alert("This is likely a RickRoll! Do you want to continue?");
}

// Main logic
extractYouTubeIDs().then((ids) => {
    const currentVideoID = window.location.href.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/);

    if (currentVideoID && ids.includes(currentVideoID[1])) {
        warning();
    } else if (isRickRoll()) {
        warning();
    }
});