Question : How to reference id of a link? See the attached image Click here
function insertButton(refresh = false) {
var to_match = 'a[class="';
var PAGE_TYPE = 0;
if (document.location.href == "https://www.youtube.com") {
How to reference id = "video-title-link"
var anchor_tag = document.getElementById("video-title-link");
There are 2 anchor tags* with the same class name. I would like to reference the id ="video-title-link"
if(anchor_tag.hasAttribute('href="\/watch\?v=(\S+)"')){
to_match = to_match.concat("yt-simple-endpoint style-scope ytd-rich-grid-video-renderer", '"]').getattribute('id ="video-title-link"');
PAGE_TYPE = 1;
}
}
UPDATE : POLLING
const poller = setInterval(function(){
const anchor_tags = document.querySelectorAll('a[id="video-title-link"]');
if(anchor_tags){
for (index = 0; index < anchor_tags.length ; index++){
console.log(anchor_tags[index].getAttribute('href'));
}
clearInterval(poller);
}
}, 1000);
OUTPUT : Click here : href of each 'id'