Browse Source

Load content script only for audio files.

tags/v0.1.0
Gerben 5 years ago
parent
commit
c8e205f9e6
2 changed files with 23 additions and 6 deletions
  1. +2
    -6
      app/manifest.json
  2. +21
    -0
      app/scripts/background.js

+ 2
- 6
app/manifest.json View File

@@ -8,12 +8,8 @@
"scripts/background.js"
]
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["scripts/contentscript.js"],
"run_at": "document_end"
}],
"permissions": [
"activeTab"
"<all_urls>",
"webRequest"
]
}

+ 21
- 0
app/scripts/background.js View File

@@ -0,0 +1,21 @@
async function onHeadersReceived({ responseHeaders, url, tabId }) {
const isAudio = responseHeaders.some(header =>
header.name === 'Content-Type' && header.value.startsWith('audio/')
);

if (isAudio) {
browser.tabs.executeScript(tabId, {
runAt: 'document_end',
file: '/scripts/contentscript.js',
});
}
}

browser.webRequest.onHeadersReceived.addListener(
onHeadersReceived,
{
urls: ['<all_urls>'],
types: ['main_frame'],
},
['responseHeaders'],
);

Loading…
Cancel
Save