From 87d6087fa59c98bad9c4d2cc39bfe30966b3d080 Mon Sep 17 00:00:00 2001 From: Index Date: Sat, 10 Feb 2024 17:28:27 -0600 Subject: [PATCH] Improved Debug Page --- js/debug.js | 179 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 146 insertions(+), 33 deletions(-) diff --git a/js/debug.js b/js/debug.js index 34bc834..50de95f 100644 --- a/js/debug.js +++ b/js/debug.js @@ -1,53 +1,166 @@ -// DEBUG MENU FOR CLEARING PINNED GAMES AND BEST FRIENDS DATA +// DEBUG PAGE FOR BETA TESTING +const Version = chrome.runtime.getManifest().version document.querySelector('#main-content .container').innerHTML = ` - + +
+
+
+
+

Version: v${Version}

+

Data Size: Loading byte(s)

+ + Open GitHub + +
+
+
+ Created by Index +

+ Beta Testers: + +
+
+ +

Set a value of the extension's local settings data

+
+ + + +
- + +

Quickly clear specific parts of the extension's local data

+
+ + + + +
-
- - -
- - - + +

This will clear all local data associated with the extension

+ +
` -const ClearPins = document.getElementById('clear-pins') -const ClearBF = document.getElementById('clear-bf') -const EditSettingName = document.getElementById('edit-setting-name') -const EditSettingValue = document.getElementById('edit-setting-value') -const EditSettingBtn = document.getElementById('edit-setting') +const CheckForUpdatesButton = document.getElementById('check-for-updates') +function CheckForUpdates() { + CheckForUpdatesButton.removeEventListener('click', CheckForUpdates) + CheckForUpdatesButton.disabled = true + fetch('https://polyplus.vercel.app/data/version.json') + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + /* + const Result = document.createElement('span') + if (data.version === Version || Math.floor((data.version - Version) * 10) === 0) { + Result.innerText = 'No updates available' + } else { + Result.innerText = Math.floor((data.version - Version) * 10) + ' updates available' + } + CheckForUpdatesButton.parentElement.insertBefore(Result, CheckForUpdatesButton) + CheckForUpdatesButton.remove() + */ + if (data.version === Version || Math.floor((data.version - Version) * 10) === 0) { + CheckForUpdatesButton.innerText = 'No updates available' + } else { + CheckForUpdatesButton.innerText = Math.floor((data.version - Version) * 10) + ' updates available' + } + }) + .catch(error => {console.log(error)}); +} +CheckForUpdatesButton.addEventListener('click', CheckForUpdates); -ClearPins.addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() { - alert('Successfully cleared Pinned Games.') - }); -}); +document.getElementById('edit-setting').addEventListener('click', function(){ + const EditSettingName = document.getElementById('edit-setting-name') + const EditSettingValue = document.getElementById('edit-setting-value') -ClearBF.addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() { - alert('Successfully cleared Best Friends.') - }); -}); - -EditSettingBtn.addEventListener('click', function(){ chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { result = result.PolyPlus_Settings let NewValue = EditSettingValue.value - if (NewValue === "true") {NewValue = true} - if (NewValue === "false") {NewValue = false} - if (parseInt(NewValue)) {NewValue = parseInt(NewValue)} + switch (NewValue) { + case 'true': + NewValue = true + break + case 'false': + NewValue = false + break + case 'null': + NewValue = null + break + case 'undefined': + NewValue = undefined + break + case parseInt(NewValue): + NewValue = parseInt(NewValue) + break + } result[EditSettingName.value] = NewValue chrome.storage.sync.set({ 'PolyPlus_Settings': result }, function() { alert('Successfully set: "' + EditSettingName.value + '" to ' + NewValue) }); - - alert('Successfully cleared Best Friends.') }); +}); + +document.getElementById('reset-settings').addEventListener('click', async function(){ + let Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js')) + Utilities = Utilities.default + chrome.storage.sync.set({ 'PolyPlus_Settings': Utilities.DefaultSettings }, function() { + alert('Successfully reset settings to their defaults!') + }); +}); + +document.getElementById('clear-pinnedgames').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() { + alert('Successfully cleared Pinned Games!') + }); +}); + +document.getElementById('clear-bestfriends').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() { + alert('Successfully cleared Best Friends!') + }); +}); + +document.getElementById('clear-itemwishlist').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_ItemWishlist': [] }, function() { + alert('Successfully cleared Item Wishlist!') + }); +}); + +document.getElementById('delete-all-data').addEventListener('click', function(){ + if (confirm("Are you sure you'd like to delete all local data associated with the extension?") === false) { return } + chrome.storage.sync.clear(function() { + alert('Successfully deleted all local data associated with the extension!') + }); +}); + +chrome.storage.sync.getBytesInUse(["PolyPlus_Settings", "PolyPlus_PinnedGames", "PolyPlus_BestFriends", "PolyPlus_ItemWishlist"], function(bytes){ + document.getElementById('data-size').innerText = bytes }); \ No newline at end of file