lotsa stuff
This commit is contained in:
@ -8,21 +8,25 @@
|
||||
|
||||
<body>
|
||||
<form>
|
||||
<fieldset>
|
||||
<label for="bcnum">The number of your BahnCard 100</label>
|
||||
<input name="bcnum" id="bcnum" type="text" pattern="70814[0-9]{11}" />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="birthday">Your date of birth</label>
|
||||
<input name="birthday" id="birthday" type="date" />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="autocontinue">Automatically continue to the "I was delayed by more than 60 minutes" screen</label>
|
||||
<input name="autocontinue" id="autocontinue" type="checkbox" />
|
||||
</fieldset>
|
||||
<button type="submit">Save</button>
|
||||
<label class="item">
|
||||
<span class="fh">Your BahnCard 100 number</span><br />
|
||||
<span class="sh">The number on the front of your card starting with <span class="ms">7081</span>.</span><br>
|
||||
<input name="bcnum" id="bcnum" type="text" pattern="70814[0-9]{11}" required
|
||||
title="Your BahnCard number is 16 digits long and starts with 7081." />
|
||||
</label>
|
||||
<label class="item">
|
||||
<span class="fh">Your date of birth</span><br>
|
||||
<input name="birthday" id="birthday" type="date" required />
|
||||
</label>
|
||||
<label>
|
||||
<span class="fh">Skip questionnaire</span><br>
|
||||
<span class="sh">Automatically answer "I was delayed, by more than 60 minutes."</span><br>
|
||||
<input name="autocontinue" id="autocontinue" type="checkbox" required />
|
||||
</label>
|
||||
<div class="item"><button type="submit">Save</button><span id="success"></span></div>
|
||||
<p id="errors"></p>
|
||||
</form>
|
||||
<script src="script.js"></script>
|
||||
<script type="module" src="script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,16 +1,63 @@
|
||||
async function saveOptions(e) {
|
||||
console.log("Saving options.");
|
||||
e.preventDefault();
|
||||
let bcNum = document.querySelector("#bcnum").value;
|
||||
let bDay = document.querySelector('#birthday').value;
|
||||
let autoContinue = document.querySelector('#autocontinue').checked;
|
||||
function luhnValidate(cardNumber) {
|
||||
cardNumber = String(cardNumber).replace(/[\s]/g, "");
|
||||
let odd = false;
|
||||
let total = 0;
|
||||
let position, doubledPos;
|
||||
|
||||
if (!/^[0-9]+$/.test(cardNumber)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = cardNumber.length; i > 0; i--) {
|
||||
position = parseInt(cardNumber[i - 1]);
|
||||
if (!odd) {
|
||||
total += position;
|
||||
} else {
|
||||
doubledPos = position * 2;
|
||||
|
||||
if (doubledPos > 9) {
|
||||
doubledPos -= 9;
|
||||
}
|
||||
total += doubledPos;
|
||||
}
|
||||
odd = !odd;
|
||||
}
|
||||
|
||||
return (total !== 0 && (total % 10) === 0);
|
||||
}
|
||||
|
||||
function putError(s){
|
||||
document.querySelector('#errors').textContent += s;
|
||||
}
|
||||
function clearError(){
|
||||
document.querySelector('#errors').textContent = "";
|
||||
}
|
||||
|
||||
async function saveOptions(ev) {
|
||||
clearError();
|
||||
ev.preventDefault();
|
||||
let bcNum = this.querySelector("#bcnum").value;
|
||||
if (!bcNum.length == 16 || !bcNum.startsWith("70814") || !luhnValidate(bcNum)) {
|
||||
putError("Your BahnCard number is not valid. Please make sure you haven't made any typos.");
|
||||
return;
|
||||
}
|
||||
let bDay = this.querySelector('#birthday').value;
|
||||
if (bDay == ""){
|
||||
putError("Please enter a birthday.");
|
||||
return;
|
||||
}
|
||||
let autoContinue = this.querySelector('#autocontinue').checked;
|
||||
let options = {
|
||||
bcnum: bcNum,
|
||||
bday: bDay,
|
||||
autocontinue: autoContinue
|
||||
};
|
||||
await browser.storage.sync.set(options);
|
||||
console.log("Saved!");
|
||||
browser.storage.sync.set(options).then(() => {
|
||||
document.querySelector('#success').textContent = "✔";
|
||||
setTimeout(() => {
|
||||
document.querySelector('#success').textContent = '';
|
||||
}, 5000);
|
||||
})
|
||||
}
|
||||
|
||||
async function restoreOptions() {
|
||||
@ -18,7 +65,7 @@ async function restoreOptions() {
|
||||
// let res = await browser.storage.managed.get('colour');
|
||||
// document.querySelector("#managed-colour").innerText = res.colour;
|
||||
|
||||
settings = await browser.storage.sync.get();
|
||||
let settings = await browser.storage.sync.get();
|
||||
console.log(settings);
|
||||
document.querySelector("#bcnum").value = settings.bcnum || "";
|
||||
document.querySelector("#birthday").value = settings.bday || "";
|
||||
|
@ -1,3 +1,52 @@
|
||||
h1 {
|
||||
.fh {
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.sh {
|
||||
font-size: 1em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
label.item {
|
||||
display: block;
|
||||
}
|
||||
|
||||
input {
|
||||
margin: 8px 0px;
|
||||
}
|
||||
|
||||
.ms {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#errors {
|
||||
color: red;
|
||||
font-style: italic;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input:invalid {
|
||||
background-color: rgba(212, 59, 59, 70%);
|
||||
}
|
||||
|
||||
input:focus {
|
||||
background-color: revert;
|
||||
}
|
||||
|
||||
#success {
|
||||
color: lightgreen;
|
||||
font-size: 1.5em;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user