mirror of
https://github.com/peter-tanner/Redirect-octopart-datasheets.git
synced 2024-11-30 11:00:18 +08:00
v1.0
This commit is contained in:
commit
02e9b44285
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.zip
|
19
background.js
Normal file
19
background.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
browser.webRequest.onBeforeRequest.addListener(
|
||||
async (details) => {
|
||||
const url = details.url;
|
||||
const tabId = details.tabId;
|
||||
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
const regex = /"name":"Datasheet","page_count":\d+,"url":"([^"]+)"/;
|
||||
const match = html.match(regex);
|
||||
|
||||
if (match && match[1]) {
|
||||
// use first match - it seems like octopart's html viewer can render
|
||||
// multiple documents but i have not found an example of this.
|
||||
browser.tabs.update(tabId, { url: match[1] });
|
||||
}
|
||||
},
|
||||
{ urls: ["https://octopart.com/datasheet/*"], types: ["main_frame"] },
|
||||
["blocking"]
|
||||
);
|
17
manifest.json
Normal file
17
manifest.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Redirect Octopart datasheets",
|
||||
"version": "1.0",
|
||||
|
||||
"description": "View the original datasheet PDF in the browser's native PDF viewer instead of the Octopart's HTML PDF viewer.",
|
||||
|
||||
"background": {
|
||||
"persistent": true,
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"permissions": [
|
||||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"https://octopart.com/datasheet/*"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user