-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from elecordapp/options-logic
Add options menu logic and styling
- Loading branch information
Showing
4 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
{ | ||
"name": "Elecord Extension", | ||
"version": "1.0", | ||
"version": "1.0.1", | ||
"manifest_version": 2, | ||
"description": "Collection of handy tools and tweaks for gamers across the web", | ||
"homepage_url": "https://github.com/elecordapp/elecord-extension", | ||
"permissions": [ | ||
"contextMenus", | ||
"tabs" | ||
"tabs", | ||
"storage" | ||
], | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
"scripts": ["background.js"] | ||
}, | ||
"icons": { | ||
"128": "icon.png" | ||
}, | ||
"options_ui": { | ||
"page": "options.html", | ||
"open_in_tab": true | ||
"open_in_tab": false, | ||
"browser_action": { | ||
"default_title": "Elecord Extension", | ||
"default_icon": "icon.png" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Function to save the options to storage | ||
function saveOptions() { | ||
// Get the values of the toggle boxes | ||
var optionGGDeals = document.getElementById("option-ggdeals").checked; | ||
var optionSteam = document.getElementById("option-steam").checked; | ||
|
||
// Save the options to storage | ||
chrome.storage.sync.set({ | ||
optionGGDeals: optionGGDeals, | ||
optionSteam: optionSteam | ||
}, function () { | ||
// Update the context menus based on the options | ||
updateContextMenus({ | ||
optionGGDeals: optionGGDeals, | ||
optionSteam: optionSteam | ||
}); | ||
}); | ||
} | ||
|
||
// Function to restore the options from storage | ||
function restoreOptions() { | ||
// Set the values of the toggle boxes based on the options, applies defaults if not set | ||
chrome.storage.sync.get(["optionGGDeals", "optionSteam"], function (options) { | ||
document.getElementById("option-ggdeals").checked = options.optionGGDeals || true; | ||
document.getElementById("option-steam").checked = options.optionSteam || true; | ||
}); | ||
} | ||
|
||
// Function to update the context menus based on the options | ||
function updateContextMenus(options) { | ||
// Hide or show "menu-ggdeals" context menu | ||
chrome.contextMenus.update("menu-ggdeals", { | ||
visible: options.optionGGDeals | ||
}); | ||
|
||
// Hide or show "menu-steam" context menu | ||
chrome.contextMenus.update("menu-steam", { | ||
visible: options.optionSteam | ||
}); | ||
|
||
// Hide or show "menu-elecord" parent context menu | ||
if (!options.optionGGDeals && !options.optionSteam) { | ||
chrome.contextMenus.update("menu-elecord", { | ||
visible: false | ||
}); | ||
} else { | ||
chrome.contextMenus.update("menu-elecord", { | ||
visible: true | ||
}); | ||
} | ||
} | ||
|
||
// Add event listener for when the options are changed | ||
document.getElementById("option-ggdeals").addEventListener("change", saveOptions); | ||
document.getElementById("option-steam").addEventListener("change", saveOptions); | ||
|
||
// Restore the options when the page is loaded | ||
document.addEventListener("DOMContentLoaded", restoreOptions); |