Niconico 網址重新導向

自動將類似 acg.tv/sm* 的網址轉換為 nicovideo.jp/watch/sm* (包含網址參數)

目前為 2024-03-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name              Niconico URL 重定向
// @name:en           Niconico URL redirector
// @name:zh-TW        Niconico 網址重新導向
// @namespace         http://tampermonkey.net/
// @version           0.1
// @description       自动将类似 acg.tv/sm* 的 URL 转换为 nicovideo.jp/watch/sm* (包括 URL 参数)
// @description:en    Redirect URLs like acg.tv/sm* to nicovideo.jp/watch/sm* (including url arguments)
// @description:zh-TW 自動將類似 acg.tv/sm* 的網址轉換為 nicovideo.jp/watch/sm* (包含網址參數)
// @author            はなちゃん with help by Bing Copilot
// @match             *://*/*
// @grant             none
// @license           MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to redirect URLs
    function redirectUrls() {
        // Redirect current window URL
        if (window.location.href.includes("acg.tv/sm")) {
            window.location.href = window.location.href.replace("acg.tv/sm", "nicovideo.jp/watch/sm");
        }

        // Redirect URLs in href of a tags
        document.querySelectorAll('a').forEach(a => {
            if (a.href.includes("acg.tv/sm")) {
                a.href = a.href.replace("acg.tv/sm", "nicovideo.jp/watch/sm");
            }
        });
    }

    // Call the function initially
    redirectUrls();

    // Call the function 1s later, for later-render page.
    setInterval(() => { redirectUrls(); }, 1000);
})();