POF for retrying extension

This commit is contained in:
2024-04-19 22:14:53 -07:00
parent 1b955f06ed
commit b5b6ca363d
11 changed files with 256 additions and 50 deletions

6
popup/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

9
popup/popup.css Normal file
View File

@@ -0,0 +1,9 @@
#saveStatus {
opacity: 0;
transition: opacity 0.5s;
color: green;
}
#saveStatus.show {
opacity: 1;
}

59
popup/popup.html Normal file
View File

@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>not-a-rescheduler popup</title>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="popup.css">
<style>
/* Set a minimum width for the body */
body {
min-width: 300px; /* Adjust the value as desired */
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12">
<h3 style="white-space: nowrap;">not-a-rescheduler<br><span id="version"></span></h3>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-check form-switch" style="text-align: left;">
<input class="form-check-input" type="checkbox" role="switch" id="activate">
<label class="form-check-label" for="activate">Activate the script</label>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group mb-2">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Username">
</div>
<div class="form-group mb-2">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
<button type="button" id="showPassword" class="btn btn-link btn-sm">Show password</button>
</div>
<div class="mb-2">
<button type="button mb-2" class="btn btn-primary" id="saveButton">Save credentials</button>
<span id="saveStatus">Saved!</span>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-2">
<input type="range" id="frequency" name="frequency" min="1" max="10" step="0.5">
<label for="frequency">Frequency of checks<br>(every <span id="frequency_info">1</span> minutes)</label>
</div>
</div>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>

68
popup/popup.js Normal file
View File

@@ -0,0 +1,68 @@
(async function() {
const $version = await new Promise(r => chrome.management.getSelf(self => r(self.version)));
document.getElementById("version").innerText = `v${$version}`;
await chrome.storage.local.get().then(items => {
document.getElementById("activate").checked = items["__activate"] || false;
document.getElementById("username").value = items["__username"] || "";
document.getElementById("password").value = items["__password"] || "";
document.getElementById("frequency").value = items["__frequency"] || 1;
document.getElementById("frequency_info").innerText = items["__frequency"] || 1;
});
chrome.storage.onChanged.addListener((changes, area) => {
if (changes.__frequency)
document.getElementById("frequency_info").innerText = changes.__frequency.newValue;
});
// activate checkbox
document.getElementById("activate").addEventListener("change", async e => {
await chrome.storage.local.set({ "__activate": e.target.checked });
});
// credentials
let usernameField = document.getElementById("username");
let passwordField = document.getElementById("password");
let showPasswordButton = document.getElementById("showPassword");
let saveCredsButton = document.getElementById("saveButton");
let saveStatusElement = document.getElementById("saveStatus");
async function save_credentials() {
await chrome.storage.local.set({
"__username": usernameField.value,
"__password": passwordField.value
});
saveStatusElement.classList.add("show");
setTimeout(() => {
saveStatusElement.classList.remove("show");
}, 2000);
}
usernameField.addEventListener("keypress", async e => {
if (e.key === "Enter") {
await save_credentials();
}
});
passwordField.addEventListener("keypress", async e => {
if (e.key === "Enter") {
await save_credentials();
}
});
saveCredsButton.addEventListener("click", async () => {
await save_credentials();
});
showPasswordButton.addEventListener("mousedown", function() {
passwordField.type = "text";
});
showPasswordButton.addEventListener("mouseup", function() {
passwordField.type = "password";
});
// frequency range slider
document.getElementById("frequency").addEventListener("change", function() {
chrome.storage.local.set({ __frequency: this.value });
});
})();