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 = `
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.
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.
+