took too long to edit:
so basically
<a href="https://www.youtube.com/channel/UC0-p-Hmc92YCtI8s3PEHC3A">greasescript</a>
or
<div id="container" class="style-scope ytd-channel-name">
<div id="text-container" class="style-scope ytd-channel-name">
<yt-formatted-string id="text" link-inherit-color="" title="" class="style-scope ytd-channel-name">MewZe</yt-formatted-string>
<a href="https://www.youtube.com/channel/UC0-p-Hmc92YCtI8s3PEHC3A">greasescript</a>
</div>
document.querySelector('#container.ytd-channel-name').insertAdjacentHTML('afterend',
`<a href="https://www.youtube.com/channel/${document.querySelector('link[rel="canonical"][href]').href.split('/').pop()}">greasescript</a>`);
But your way of getting the channel-id is complete bullshit. Use better way to get it
document.body.querySelector('ytd-watch-flexy')?.playerData?.videoDetails.channelId
oh wow, thank you very much
But your way of getting the channel-id is complete bullshit. Use better way to get it
heh, I'm sorry. I just wanted to show what I meant. I don't even know what type of call that is. DOM, JS, etc. ?
I think you had too much faith in me. I pasted the code in tamper and grease and nothing shows up. Tinkered a bit with the selector but nothing.
Yes, I thought that if you inserted the code, then it was you who wrote it, heh
Read about ways to add html
// universal
https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML
// around
https://developer.mozilla.org/en-US/docs/Web/API/Element/after
https://developer.mozilla.org/en-US/docs/Web/API/Element/before
// inside
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
https://developer.mozilla.org/en-US/docs/Web/API/Element/append
There is such a thing as. It specifies when to run the code. Before page load or after.
// @run-at document-start
OR
// @run-at document-end
obviously what you need after. Since you need to wait for the ytd-watch-flexy
element to appear
p.s. it is possible and up to but more complex designs are needed. If you want to dive, then here
In general, the code can be directly tested (without monkeys) if you paste it into the browser console Try pasting this code into the console. Should add a link.
document.querySelector('#container.ytd-channel-name')
.insertAdjacentHTML('afterend',
`<a href="https://www.youtube.com/channel/${document.querySelector('link[rel="canonical"][href]').href.split('/').pop()}">greasescript</a>`);
The complete code looks like this
// ==UserScript==
// @name 111
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/watch?v=*
// @version 1.0
// @run-at document-end
// ==/UserScript==
waitForElement('#upload-info #channel-name a[href]')
.then(element => {
element.insertAdjacentHTML('afterend',
`<a href="https://www.youtube.com/channel/${document.querySelector('link[rel="canonical"][href]').href.split('/').pop()}">greasescript2</a>`
)
});
function waitForElement(selector = required()) {
if (typeof selector !== 'string') return console.error('wait > selector:', typeof selector);
return new Promise((resolve, reject) => {
// try {
let nodeInterval
const checkIfExists = () => {
if (el = document.querySelector(selector)) {
if (typeof nodeInterval === 'number') clearInterval(nodeInterval);
resolve(el);
} else return;
}
checkIfExists();
nodeInterval = setInterval(checkIfExists, 150); // ms
// } catch (err) { // does not output the reason/line to the stack
// reject(new Error('Error waitElement', err));
// }
});
}
The problem is that youtube is loaded in parts. And not entirely as a static page. Therefore, you need to find the time or trigger to understand when the desired element appeared and only then run our code
omfg I tried to modify the element selectors but no idea what I'm doing wrong.
btw my example was for the profile page. the canonical is different on video pages.
but, if you can make it work with the document.body.querySelector('ytd-watch-flexy')?.playerData?.videoDetails.channelId
on video pages, I think that would be even better.
// ==UserScript==
// @name lerma-yt
// @namespace https://greasyfork.org/en/discussions/requests/183547-youtube-com-create-anchor-for-channelid-next-to-title-or-wherever-channel-s-uid
// @match https://www.youtube.com/*
// @version 1.0
// @run-at document-end
// ==/UserScript==
waitForElement('#channel-header ytd-channel-name, #upload-info #channel-name a[href]')
.then(element => {
element.insertAdjacentHTML('afterend',
`<a href="https://www.youtube.com/channel/${document.querySelector('document.querySelector('link[itemprop="url"][href]')?.href.split('/')[4] || document.body.querySelector('ytd-watch-flexy')?.playerData?.videoDetails.channelId}">channel link</a>`
)
});
function waitForElement(selector = required()) {
if (typeof selector !== 'string') return console.error('wait > selector:', typeof selector);
return new Promise((resolve, reject) => {
// try {
let nodeInterval
const checkIfExists = () => {
if (el = document.querySelector(selector)) {
if (typeof nodeInterval === 'number') clearInterval(nodeInterval);
resolve(el);
} else return;
}
checkIfExists();
nodeInterval = setInterval(checkIfExists, 150); // ms
// } catch (err) { // does not output the reason/line to the stack
// reject(new Error('Error waitElement', err));
// }
});
}
:S I'm getting Syntax error?
with violentmonkey. tamper gives error on line 13
<3
remove ('document.querySelector
perfection. amazing.
very happy.
thank you very much <3
super blind. should've figured out this myself. the line 13. AD&D etc
seems like youtube is or already was doing this. I just never bothered to look over these links whenever I opened the description box. thanks asmongold for being too lazy to have an advertisement description box.
https://i.postimg.cc/wMDtYL54/image.png
but i prefer the script either way. thank you
if you need to open a "video" tab instead of "featured"
that is, implementation is much simpler - redirection
There are alternative scripts above
no I wanted the channel's UID page in case the person gets hacked or renames or whatever.
holy cow, I don't think I've heard of Nova Youtube. I'll give it a try.
hello
can someone create a script that creates an <a> next to
taking the value from