Greasy Fork

Greasy Fork is available in English.

随缘旧域名重定向

重定向旧域名到 mtslash.org。

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

"use strict";

/**
 * Created by Nb on 12/7/2016.
 * Transpiled from ES6 to ES5 by Babel.
 */

// ==UserScript==
// @name         MovieTV Slash Redirect
// @name:zh-CN   随缘旧域名重定向
// @name:zh-TW   隨緣舊域名重定向
// @namespace    NB-Kevin
// @version      0.1
// @description  Redirect old address.
// @description:zh-CN 重定向旧域名到 mtslash.org。
// @description:zh-TW 重定向舊域名 mtslash.org。
// @author       Nb/Kevin
// @match        http://*/*
// @match        https://*/*
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==

var OLD_ADDRESS = "www.movietvslash.com";
var ANOTHER_OLD_ADDRESS = "www.mtslash.com";
var NEW_ADDRESS = "www.mtslash.org";

/**
 * Convert a node list to array.
 * @returns {Array.<HTMLElement>}
 */
NodeList.prototype.toArray = function () {
    var that = this;
    return Array.prototype.slice.call(that);
};

var currentAddress = location.href.split('//')[1];
if (currentAddress.startsWith(OLD_ADDRESS) || currentAddress.startsWith(ANOTHER_OLD_ADDRESS)) {
    // Check whether current page is of the old address and
    // redirect if so.
    var targetAddress = location.href.replace(OLD_ADDRESS, NEW_ADDRESS).replace(ANOTHER_OLD_ADDRESS, NEW_ADDRESS);
    console.log("Redirecting to " + targetAddress + "...");
    location.replace(targetAddress);
} else {
    // otherwise check all href link and replace them with new address
    addEventListener('load', function (event) {
        var targetElements = document.querySelectorAll("[href*=\"" + OLD_ADDRESS + "\"]").toArray().concat(document.querySelectorAll("[href*=\"" + ANOTHER_OLD_ADDRESS + "\"]").toArray());
        targetElements.forEach(function (element) {
            var newAddress = element.getAttribute('href').replace(OLD_ADDRESS, NEW_ADDRESS).replace(ANOTHER_OLD_ADDRESS, NEW_ADDRESS);
            console.log("Redirecting " + element.getAttribute('href') + " to " + newAddress + "...");
            element.setAttribute('href', newAddress);
        });
    });
}