I am creating a Chrome Extension that will inject HTML on top of the related videos bar of a YouTube video.
This is the desired effect of the plugin.
Here is the manifest.json
:
{
// Required
"manifest_version": 2,
// App
"name": "...",
"version": "...",
"author": "...",
"description": "...",
"content_scripts": [
{
"run_at": "document_idle",
"matches": ["*://www.youtube.com/watch?v=*"],
"js": ["jquery-min-3.3.1.js", "inject.js"]
}
]
}
And here is inject.js
:
$(document).ready(function(){
$('#related').prepend('<h1>This was injected throught jQuery.</h1>');
});
When the extension is loaded into Chrome and a YouTube video page is loaded, the script seems to work for a second. The h1
in injected at the top of the #related
bar until related video thumbnails start to load. Then the injected h1
quickly is pushed to the bottom as each new thumbnail loads.
I'm guessing this has something to do with YouTube using AJAX to load content. Is there a way to wait until all AJAX has been loaded before injecting HTML?