-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
105 lines (91 loc) · 3.86 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var extensionIsDisabled;
var appearChance;
var flipChance;
var isTropassMode = false; // Initial state of TROPASS MODE
// Function to load settings from Chrome storage
function loadSettings() {
chrome.storage.local.get({
extensionIsDisabled: false,
appearChance: 1.00,
flipChance: 0.25,
isTropassMode: false // Include isTropassMode in storage retrieval
}, function (data) {
extensionIsDisabled = data.extensionIsDisabled;
appearChance = data.appearChance;
flipChance = data.flipChance;
isTropassMode = data.isTropassMode; // Update isTropassMode from storage
document.getElementById('disableExtension').checked = !extensionIsDisabled;
document.getElementById('appearChance').value = appearChance * 100;
document.getElementById('flipChance').value = 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,
isTropassMode: isTropassMode // Ensure isTropassMode is saved
};
chrome.storage.local.set(data, () => {
if (chrome.runtime.lastError) {
console.error("Error saving settings:", chrome.runtime.lastError);
} else {
console.log("Settings saved successfully.");
}
});
}
// Function to toggle TROPASS MODE
function toggleTropassMode() {
isTropassMode = !isTropassMode; // Toggle the mode
chrome.storage.local.set({ isTropassMode }, () => {
if (chrome.runtime.lastError) {
console.error("Error saving TROPASS MODE:", chrome.runtime.lastError);
} else {
console.log("TROPASS MODE toggled successfully:", isTropassMode);
// Apply settings immediately after toggle
applyOverlayToThumbnails();
}
});
}
// Function to apply overlay based on current settings
function applyOverlayToThumbnails() {
// This function should contain your logic to apply overlays
// Based on the current state of isTropassMode
// Ensure to integrate with your existing code
// Example:
if (isTropassMode) {
console.log("Applying TROPASS MODE overlay");
// Apply TROPASS MODE specific overlay
} else {
console.log("Applying normal overlay");
// Apply normal overlay
}
}
// Function to change extension name in heading
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 "Pearify" in the title with the cleaned extension name
const titleElement = document.getElementById('extension-title');
titleElement.textContent = titleElement.textContent.replace('Pearify', extensionName);
}
// Add event listeners after DOM content is loaded
document.addEventListener('DOMContentLoaded', function () {
loadSettings(); // Load settings from storage
changeNameInHeading(); // Change extension name in heading
// Add event listeners for settings inputs
document.getElementById('disableExtension').addEventListener('input', saveSettings);
document.getElementById('appearChance').addEventListener('input', saveSettings);
document.getElementById('flipChance').addEventListener('input', saveSettings);
// Add event listener for help button to toggle TROPASS MODE
document.getElementById('help-button').addEventListener('click', toggleTropassMode);
});
// Initialize the application
function initializeApp() {
// Additional initialization if needed
}
// Start the application
initializeApp();