From 46efc889e711b80e2f53eee55080ba160e85ea40 Mon Sep 17 00:00:00 2001 From: Index Date: Sun, 11 Feb 2024 11:30:59 -0600 Subject: [PATCH] Items in Wishlist get Removed upon Purchase - Items that are in your "Item Wishlist" will now be automatically removed when purchased. You can now also no longer add items to your "Item Wishlist" if you already own the item. - Fixed issue with forgetting to remove simplified-profile.js from manifest.json after deleting the file - Added all experimental settings to the settings page ("Game Profiles", "Inline Editing", "Forum Unix Timestamps") - Removed commented out settings on the settings page - Removed the "Handle" part of all function names (eg. "HandlePinnedGames()" -> "PinnedGames()") - Moved profile/profile.js to account/profile.js - You can now quickly copy a message to share your or somebody else's 3D avatar URL on profile pages. --- js/account/inbox.js | 4 +- js/{profile => account}/profile.js | 35 ++++++-- js/forum/forum-view.js | 8 +- js/places/place-view.js | 17 ++-- js/places/place-view2.js | 12 +-- js/store/item-view.js | 23 +++++- manifest.json | 8 +- settings.html | 126 ++++++++++++++++------------- 8 files changed, 136 insertions(+), 97 deletions(-) rename js/{profile => account}/profile.js (89%) diff --git a/js/account/inbox.js b/js/account/inbox.js index f5324d4..53a4c23 100644 --- a/js/account/inbox.js +++ b/js/account/inbox.js @@ -1,6 +1,6 @@ -HandleExpandMessages() +ExpandMessages() -function HandleExpandMessages() { +function ExpandMessages() { const Messages = document.getElementById('messages') for (let message of Messages.children) { diff --git a/js/profile/profile.js b/js/account/profile.js similarity index 89% rename from js/profile/profile.js rename to js/account/profile.js index 058f2e6..a8894a6 100755 --- a/js/profile/profile.js +++ b/js/account/profile.js @@ -15,11 +15,11 @@ if (UserID && !isNaN(UserID)) { } if (Settings.IRLPriceWithCurrencyOn === true) { - HandleIRLPrice() + IRLPrice() } if (Settings.BestFriendsOn === true) { - HandleBestFriends() + BestFriends() } if (Settings.OutfitCostOn === true) { @@ -30,23 +30,23 @@ if (UserID && !isNaN(UserID)) { AvatarRow.parentElement.style.marginTop = '10px' CalculateButton.addEventListener('click', function(){ - HandleOufitCost() + OutfitCost() }); } }); const AvatarIFrame = document.querySelector('[src^="/ptstatic"]') const DropdownMenu = document.getElementsByClassName('dropdown-menu dropdown-menu-right')[0] + const CopyItem = document.createElement('a') CopyItem.classList = 'dropdown-item text-primary' - CopyItem.classList.remove('text-danger') - CopyItem.classList.add('text-primary') CopyItem.href = '#' CopyItem.innerHTML = ` Copy 3D Avatar URL ` DropdownMenu.appendChild(CopyItem) + CopyItem.addEventListener('click', function(){ navigator.clipboard.writeText(AvatarIFrame.src) .then(() => { @@ -56,6 +56,25 @@ if (UserID && !isNaN(UserID)) { alert('Failure to copy 3D avatar URL.') }); }); + + const ShareItem = document.createElement('a') + ShareItem.classList = 'dropdown-item text-warning' + ShareItem.href = '#' + ShareItem.innerHTML = ` + + Share your 3D Avatar URL! + ` + DropdownMenu.appendChild(ShareItem) + + ShareItem.addEventListener('click', function(){ + navigator.clipboard.writeText("Hey! Look at my Polytoria avatar in 3D [here](" + AvatarIFrame.src + ")!") + .then(() => { + alert('Successfully copied sharable 3D avatar URL!') + }) + .catch(() => { + alert('Failure to copy sharable 3D avatar URL.') + }); + }); } else if (UserID && UserID[0] === "@") { const Username = window.location.pathname.split('/')[2].substring(1) @@ -80,7 +99,7 @@ if (UserID && !isNaN(UserID)) { }); } -function HandleIRLPrice() { +function IRLPrice() { const NetWorthElement = document.getElementsByClassName('float-end text-success')[0]; const NetWorth = parseInt(NetWorthElement.innerText.replace(/,/g, '')); let IRL; @@ -118,7 +137,7 @@ function HandleIRLPrice() { NetWorthElement.innerText = NetWorthElement.innerText + " ($" + IRL + " " + DISPLAY + ")" } -function HandleBestFriends() { +function BestFriends() { chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result){ BestFriends = result.PolyPlus_BestFriends || []; @@ -200,7 +219,7 @@ function HandleBestFriends() { } } -async function HandleOufitCost() { +async function OutfitCost() { const AvatarCost = { Total: 0, Limiteds: 0, diff --git a/js/forum/forum-view.js b/js/forum/forum-view.js index f1abeee..8a523b3 100644 --- a/js/forum/forum-view.js +++ b/js/forum/forum-view.js @@ -8,15 +8,15 @@ chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { } if (Settings.ForumMentsOn === true) { - HandleForumMentions() + ForumMentions() } if (Settings.ForumUnixStampsOn === true) { - HandleUnixTimestamps() + ForumUnixTimestamps() } }); -function HandleForumMentions() { +function ForumMentions() { const Regex = /@([\w.]+)/g for (let text of ForumText) { @@ -30,7 +30,7 @@ function HandleForumMentions() { } } -function HandleUnixTimestamps() { +function ForumUnixTimestamps() { const Regex = /<t:[A-Za-z0-9]+>/i for (let text of ForumText) { diff --git a/js/places/place-view.js b/js/places/place-view.js index 96359f5..7508e68 100755 --- a/js/places/place-view.js +++ b/js/places/place-view.js @@ -29,21 +29,20 @@ let PinnedGames; Settings = result.PolyPlus_Settings; if (Settings.PinnedGamesOn === true) { - HandlePinnedGames() + PinnedGames() } - // Disabled settings - if (Settings.InlineEditingOn === true || 1 === 2) { - HandleInlineEditing() + if (Settings.InlineEditingOn === true) { + InlineEditing() } - if (Settings.GameProfilesOn === true && 1 === 2) { - HandleGameProfiles() + if (Settings.GameProfilesOn === true) { + GameProfiles() } }); })() -async function HandlePinnedGames() { +async function PinnedGames() { chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result){ PinnedGames = result.PolyPlus_PinnedGames || []; const PinBtn = document.createElement('button'); @@ -107,7 +106,7 @@ async function HandlePinnedGames() { }); } -async function HandleInlineEditing() { +async function InlineEditing() { // Fix description editing // Make it possible to edit description even if the game doesn't initially have a description // Add the ability to edit the game's genre @@ -202,7 +201,7 @@ async function HandleInlineEditing() { const Data = JSON.parse('{"gameTitle": "Hyper[Fart]","bg": "#000","accent": "#007bff","secondary": "#","cardBg": "#313131","font": "","text": "#fff"}') -async function HandleGameProfiles(Data) { +async function GameProfiles(Data) { document.querySelector('h1.my-0') .setAttribute('game-key', 'true'); document.querySelector('div[style="min-height: 60vh;"]') diff --git a/js/places/place-view2.js b/js/places/place-view2.js index e7e3a24..4de1345 100644 --- a/js/places/place-view2.js +++ b/js/places/place-view2.js @@ -33,22 +33,22 @@ let GamePinned; }; if (Settings.PinnedGamesOn === true) { - HandlePinnedGames() + PinnedGames() } // Work in Progress if (Settings.InlineEditingOn === true) { - HandleInlineEditing() + InlineEditing() } // Work in Progress if (Settings.GameProfilesOn === true) { - HandleGameProfiles() + GameProfiles() } }); })() -async function HandlePinnedGames() { +async function PinnedGames() { chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result){ PinnedGames = result.PolyPlus_PinnedGames || {}; /* @@ -154,7 +154,7 @@ async function HandlePinnedGames() { }); } -async function HandleInlineEditing() { +async function InlineEditing() { // Fix description editing // Make it possible to edit description even if the game doesn't initially have a description // Add the ability to edit the game's genre @@ -320,7 +320,7 @@ async function HandleInlineEditing() { const Data = JSON.parse('{"gameTitle": "Hyper[Fart]","bg": "#000","accent": "#007bff","secondary": "#","cardBg": "#313131","font": "","text": "#fff"}') -async function HandleGameProfiles(Data) { +async function GameProfiles(Data) { document.querySelector('h1.my-0') .setAttribute('game-key', 'true'); document.querySelector('div[style="min-height: 60vh;"]') diff --git a/js/store/item-view.js b/js/store/item-view.js index 792ed50..2fd3e23 100755 --- a/js/store/item-view.js +++ b/js/store/item-view.js @@ -6,6 +6,7 @@ var Settings; var ItemWishlist; var PurchaseBtn; var WishlistBtn; +var ItemOwned; (async () => { if (!(window.location.href.split('/')[4])) {return} @@ -13,14 +14,14 @@ var WishlistBtn; Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js')); Utilities = Utilities.default - if (!(window.location.href.split('/')[4])) {return} chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ Settings = result.PolyPlus_Settings || {} - PurchaseBtn = document.getElementsByClassName('btn btn-outline-success')[0] + PurchaseBtn = document.querySelector('.btn#purchase-button') + ItemOwned = (PurchaseBtn.innerText === ' Item owned' || document.querySelector('.btn[onclick="sellItem()"]') !== null) if (Settings.IRLPriceWithCurrencyOn === true){ IRLPrice() } - if (Settings.ItemWishlistOn === true && !(PurchaseBtn.getAttribute('disabled'))) { + if (Settings.ItemWishlistOn === true) { HandleItemWishlist() } }) @@ -74,7 +75,21 @@ function HandleItemWishlist() { chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ ItemWishlist = result.PolyPlus_ItemWishlist || []; - if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) { + if (ItemOwned === true) { + if (ItemWishlist.includes(parseInt(ItemID))) { + ItemWishlist.splice(ItemWishlist.indexOf(parseInt(ItemID)), 1) + chrome.storage.sync.set({'PolyPlus_ItemWishlist': ItemWishlist, arrayOrder: true}); + } + return + } + if (ItemOwned === true) { + return + } else if (ItemOwned === true && ItemWishlist.includes(parseInt(ItemID))) { + ItemWishlist.splice(ItemWishlist.indexOf(parseInt(ItemID)), 1) + return + } + + if (ItemWishlist.includes(parseInt(ItemID))) { WishlistBtn.classList = 'btn btn-danger btn-sm' WishlistBtn.innerHTML = ` Un-Wishlist Item diff --git a/manifest.json b/manifest.json index 393a631..d988c58 100755 --- a/manifest.json +++ b/manifest.json @@ -51,13 +51,7 @@ { "matches": ["https://polytoria.com/users/**"], - "js": ["/js/profile/profile.js"] - }, - - { - "matches": ["https://polytoria.com/profile/**"], - "js": ["/js/profile/simplified-profile.js"], - "run_at": "document_start" + "js": ["/js/account/profile.js"] }, { diff --git a/settings.html b/settings.html index 832a6df..951173b 100755 --- a/settings.html +++ b/settings.html @@ -132,18 +132,6 @@