Add Content Security Policy url to load latest crates index from the server

This commit is contained in:
Folyd 2019-12-23 00:13:08 +08:00
parent a8762d48b4
commit 5a9b842cf4
2 changed files with 4 additions and 5 deletions

View file

@ -17,6 +17,7 @@
"default_popup": "popup.html",
"default_title": "A handy browser extension to search crates and official docs in the address bar (omnibox)"
},
"content_security_policy": "script-src-elem 'self' https://folyd.github.io/rust-search-extension/crates/crates-index.js; script-src 'self'; object-src 'self'",
"omnibox": {
"keyword": "rs"
},

View file

@ -1,10 +1,8 @@
const omnibox = new Omnibox();
const CRATES_INDEX_ENDPOINT = "chrome-extension://hlpbdelgppbbhoilofpcfjebkbdgkgma";
const CRATES_INDEX_BASE_URL = "https://folyd.github.io/rust-search-extension/crates";
async function checkLatestCratesIndex() {
let response = await fetch(`${CRATES_INDEX_ENDPOINT}/crate-index-version.json`, {
mode: "no-cors",
});
let response = await fetch(`${CRATES_INDEX_BASE_URL}/version.json`);
console.log(response);
let {version} = await response.json();
if (parseInt(localStorage.getItem("crate-index-version") || 1) < version) {
@ -18,7 +16,7 @@ async function checkLatestCratesIndex() {
async function loadLatestCratesIndex(version) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = `${CRATES_INDEX_ENDPOINT}/crates-index.js?${version}`;
script.src = `${CRATES_INDEX_BASE_URL}/crates-index.js?${version}`;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);