From 4577213ee948903a6417684625d29169a31cf5c7 Mon Sep 17 00:00:00 2001 From: Index Date: Sat, 1 Jun 2024 18:54:10 -0500 Subject: [PATCH] bug fixes and fix fresh installs --- js/background.js | 107 ++++++++++++++++++++++++++++++++ js/{debug.js => extra-pages.js} | 102 +++++++++++++++++++++++++++--- js/settings.js | 2 +- manifest.json | 2 +- 4 files changed, 204 insertions(+), 9 deletions(-) rename js/{debug.js => extra-pages.js} (67%) diff --git a/js/background.js b/js/background.js index 1df4530..a8a4af4 100755 --- a/js/background.js +++ b/js/background.js @@ -1,6 +1,94 @@ const Manifest = chrome.runtime.getManifest(); const SettingsURL = chrome.runtime.getURL('settings.html'); +const DefaultSettings = { + PinnedGamesOn: true, + ForumMentsOn: true, + BestFriendsOn: false, + ImprovedFrListsOn: false, + IRLPriceWithCurrency: { + Enabled: true, + Currency: 0, + Package: 0 + }, + IRLPriceWithCurrencyOn: true, + IRLPriceWithCurrencyCurrency: 0, + IRLPriceWithCurrencyPackage: 0, + HideNotifBadgesOn: false, + StoreOwnTagOn: true, + ThemeCreatorOn: false, + ThemeCreator: { + Enabled: false, + BGColor: null, + BGImage: null, + BGImageSize: 'fit', + PrimaryTextColor: null, + SecondaryTextColor: null, + LinkTextColor: null, + WebsiteLogo: null + }, + ModifyNavOn: false, + ModifyNav: [ + { + Label: 'Places', + Link: 'https://polytoria.com/places' + }, + { + Label: 'Store', + Link: 'https://polytoria.com/store' + }, + { + Label: 'Guilds', + Link: 'https://polytoria.com/guilds' + }, + { + Label: 'People', + Link: 'https://polytoria.com/users' + }, + { + Label: 'Forum', + Link: 'https://polytoria.com/forum' + } + ], + MoreSearchFiltersOn: true, + ApplyMembershipTheme: { + Enabled: false, + Theme: 0 + }, + ApplyMembershipThemeOn: false, + ApplyMembershipThemeTheme: 0, + MultiCancelOutTradesOn: true, + ItemWishlistOn: true, + HideUpgradeBtnOn: false, + TryOnItemsOn: true, + OutfitCostOn: true, + ShowPlaceRevenueOn: true, + ReplaceItemSalesOn: false, + HoardersListOn: true, + HoardersList: { + Enabled: true, + AvatarsEnabled: false, + MinCopies: 2 + }, + LibraryDownloadsOn: true, + EventItemsCatOn: true, + HomeFriendCountOn: true, + HideUserAds: { + Enabled: false, + Banners: true, + Rectangles: true + } +} + +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + const MergedSettings = MergeObjects((result.PolyPlus_Settings || DefaultSettings), DefaultSettings) + chrome.storage.sync.set({'PolyPlus_Settings': MergedSettings}, function(){ + console.log('Successfully merged settings') + }) + }) +}); + // WHEN CLICKING ON EXTENSION ICON OPEN THE SETTINGS PAGE chrome.action.onClicked.addListener((tab) => { chrome.tabs.create({active: true, url: SettingsURL}); @@ -189,3 +277,22 @@ function CopyAvatarHash(hash) { alert('Failure to copy avatar hash.'); }); } + +// MergeObjects function was written by ChatGPT cause I was lazy and it was awhile ago +function MergeObjects(obj1, obj2) { + var mergedObj = {}; + + // Copy the values from obj1 to the mergedObj + for (var key in obj1) { + mergedObj[key] = obj1[key]; + } + + // Merge the values from obj2 into the mergedObj, favoring obj2 for non-existing keys in obj1 + for (var key in obj2) { + if (!obj1.hasOwnProperty(key)) { + mergedObj[key] = obj2[key]; + } + } + + return mergedObj; +} \ No newline at end of file diff --git a/js/debug.js b/js/extra-pages.js similarity index 67% rename from js/debug.js rename to js/extra-pages.js index 4bc6a0b..1add1ab 100644 --- a/js/debug.js +++ b/js/extra-pages.js @@ -1,12 +1,12 @@ /* - Debug page for Development - Accessable at /my/settings/polyplus#dev + Developer & Debug Page + Accessable at /my/settings/polyplus#dev and /my/settings/polyplus#debug */ -if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash === '#dev') { - document.title = 'Poly+ Debug - Polytoria'; - const Version = chrome.runtime.getManifest().version; +document.title = 'Poly+ Debug - Polytoria'; +const Version = chrome.runtime.getManifest().version; +if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash === '#dev') { document.addEventListener('DOMContentLoaded', function () { document.querySelector('#main-content .container').innerHTML = `
-

Poly+ Debug

+

Poly+ Developer

This page is used by developers for debugging most data related things. It is unrecommended you modify any data on this page, but if you ever want to go ahead.

@@ -235,7 +235,95 @@ if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.has }); chrome.storage.sync.getBytesInUse(['PolyPlus_Settings', 'PolyPlus_PinnedGames', 'PolyPlus_BestFriends', 'PolyPlus_ItemWishlist'], function (bytes) { + console.log(bytes) document.getElementById('data-size').innerText = bytes.toLocaleString(); }); }); -} +} else if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash === '#debug') { + document.addEventListener('DOMContentLoaded', function () { + chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames', 'PolyPlus_BestFriends', 'PolyPlus_ItemWishlist'], function(result) { + document.querySelector('#main-content .container').innerHTML = ` + +
+

Poly+ Debug

+

This page is used by developers for debugging most data related things. It is unrecommended you modify any data on this page, but if you ever want to go ahead.

+
+
+
+
+
+

Settings

+
+ ${JSON.stringify((result.PolyPlus_Settings || {}), null, 2) + .replaceAll('\n','
') + .replaceAll(' ', ' ') + .replaceAll('\t', '    ')} + +
+
+
+
+
+

Version: v${Version}

+

Data Size: Loading byte(s)

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

Pinned Games (${(result.PolyPlus_PinnedGames || []).length})

+
+ ${JSON.stringify((result.PolyPlus_PinnedGames || []), null, 2) + .replaceAll('\n','
') + .replaceAll(' ', ' ') + .replaceAll('\t', '    ')} + +
+
+
+
+
+

Best Friends (${(result.PolyPlus_BestFriends || []).length})

+
+ ${JSON.stringify((result.PolyPlus_BestFriends || []), null, 2) + .replaceAll('\n','
') + .replaceAll(' ', ' ') + .replaceAll('\t', '    ')} + +
+
+
+
+
+

Item Wishlist (${(result.PolyPlus_ItemWishlist || []).length})

+
+ ${JSON.stringify((result.PolyPlus_ItemWishlist || []), null, 2) + .replaceAll('\n','
') + .replaceAll(' ', ' ') + .replaceAll('\t', '    ')} + +
+
+
+
+
+ `; + }) + }); +} \ No newline at end of file diff --git a/js/settings.js b/js/settings.js index 10b2895..5356099 100755 --- a/js/settings.js +++ b/js/settings.js @@ -1,5 +1,5 @@ const SettingsURL = chrome.runtime.getURL('settings.html'); -const InExtensionSettings = window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash !== '#dev'; +const InExtensionSettings = window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash !== '#dev' && window.location.hash !== '#debug'; if (InExtensionSettings === true) { window.location.href = SettingsURL + window.location.hash; } diff --git a/manifest.json b/manifest.json index 432c1b7..3d9b622 100755 --- a/manifest.json +++ b/manifest.json @@ -17,7 +17,7 @@ { "matches": ["https://polytoria.com/my/settings/*"], - "js": ["/js/settings.js", "/js/debug.js"], + "js": ["/js/settings.js", "/js/extra-pages.js"], "run_at": "document_start" },