Skip to content

Commit

Permalink
Updated options page
Browse files Browse the repository at this point in the history
  • Loading branch information
bottiger committed Jun 25, 2024
1 parent 11ef786 commit a3c959e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Trolling with love",
"version": "1.0.6",
"version": "1.0.7",
"description": "Replaces certain images during your web browsing",

"icons": {
Expand Down
11 changes: 7 additions & 4 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
</head>
<body>
<form>
<p>
<label for="name">Your name:</label>
<input type="text" id="name" />
</p>

<p>
<label for="category">Category:</label>
<select id="category">
Expand All @@ -19,11 +24,9 @@
<p>
<label for="increase">Increase over time:</label>
<input type="checkbox" id="increase" />
</p>

<p>
<label for="name">Name:</label>
<input type="text" id="name" />
<i id="increase_desc">Test text</i>
</p>
</p>

<p>
Expand Down
23 changes: 21 additions & 2 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,31 @@ function saveOptions(e) {

// Set values from storage
categorySelect.value = result.category || categoriesNames[0].value;
//categorySelect.value = result.category || Settings.CategoryEnum.Cage;

//document.querySelector("#category").value = result.category || Categories.Cage
document.querySelector("#percentage").value = result.percentage || 1;
document.querySelector("#increase").checked = result.increase ? true : false;
document.querySelector("#name").value = result.name || "A Friend";

const increaseDescElement = document.getElementById('increase_desc');

// Check if result.increase is a valid date and not null
if (result.increase && !isNaN(Date.parse(result.increase))) {
const increaseDate = new Date(result.increase);
const currentDate = new Date();

// Calculate the number of days (n) between the increase date and the current date
const timeDiff = Math.abs(currentDate - increaseDate);
const n = Math.ceil(timeDiff / (1000 * 3600 * 24)); // Convert milliseconds to days

// Placeholder values for x and p, these should be calculated based on your logic
const x = 1; // Function to calculate the daily increase percentage
const p = result.percentage * n; // Function to calculate the current probability

// Update the <i> element with the description
increaseDescElement.innerHTML = `The probability has been increasing by ${x}% every day for ${n} days and is now ${p}%`;
} else {
increaseDescElement.innerHTML = '';
}
}

function onError(error) {
Expand Down

0 comments on commit a3c959e

Please sign in to comment.