Support configure auto index updating

This commit is contained in:
Folyd 2020-10-27 00:06:00 +08:00
parent 55419a9bea
commit 40ff8b6dfd
4 changed files with 31 additions and 0 deletions

View file

@ -268,6 +268,10 @@ omnibox.addPrefixQueryEvent(":", {
omnibox.addNoCacheQueries("/", "!", "@", ":");
if (settings.autoUpdate) {
Omnibox.navigateToUrl("https://rust.extension.sh/update");
}
let fileNewIssue = "title=Have you found a bug? Did you feel something was missing?&body=Whatever it was, we'd love to hear from you.";
chrome.runtime.setUninstallURL(
`https://github.com/huhu/rust-search-extension/issues/new?${encodeURI(fileNewIssue)}`

View file

@ -27,6 +27,7 @@
padding: 0 5px;
}
</style>
<link rel="stylesheet" href="../libs/balloon.min.css">
<link rel="stylesheet" href="index.css">
</head>
<body>
@ -41,6 +42,20 @@
</a>
</div>
</div>
<div style="margin-top: 20px" class="flex-vertical">
<div>
Enable auto update
<span aria-label="Whether auto opens the index update page when the browser launch (default false). At any time, you can use the `:update` command to sync the latest index."
data-balloon-pos="up" data-balloon-length="large" style="vertical-align: middle">
<img style="vertical-align: middle;width: 15px;margin-right: 5px;"
src="../stats/info.svg" alt="info">
</span>
<label class="toggle">
<input type="checkbox" id="auto-update">
<span class="slider"></span>
</label>
</div>
</div>
<div style="margin-top: 20px" class="flex-vertical">
<div>
Enable offline mode

View file

@ -1,6 +1,12 @@
const toast = new Toast(".toast");
document.addEventListener('DOMContentLoaded', function () {
const autoUpdateCheckbox = document.getElementById('auto-update');
autoUpdateCheckbox.checked = settings.autoUpdate;
autoUpdateCheckbox.onchange = function (event) {
settings.autoUpdate = event.target.checked;
};
// Offline mode checkbox
if (!settings.offlineDocPath) {
// If the offline doc path not exists, turn off the offline mode.

View file

@ -4,6 +4,12 @@ const REGEX_DOC_PATH_FILE = /(^file:\/\/.*\/doc\/rust\/html\/)(.*)/i;
const REGEX_DOC_PATH_HTTP = /(^https?:\/\/.*:\d{2,6}\/)(.*)/i;
const settings = {
get autoUpdate() {
return JSON.parse(localStorage.getItem('auto-update')) || false;
},
set autoUpdate(mode) {
localStorage.setItem('auto-update', mode);
},
get isOfflineMode() {
return JSON.parse(localStorage.getItem('offline-mode')) || false;
},