-
Notifications
You must be signed in to change notification settings - Fork 86
/
settings.js
55 lines (46 loc) · 2.08 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var extensionIsDisabled
var appearChance
var flipChance
// Function to load settings from Chrome storage
function loadSettings() {
chrome.storage.local.get({
extensionIsDisabled: false,
appearChance: 1.00,
flipChance: 0.25
}, function (data) {
document.getElementById('disableExtension').checked = !data.extensionIsDisabled;
document.getElementById('appearChance').value = data.appearChance * 100;
document.getElementById('flipChance').value = data.flipChance * 100;
});
}
// Function to save settings to Chrome storage
function saveSettings() {
const data = {
extensionIsDisabled: !document.getElementById('disableExtension').checked,
appearChance: parseInt(document.getElementById('appearChance').value) / 100,
flipChance: parseInt(document.getElementById('flipChance').value) / 100
};
chrome.storage.local.set(data, () => {
if (chrome.runtime.lastError) {
console.error("Error saving settings:", chrome.runtime.lastError);
} else {
console.log("Settings saved successfully.");
}
});
}
function ChangeNameInHeading() {
// Get the extension name
let extensionName = chrome.runtime.getManifest().name;
// Remove "youtube" (case-insensitive) from the extension name and trim
extensionName = extensionName.replace(/youtube/i, '').trim();
// Replace "MrBeastify" in the title with the cleaned extension name
const titleElement = document.getElementById('extension-title');
titleElement.textContent = titleElement.textContent.replace('TITLE', extensionName);
}
// Call loadSettings() when the page loads
document.addEventListener('DOMContentLoaded', loadSettings);
// Add input event listeners to all input fields to trigger autosave
document.getElementById('disableExtension').addEventListener('input', saveSettings);
document.getElementById('appearChance').addEventListener('input', saveSettings);
document.getElementById('flipChance').addEventListener('input', saveSettings);
document.addEventListener('DOMContentLoaded', ChangeNameInHeading);