Skip to content

Commit

Permalink
Run content_script on install for YouTube tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
AleshaOleg committed Apr 5, 2020
1 parent 5250cd2 commit 325487b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
19 changes: 18 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mapIcons = {
env.runtime.onMessage.addListener(message => {
if (message.action === 'updateIcon') {
const type = mapIcons[message.icon]
chrome.browserAction.setIcon({
env.browserAction.setIcon({
path: {
16: `./assets/toolbar/${type}/16.png`,
24: `./assets/toolbar/${type}/24.png`,
Expand All @@ -26,4 +26,21 @@ const mapIcons = {
})
}
})

env.runtime.onInstalled.addListener(({ reason }) => {
switch (reason) {
case 'install':
env.tabs.getAllInWindow(null, tabs => {
tabs.forEach(tab => {
const { hostname, pathname } = new URL(tab.url)
if (hostname === 'www.youtube.com' && pathname === '/watch') {
env.tabs.executeScript(tab.id, { file: 'index.js' })
}
})
})
break
default:
break
}
})
})()
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@ const adjustQuality = () => {
}
}
})

env.runtime.onMessage.addListener((msg, _, sendResponse) => {
if (msg.action === 'getDOM') {
sendResponse({
document,
})
}
})
})()
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"description": "Adjust quality of YouTube videos automatically",
"permissions": [
"storage",
"tabs"
"tabs",
"http://*/",
"https://*/"
],
"browser_specific_settings": {
"gecko": {
Expand Down

0 comments on commit 325487b

Please sign in to comment.