I created something a bit like this some time ago .I hope the below guidelines would help
manifest.json
{
"manifest_version": 2,
"content_scripts": [ {
"all_frames": true,
"css": [ "ol.css" ],
"js": [ "jquery.js","ol.js"],
"matches": [ "*://www.youtube.com/*"]
} ],
"name": "Thumbnail overlay",
"version": "1.1",
"permissions": [ "tabs", "*://www.youtube.com/*","https://yoursite.com/*" ,"webNavigation"],
"web_accessible_resources": [ "ol.css" ,"ol.js" ,"jquery.js"],
"background": {
"scripts": ["background.js"]
}
}
ol.css and ol.js are where you would write your code
Now every thumbs is in its container with class .yt-uix-simple-thumb-related
also it holds the corresponding video id in its data attribute
ol.js
thmbColl = $('.yt-uix-simple-thumb-related>img') // collect all thmbs
thmbColl.each(function(){
var url= $(this).parent().data("vid"); //thmb's parent holds video id
//create and append a dynamic span with vid-id
$(this).after('<span class="my-notifier" data-url="'+url+'">demo</span>');
});
$('.my-notifier').click(function(e){
e.preventDefault();
e.stopPropagation();
alert('clicked! sendin video ID to svr');
$.ajax({
url:'http://yoursite.com/andPath',
data:$(this).data("url"),
success: function(data){
$(this).parent().parent().trigger('click');
} //trigger a click on thmb's grandfather (wiz. anchor) to switch video
});
});
background.js
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
chrome.tabs.executeScript(null,{file:"ol.js"});
});
Since youtube used PJAX rather than actuall page refresh , above code fixes the problem of youtube navigation not firing script it hooks on chrome.webNavigation
to execute your js everytime state is manipulated more here.Now comes the hardest part (at least for me) you need work out appropriate css to make the dynamic span appear on thumbnail put that in ol.css, don't look at me :p i don't know any css