Greasy Fork is available in English.

Universal Domain Redirect

did someone change their domain but a imbed is still using the old one \n not anymore automaticaly change domains to fix this \n originaly made because aniwatch stoped working

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Universal Domain Redirect
// @namespace   Violentmonkey Scripts
// @version     1.2
// @description  did someone change their domain but a imbed is still using the old one \n not anymore automaticaly change domains to fix this \n originaly made because aniwatch stoped working
// @author       dindiner
// @match        *://*/*
// @exclude      *://*youtube*/*
// @run-at       document-start
// @grant        unsafeWindow
// @license MIT
// ==/UserScript==
(function(){
    'use strict';
  	const win=(unsafeWindow||window);
    const chnglst={
        // TLD-style rule
        //"megacloud": { ".blog": ".tv" },
        // Full domain swap (root + subdomains)
        "megacloud.blog": "megacloud.tv"
    };
    const transformUrl=(url)=>{
        try{
            const u=new URL(url);
            let host=u.hostname;
            for(const key in chnglst){
                const val=chnglst[key];
                if(typeof val==="string"){
                    if(host===key||host.endsWith("."+key)){
                        const prefix=host===key?"":host.replace("."+key,"");
                        host=prefix?`${prefix}.${val}`:val;
                    }
                }else if(typeof val==="object"){
                    for(const from in val){
                        const to=val[from];
                        if(host===key+from||host.endsWith("."+key+from)){
                            const prefix=host===key+from?"":host.replace("."+key+from,"");
                            host=prefix?`${prefix}.${key}${to}`:`${key}${to}`;
                        }
                    }
                }
            }
            u.hostname=host;
            return u.toString();
        }catch(e){
            return url;
        }
    };
    const redirected=transformUrl(win.location.href);
    if(redirected!==win.location.href){
        win.location.replace(redirected);
        return;
    }
    const fixIframes=()=>{
        document.querySelectorAll('iframe').forEach(iframe=>{
            if(iframe.src){
                const updated=transformUrl(iframe.src);
                if(updated!==iframe.src)iframe.src=updated;
            }
        });
    };
    const originalFetch=win.fetch;
    win.fetch=function(input,init){
        try{
            let url=(typeof input==="string")?input:input.url;
            const newUrl=transformUrl(url);
            if(typeof input==="string"){
                input=newUrl;
            }else{
                input=new Request(newUrl,input);
            }
        } catch(e){}
        return originalFetch.call(this,input,init);
    };
    const originalOpen=XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open=function(method,url,...rest){
        try{
            url=transformUrl(url);
        }catch(e){}
        return originalOpen.call(this,method,url,...rest);
    };
    const observer=new MutationObserver(fixIframes);
    const init=()=>{
        fixIframes();
        observer.observe(document.documentElement,{childList:true,subtree:true});
    };
    if (document.readyState==='loading'){
        document.addEventListener('DOMContentLoaded',init);
    }else{
        init();
    }
})();