Added options menu to extension page
This commit is contained in:
parent
dffc4b3c9b
commit
a8fcb3ad6d
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
@ -1,6 +1,6 @@
|
|||||||
const JD2_API_URL = 'http://localhost:9666/flashgot?';
|
let JD2_API_URL = window.localStorage.getItem("jd2_api_url") ?? 'http://localhost:9666/flashgot?';
|
||||||
const JD2_REFERER = 'localhost';
|
let JD2_REFERER = window.localStorage.getItem("jd2_referer") ?? 'localhost';
|
||||||
const JD2_MATCH_URL = "*://*/flashgot?*";
|
let JD2_MATCH_URL = window.localStorage.getItem("jd2_match_url") ?? "*://*/flashgot?*";
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
const mnDlId = "JD2Dl";
|
const mnDlId = "JD2Dl";
|
||||||
@ -132,10 +132,16 @@ browser.menus.onShown.addListener(info => {
|
|||||||
|
|
||||||
// Handle message from 'popup'
|
// Handle message from 'popup'
|
||||||
function handleMessageFromPopup(request, sender, sendResponse) {
|
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);
|
let forJD2link = urlConstruct(request.jd2url, request.jd2action);
|
||||||
makeRequest(forJD2link);
|
makeRequest(forJD2link);
|
||||||
return Promise.resolve({response: "done"});
|
return Promise.resolve({response: "done"});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
browser.runtime.onMessage.addListener(handleMessageFromPopup);
|
browser.runtime.onMessage.addListener(handleMessageFromPopup);
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,10 @@
|
|||||||
"webRequest",
|
"webRequest",
|
||||||
"webRequestBlocking",
|
"webRequestBlocking",
|
||||||
"menus"
|
"menus"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"options_ui": {
|
||||||
|
"page": "options.html",
|
||||||
|
"browser_style": true
|
||||||
|
}
|
||||||
}
|
}
|
21
options.html
Normal file
21
options.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<script src="options.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<label for="jd2_api_url">JD2 API URL: </label>
|
||||||
|
<input type="text" id="jd2_api_url" name="jd2_api_url" />
|
||||||
|
<br>
|
||||||
|
<label for="jd2_referer">JD2 Referer: </label>
|
||||||
|
<input type="text" id="jd2_referer" name="jd2_referer" />
|
||||||
|
<br>
|
||||||
|
<label for="jd2_match_url">JD2 API URL: </label>
|
||||||
|
<input type="text" id="jd2_match_url" name="jd2_match_url" />
|
||||||
|
<br>
|
||||||
|
<button id="save">Save</button>
|
||||||
|
</body>
|
||||||
|
</html>
|
15
options.js
Normal file
15
options.js
Normal file
@ -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"})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user