-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extension fetches data via Service Worker and message passing
- Loading branch information
Showing
9 changed files
with
85 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
const { runtime } = chrome || browser; | ||
|
||
function getVersion() { | ||
return runtime.getManifest().version; | ||
} | ||
|
||
function fetchData(url, info) { | ||
const searchString = new URLSearchParams(Object.entries(info).filter(([, val]) => Boolean(val))); | ||
searchString.append("url", url); | ||
searchString.append("ext", getVersion()); | ||
console.log(searchString.toString()); | ||
return fetch(`https://api.hlidacshopu.cz/v2/detail?${searchString}`).then(resp => { | ||
if (resp.status === 404) { | ||
return resp.json(); | ||
} | ||
if (!resp.ok) { | ||
throw new Error("HTTP error, status = " + resp.status); | ||
} | ||
return resp.json(); | ||
}); | ||
} | ||
|
||
runtime.onMessage.addListener(({ name, options }, sender, sendResponse) => { | ||
if (name === "hs-detail") { | ||
fetchData(options.url, options.info).then(sendResponse); | ||
return true; | ||
} | ||
return false; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export default { | ||
sourceDir: "./extension-dist", | ||
ignoreFiles: ["README.md", "background.js", "**/*.mjs"] | ||
ignoreFiles: ["README.md", "**/*.mjs"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters