diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6cb640b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 + +[*.json] +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/background.js b/background.js index 2dd9b1f..332163d 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,6 @@ -const JD2_API_URL = 'http://localhost:9666/flashgot?'; -const JD2_REFERER = 'localhost'; -const JD2_MATCH_URL = "*://*/flashgot?*"; +let JD2_API_URL = window.localStorage.getItem("jd2_api_url") ?? 'http://localhost:9666/flashgot?'; +let JD2_REFERER = window.localStorage.getItem("jd2_referer") ?? 'localhost'; +let JD2_MATCH_URL = window.localStorage.getItem("jd2_match_url") ?? "*://*/flashgot?*"; // menu const mnDlId = "JD2Dl"; @@ -132,10 +132,16 @@ browser.menus.onShown.addListener(info => { // Handle message from 'popup' function handleMessageFromPopup(request, sender, sendResponse) { + if (request.message == "refresh") { + JD2_API_URL = window.localStorage.getItem("jd2_api_url"); + JD2_REFERER = window.localStorage.getItem("jd2_referer"); + JD2_MATCH_URL = window.localStorage.getItem("jd2_match_url"); + } else { let forJD2link = urlConstruct(request.jd2url, request.jd2action); makeRequest(forJD2link); return Promise.resolve({response: "done"}); } +} browser.runtime.onMessage.addListener(handleMessageFromPopup); @@ -168,4 +174,4 @@ browser.webRequest.onBeforeSendHeaders.addListener( rewriteHeader, { urls: [JD2_MATCH_URL] }, ["blocking", "requestHeaders"] -); +); \ No newline at end of file diff --git a/manifest.json b/manifest.json index d2b0602..5006562 100644 --- a/manifest.json +++ b/manifest.json @@ -45,6 +45,10 @@ "webRequest", "webRequestBlocking", "menus" - ] + ], + "options_ui": { + "page": "options.html", + "browser_style": true + } } \ No newline at end of file diff --git a/options.html b/options.html new file mode 100644 index 0000000..e10dc61 --- /dev/null +++ b/options.html @@ -0,0 +1,21 @@ + + + + + + + + + + + +
+ + +
+ + +
+ + + \ No newline at end of file diff --git a/options.js b/options.js new file mode 100644 index 0000000..14e7c57 --- /dev/null +++ b/options.js @@ -0,0 +1,15 @@ +document.addEventListener("DOMContentLoaded", () => { + document.getElementById("save").onclick = save; + + document.getElementById("jd2_api_url").value = window.localStorage.getItem("jd2_api_url") ?? 'http://localhost:9666/flashgot?'; + document.getElementById("jd2_referer").value = window.localStorage.getItem("jd2_referer") ?? 'localhost'; + document.getElementById("jd2_match_url").value = window.localStorage.getItem("jd2_match_url") ?? "*://*/flashgot?*"; +}) + +function save() { + window.localStorage.setItem("jd2_api_url", document.getElementById("jd2_api_url").value); + window.localStorage.setItem("jd2_referer", document.getElementById("jd2_referer").value); + window.localStorage.setItem("jd2_match_url", document.getElementById("jd2_match_url").value); + + browser.runtime.sendMessage({message: "refresh"}) +} \ No newline at end of file