I'm trying to get the YouTube logo link on the site to link to my subscriptions by using Tampermonkey.

This is what I'm trying to change

<a id="logo-container" href="/" title="YouTube home" class=" "><img id="logo" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="YouTube home"><span class="content-region">NL</span></a>

I'm trying to change the

href="/"

to

href="/feed/subscriptions"

This is the code I am using now and I have no idea why it doesn't work

var newURL = "/feed/subscriptions";
onload=function() {
    var dt = document.getElementById("logo-container");
    document.body.innerHTML = dt.getAttributeNode("href").value.replace("/",newURL);
}   
有帮助吗?

解决方案

document.body.innerHTML = dt.getAttributeNode("href").value.replace("/",newURL);

You're setting the HTML of the <body> tag to a string. What did you expect this to do?

If all you're trying to do is modify the href attribute on the <a> tag, try instead doing something more like:

document.getElementById('logo-container').href = "/feed/subscriptions";
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top