40 lines
921 B
JavaScript
40 lines
921 B
JavaScript
function ignoreInjectionError() {
|
|
if (chrome.runtime.lastError) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
function includeFiles(tabID) {
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tabID },
|
|
files: [ 'files/script/jquery-3.2.1.min.js' ]
|
|
}, function() {
|
|
if (chrome.runtime.lastError) {
|
|
return;
|
|
}
|
|
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tabID },
|
|
files: [ 'files/script/postload.js' ]
|
|
}, ignoreInjectionError);
|
|
|
|
chrome.scripting.insertCSS({
|
|
target: { tabId: tabID },
|
|
files: [ 'files/css/style.css' ]
|
|
}, ignoreInjectionError);
|
|
});
|
|
}
|
|
|
|
function includeFilesInOpenYouTubeTabs() {
|
|
chrome.tabs.query({
|
|
url: [ '*://youtube.com/*', '*://www.youtube.com/*' ]
|
|
}, function(tabs) {
|
|
for (var i = 0; i < tabs.length; i++) {
|
|
includeFiles(tabs[i].id);
|
|
}
|
|
});
|
|
}
|
|
|
|
chrome.runtime.onInstalled.addListener(includeFilesInOpenYouTubeTabs);
|
|
chrome.runtime.onStartup.addListener(includeFilesInOpenYouTubeTabs);
|