javascript - Using YouTube API to like a video after action done on a different website -


i'm trying code first google chrome extension , i'm kind of stuck on something. so, i'm trying make extension when user 'upvotes' link on reddit.com, , if it's youtube.com link, want grab link , 'like' video. it's turning 4-5 clicks one.

my main question how go listening 'upvote' button hit? need use reddit's api listen this? or there kind of method/event listener can tell me if user clicked upvote button?

i did notice when inspecting element on upvote button, when hasn't been clicked it, 1 of classes on arrows 'up' , when click it, changes 'upmod'

i need figure out , feel can rest ease. i'm teaching myself javascript right now, , find best way have project , learn make it.

any appreciated! thank you

since upvote triggered solely via clicking, attach click event listener in content script declared run on reddit video urls (https://www.reddit.com/r/videos/*, example):

document.addeventlistener('click', function(e) {     if (e.target.matches('.arrow.upmod')) {         ............         // on youtube         ............     } }); 

to upvote on youtube, you'll need in background/event page can connect urls declared in manifest.json's permissions.

so send message video url event page. in event page's message listener you'll send xmlhttprequest per youtube api, example. require adding api url in abovementioned permissions.


Comments