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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
    }
})();