Discussions » Development

Allow Css on specific domain?

§
Posted: 2018/10/03
Edited: 2018/10/03

Allow Css on specific domain?

// ==UserScript==
// @name     Allow_only_on_main_of_youtube
// @match    https://www.youtube.com/
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==

GM_addStyle ( `

a{color:red!important}

`)

I'd convert give custom css only on "https://www.youtube.com/" but not other domains such as starts with "https://www.youtube.com/results*" or "https://www.youtube.com/watch*"

as the page do not refresh when move on another youtube site from the "www.youtube.com/" font color does not changed to red with the code.

§
Posted: 2018/10/03

youtube use a weird function to change the url location,blow code may work but not so perfectly

// ==UserScript==
// @name     Allow_only_on_main_of_youtube
// @match    https://www.youtube.com/
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==
const style = GM_addStyle ( `
a{color:red!important}
`);

window.addEventListener('yt-navigate-finish', function (){
    if (document.location.search!=""){
        style.innerHTML = "";
    }else{
        style.innerHTML = `a{color:red!important}`;
    }
});

§
Posted: 2018/10/03

I didn't know it could be hard to manage. as you mentioned, the code is not working fluently. however Thanks for spare your time for finding a solution. :)

woxxomMod
§
Posted: 2018/10/04

Also try yt-navigate-start instead of yt-navigate-finish

§
Posted: 2018/10/05

@wOxxOm as I'd tested, yt-navigate-start works better than the yt-navigate-finish, however still unstable to use though. Thanks for the suggestion :)

Post reply

Sign in to post a reply.