diff --git a/icon.png b/icon.png old mode 100755 new mode 100644 index 1315998..2921c8a Binary files a/icon.png and b/icon.png differ diff --git a/js/account/avatar-sandbox.js b/js/account/avatar-sandbox.js index 42ec484..9615f8b 100755 --- a/js/account/avatar-sandbox.js +++ b/js/account/avatar-sandbox.js @@ -42,7 +42,7 @@ let ItemCardContents = ` if (new URLSearchParams(new URL(window.location).search).get('sandbox') === 'true') { console.log('Avatar Sandbox!') - LoadFile(chrome.runtime.getURL('js/account/avatar-sandbox.html'), function(html){ + LoadFile(chrome.runtime.getURL('js/resources/avatar-sandbox.html'), function(html){ PageContainer.innerHTML = html ItemGrid = document.getElementById('inventory') Wearing = document.getElementById('wearing') diff --git a/js/account/avatar-sandbox2.js b/js/account/avatar-sandbox2.js index ebad5e6..3968a77 100755 --- a/js/account/avatar-sandbox2.js +++ b/js/account/avatar-sandbox2.js @@ -46,7 +46,7 @@ let ItemCardContents = ` if (new URLSearchParams(new URL(window.location).search).get('sandbox') === 'true') { console.log('Avatar Sandbox!') - LoadFile(chrome.runtime.getURL('js/account/avatar-sandbox.html'), function(html){ + LoadFile(chrome.runtime.getURL('js/resources/avatar-sandbox.html'), function(html){ PageContainer.innerHTML = html ItemGrid = document.getElementById('inventory') Wearing = document.getElementById('wearing') diff --git a/js/account/home.js b/js/account/home.js index ea9f6c1..558df4e 100755 --- a/js/account/home.js +++ b/js/account/home.js @@ -49,13 +49,13 @@ let Spacer = document.createElement('div') Spacer.innerHTML = ' ' Spacer.style.width = '50px' Spacer.prepend(BestFriendsContainer) -FriendContainer.prepend(BestFriendsContainer) +FriendContainer.prepend(BestFriendsContainer) UpdateLocalData(); function UpdateLocalData() { chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { - Settings = result.PolyPlus_Settings + Settings = result.PolyPlus_Settings || {PinnedGamesOn: false} }); chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result) { @@ -93,7 +93,7 @@ function LoadPinnedGames() { } PinnedGames.forEach(element => { - fetch('https://api.polytoria.com/v1/places/:id'.replace(':id', element)) + fetch('https://api.polytoria.com/v1/places/' + element) .then(response => response.json()) .then(data => { let GameName = data.name; @@ -101,7 +101,7 @@ function LoadPinnedGames() { var NewGameContainer = document.createElement('a'); NewGameContainer.innerHTML = GameContainerElement.replace(':GameName',GameName).replace(':Thumbnail',GameThumbnail); - NewGameContainer.setAttribute('href', '/places/:id'.replace(':id',element)); + NewGameContainer.setAttribute('href', '/places/' + element); if (new Date().getDate() >= new Date(data.updatedAt).getDate()) { console.log('Game has updated') @@ -123,9 +123,13 @@ function LoadBestFriends() { }); if (BestFriends.length === 0) { - BestFriendsContainer.style.display = 'none' + BestFriendsContainer.style.visibility = 'hidden' + BestFriendsContainer.style.padding = '0px !important' + BestFriendsContainer.style.margin = '0px !important' } else { - BestFriendsContainer.style.display = '' + BestFriendsContainer.style.visibility = 'visible' + BestFriendsContainer.style.padding = '' + BestFriendsContainer.style.margin = '' } BestFriends.forEach(element => { diff --git a/js/account/inventory.js b/js/account/inventory.js index a57615b..e394c05 100755 --- a/js/account/inventory.js +++ b/js/account/inventory.js @@ -1,5 +1,5 @@ if (window.location.pathname.split('/')[3] === "inventory") { - let UserID = window.location.pathname.split('/')[2] + const UserID = window.location.pathname.split('/')[2] if (UserID === JSON.parse(window.localStorage.getItem('account_info')).ID) { let Nav = document.getElementsByClassName('nav-pills')[0] let WishlistNav = document.createElement('li') @@ -13,8 +13,8 @@ if (window.location.pathname.split('/')[3] === "inventory") { Nav.appendChild(WishlistNav) if (window.location.pathname.split('/')[4] === "wishlist") { - let ItemGrid = document.getElementsByClassName('itemgrid')[0] - let ItemCardContents = ` + const ItemGrid = document.getElementsByClassName('itemgrid')[0] + const ItemCardContents = `
:LimitedTag @@ -44,7 +44,7 @@ if (window.location.pathname.split('/')[3] === "inventory") { } }); WishlistNav.children[0].classList.add('active') - let Search = document.createElement('div') + const Search = document.createElement('div') Search.classList = 'row' Search.innerHTML = `
diff --git a/js/forum/forum-view-old.js b/js/forum/forum-view-old.js deleted file mode 100755 index f999098..0000000 --- a/js/forum/forum-view-old.js +++ /dev/null @@ -1,173 +0,0 @@ -var idCache = [] -let url = "https://polytoria.com/users/:id" - -console.log('loaded!') - -function LowAttentionSpanMode() { - let PostContent = document.querySelector('.mcard p:nth-child(3)').textContent - let Captions = CombineArray(PostContent.split(' ')).map((x, i) => `${x}`).join('') - let NumberOfCaptions = (PostContent.split(' ').length) - 1 - Swal.fire({ - title: "No Attention Span Mode", - html: ` - @$1'); - output = output.replace(/\n/g, '
'); - element.innerHTML = output - - let links = element.querySelectorAll('a.polyplus-mention'); - if (!(links.length > 3)) { - HandleLinks(links, null) - setTimeout(function () {}, 125) - } - }); - } -}); - -function HandleLinks(links, link, index = 0) { - if (index >= links.length) { - return - } - - link = links[index] - let username = link.textContent.replace(/@/g, '') - var inCache = CheckIDCache(username) - console.log(idCache, inCache) - if (inCache.success === false) { - fetch('https://api.polytoria.com/v1/users/find?username=:user'.replace(':user', username)) - .then(response => { - if (!response.ok) { - throw new Error(`An error occurred: ${response.status}`); - } - return response.json(); - }) - .then(data => { - link.setAttribute('href', url.replace(':id', data.id)); - idCache.push({ "username": username, "id": data.id }); - console.log(idCache); - HandleLinks(links, null, index + 1) - }) - .catch(error => { - console.error(error); - link.removeAttribute('href'); - HandleLinks(links, null, index + 1) - }); - } else { - console.log('cached') - link.setAttribute('href', url.replace(':id', inCache.id)) - HandleLinks(links, null, index + 1) - } -} - -function CheckIDCache(cache, username) { - idCache.forEach(element => { - if (element.username === username) { - return {"success": true, "id": element.id} - } - }); - /* - for (let i = 0; i < cache.length; i++) { - const element = cache[i]; - console.log((element.username === username)) - if (element.username === username) { - return {"success": true, "id": element.id}; - } - } - */ - return {"success": false, "id": null}; -} - -function MarkdownText(text) { - // Split the text into an array of lines - const lines = text.split('\n'); - - // Process each line - const formattedLines = lines.map(line => { - if (line.startsWith('###')) { - // Third-level heading: remove the '###' and wrap in

tag - const headingText = line.substring(3).trim(); - return `

${headingText}

`; - } else if (line.startsWith('##')) { - // Secondary heading: remove the '##' and wrap in

tag - const headingText = line.substring(2).trim(); - return `

${headingText}

`; - } else if (line.startsWith('#')) { - // Big heading: remove the '#' and wrap in

tag - const headingText = line.substring(1).trim(); - return `

${headingText}

`; - } else { - // Apply formatting to the line - let formattedLine = line.replace(/\*\*(.*?)\*\*/g, '$1'); // Bold - formattedLine = formattedLine.replace(/__(.*?)__/g, '$1'); // Underline - formattedLine = formattedLine.replace(/\*(.*?)\*/g, '$1'); // Italics - formattedLine = formattedLine.replace(/~~(.*?)~~/g, '$1'); // Strikethrough - return formattedLine; - } - }); - - // Join the formatted lines back into a single string - const formattedText = formattedLines.join('\n\n'); - - return formattedText; - } \ No newline at end of file diff --git a/js/forum/forum-view-old2.js b/js/forum/forum-view-old2.js deleted file mode 100755 index 41b62ac..0000000 --- a/js/forum/forum-view-old2.js +++ /dev/null @@ -1,63 +0,0 @@ -chrome.storage.sync.get(['PolyPlus'], function (result) { - if (result.PolyPlus.Settings.ForumMentsOn === false) { - return; - } - - const idCache = []; - const url = "https://polytoria.com/users/:id"; - const text = document.querySelectorAll('p.mb-0'); - - async function CheckIDCache(cache, username) { - for (let i = 0; i < cache.length; i++) { - const element = cache[i]; - console.log('type', typeof element); - console.log('expected type', typeof username); - - const cachedUsername = Object.keys(element)[0]; - if (cachedUsername.toString() === username) { - return [true, element]; - } - } - return [false, null]; - } - - async function processLinks(links) { - for (const link of links) { - const username = link.textContent.replace(/@/g, ''); - const inCache = await CheckIDCache(idCache, username); - console.log('1', inCache[0]); - console.log('2', inCache[1]); - - if (inCache[0] === false) { - console.log('not cached'); - try { - const response = await fetch(`https://api.polytoria.com/v1/users/find?username=${username}`); - if (!response.ok) { - throw new Error(`An error occurred: ${response.status}`); - } - const data = await response.json(); - link.setAttribute('href', url.replace(':id', data.id)); - idCache.push({ [username]: data.id }); - console.log(idCache); - } catch (error) { - console.error(error); - link.removeAttribute('href'); - } - } else { - console.log('cached'); - link.setAttribute('href', url.replace(':id', inCache[1][username])); - } - } - } - - text.forEach(element => { - let output = element.innerText.replace(/@([\w.]+)/g, '@$1'); - output = output.replace(/\n/g, '
'); - element.innerHTML = output; - - const links = element.querySelectorAll('a'); - if (!(links.length > 3)) { - processLinks(links); - } - }); -}); diff --git a/js/forum/forum-view.js b/js/forum/forum-view.js index 0acca90..f1abeee 100644 --- a/js/forum/forum-view.js +++ b/js/forum/forum-view.js @@ -2,13 +2,16 @@ const ForumText = document.querySelectorAll('p:not(.text-muted):not(.mb-0)') var Settings = [] chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { - Settings = result.PolyPlus_Settings || [] + Settings = result.PolyPlus_Settings || { + ForumMentsOn: false, + ForumUnixStampsOn: false + } - if (Settings.ForumMentsOn === true || 1 === 2) { + if (Settings.ForumMentsOn === true) { HandleForumMentions() } - if (1 === 1) { + if (Settings.ForumUnixStampsOn === true) { HandleUnixTimestamps() } }); @@ -21,27 +24,28 @@ function HandleForumMentions() { let match; while ((match = Regex.exec(text.innerText)) !== null) { const Username = match[0].substring(1) - FormattedText = FormattedText.replaceAll(match[0], `${match[0]}`) + FormattedText = FormattedText.replaceAll(match[0], `${match[0]}`) } text.innerHTML = FormattedText } } function HandleUnixTimestamps() { - const Regex = //gm - //const Regex = /<t:[A-Za-z0-9]+>/i + const Regex = /<t:[A-Za-z0-9]+>/i for (let text of ForumText) { - //let FormattedText = text.innerHTML + let FormattedText = text.innerHTML let match; - while ((match = Regex.exec(text.innerText)) !== null) { - console.log(match[0]) - const Timestamp = new Date(parseInt(match[0].substring(3).slice(0, -1))*1000) + + while ((match = Regex.exec(FormattedText)) !== null) { + const Timestamp = new Date(match[0].substring(6, match[0].length - 4) * 1000) const Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] - const Result = `${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()}` - text.innerHTML = text.innerText.replaceAll(Regex.exec(text.innerText)[0], Result) + const Distance = new Intl.RelativeTimeFormat({numeric: 'auto', style: 'short'}).format(Math.floor((Timestamp - new Date()) / (60 * 1000)), 'day') + const Result = `${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()} (${["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][Timestamp.getDay()-1]}) at ${Timestamp.getHours()-12}:${String(Timestamp.getMinutes()).padStart(2, "0")} (${Distance})` + FormattedText = FormattedText.replaceAll(match[0], Result) + console.log(FormattedText) } - //text.innerHTML = FormattedText + text.innerHTML = FormattedText } } \ No newline at end of file diff --git a/js/membership-themes.js b/js/membership-themes.js index ee67a76..ebc8154 100755 --- a/js/membership-themes.js +++ b/js/membership-themes.js @@ -1,7 +1,10 @@ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ - Settings = result.PolyPlus_Settings || []; - + Settings = result.PolyPlus_Settings || { + ApplyMembershipThemeOn: false, + ApplyMembershipThemeTheme: 0 + }; if (Settings.ApplyMembershipThemeOn !== true) {return} + MembershipTheme = Settings.ApplyMembershipThemeTheme === 0 ? 'plus': 'plusdx' document.addEventListener('DOMContentLoaded', function(){ diff --git a/js/places/place-join.js b/js/places/place-join.js index 2614110..3f732e7 100644 --- a/js/places/place-join.js +++ b/js/places/place-join.js @@ -1,7 +1,10 @@ -!(() => { - const PlaceID = parseInt(window.location.pathname.split('/')[2]) +/* + DISABLED FEATURE +*/ - console.log('PLACE ID: ' + PlaceID) +!(() => { + return + const PlaceID = parseInt(window.location.pathname.split('/')[2]) fetch('https://polytoria.com/home') .then(response => { diff --git a/js/places/place-view.js b/js/places/place-view.js index af29130..96359f5 100755 --- a/js/places/place-view.js +++ b/js/places/place-view.js @@ -7,7 +7,6 @@ let PinnedGames; !(() => { if (GameID === undefined) {return} - /* const DataContainer = document.getElementById('likes-data-container') const RatingsData = { Likes: parseInt(DataContainer.getAttribute('data-like-count')), @@ -25,7 +24,6 @@ let PinnedGames; PercentageLabel.innerText = RatingsData.Percentage + '%' RatingsContainer.children[0].appendChild(PercentageLabel) - */ chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { Settings = result.PolyPlus_Settings; @@ -55,7 +53,12 @@ async function HandlePinnedGames() { if (PinnedGames.includes(parseInt(GameID))) { PinBtn.innerHTML = ' Un-pin'; } else { - PinBtn.innerHTML = ' Pin'; + if (PinnedGames.length !== 5) { + PinBtn.innerHTML = ' Pin' + } else { + PinBtn.setAttribute('disabled', true) + PinBtn.innerHTML = ' Pin (max 5/5)' + } } PinBtn.addEventListener('click', function() { diff --git a/js/places/place-view2.js b/js/places/place-view2.js new file mode 100644 index 0000000..b51adfe --- /dev/null +++ b/js/places/place-view2.js @@ -0,0 +1,313 @@ +let GameID = window.location.pathname.split('/')[2] + +var Settings; +let PinnedGames; +let GamePinned; + +!(() => { + if (GameID === undefined) {return} + + const DataContainer = document.getElementById('likes-data-container') + const RatingsData = { + Likes: parseInt(DataContainer.getAttribute('data-like-count')), + Dislikes: parseInt(DataContainer.getAttribute('data-dislike-count')), + Percentage: null + } + RatingsData.Percentage = Math.floor((RatingsData.Likes / (RatingsData.Likes + RatingsData.Dislikes)) * 100) + const RatingsContainer = document.getElementById('thumbup-btn').parentElement.parentElement + + const PercentageLabel = document.createElement('small') + PercentageLabel.classList = 'text-muted' + PercentageLabel.style.fontSize = '0.8rem' + PercentageLabel.style.marginLeft = '10px' + PercentageLabel.style.marginRight = '10px' + PercentageLabel.innerText = RatingsData.Percentage + '%' + + RatingsContainer.children[0].appendChild(PercentageLabel) + + chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { + Settings = result.PolyPlus_Settings; + + if (Settings.PinnedGamesOn === true) { + HandlePinnedGames() + } + + // Disabled settings + if (Settings.InlineEditingOn === true || 1 === 1) { + HandleInlineEditing() + } + + if (Settings.GameProfilesOn === true && 1 === 2) { + HandleGameProfiles() + } + }); +})() + +async function HandlePinnedGames() { + chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result){ + PinnedGames = result.PolyPlus_PinnedGames || {}; + const PinBtn = document.createElement('button'); + PinBtn.classList = 'btn btn-warning btn-sm'; + PinBtn.style = 'position: absolute; right: 0; margin-right: 7px;' + + if (PinnedGames[GameID]) { + PinBtn.innerHTML = ' Un-pin'; + } else { + if (PinnedGames.length !== 5) { + PinBtn.innerHTML = ' Pin' + } else { + PinBtn.setAttribute('disabled', true) + PinBtn.innerHTML = ' Pin (max 5/5)' + } + } + + PinBtn.addEventListener('click', function() { + PinBtn.setAttribute('disabled', 'true') + + chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result) { + PinnedGames = result.PolyPlus_PinnedGames || {}; + if (PinnedGames[GameID]) { + delete PinnedGames[GameID] + PinBtn.innerHTML = ' Pin' + } else { + PinnedGames[GameID] = {lastVisited: new Date()} + PinBtn.innerHTML = ' Un-pin' + } + + chrome.storage.sync.set({ 'PolyPlus_PinnedGames': PinnedGames, arrayOrder: true }, function() { + setTimeout(function() { + PinBtn.removeAttribute('disabled') + console.log(PinnedGames) + }, 1250) + }); + }); + }); + + document.querySelectorAll('.card-header')[2].appendChild(PinBtn); + + chrome.storage.onChanged.addListener(function(changes, namespace) { + if ('PolyPlus_PinnedGames' in changes) { + chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result) { + PinnedGames = result.PolyPlus_PinnedGames || {}; + + if (PinnedGames[GameID]) { + PinBtn.innerHTML = ' Un-pin' + } else { + if (PinnedGames.length !== 5) { + PinBtn.removeAttribute('disabled') + PinBtn.innerHTML = ' Pin' + } else { + PinBtn.setAttribute('disabled', true) + PinBtn.innerHTML = ' Pin (max 5/5)' + } + } + }); + } + }); + }); +} + +async function HandleInlineEditing() { + // 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 + // Improve editing visuals overall + + const GameCreator = document.querySelector('#main-content .card-body .col div.text-muted a[href^="/users/"]').getAttribute('href').split('/')[2] + console.log(GameCreator) + console.log(JSON.parse(window.localStorage.getItem('account_info')).ID) + if (GameCreator !== JSON.parse(window.localStorage.getItem('account_info')).ID) { + return + } + + let Editing = false + + const Style = document.createElement('style') + Style.innerHTML = ` + body[data-polyplus-inlineEditing="true"] .polyplus-inlineEditing-visible {display: block !important;} + .polyplus-inlineEditing-visible {display: none;} + + body[data-polyplus-inlineEditing="true"] .polyplus-inlineEditing-hidden {display: none !important;} + .polyplus-inlineEditing-hidden {display: block;} + ` + document.body.prepend(Style) + + const Inputs = [ + { + name: "name", + element: null, + reference: '.card-header h1[style="font-weight:800;font-size:1.6em"]', + placeholder: "Place Title..", + required: true, + isTextarea: false, + styles: 'font-weight:800;font-size:1.6em' + }, + { + name: "description", + element: null, + reference: '.col:has(#likes-data-container) .card.mcard.mb-2 .card-body.p-3.small', + placeholder: "Place Description..", + required: false, + isTextarea: true, + styles: 'height:300px; overflow-y:auto;' + } + ] + console.log(Inputs) + for (let input of Inputs) { + let Input = (input.isTextarea === true) ? document.createElement('textarea') : document.createElement('input') + input.element = Input + + const Reference = document.querySelector(input.reference) + + Input.classList = 'polyplus-inlineEditing-visible form-control' + Input.placeholder = input.placeholder + Input.value = Reference.innerText + Input.style = input.styles + + Reference.classList.add('polyplus-inlineEditing-hidden') + Reference.parentElement.appendChild(Input) + } + + const PlaceGenre = document.getElementsByClassName('list-unstyled m-0 col')[0].children[3] + + const Genres = [ + "other", + "adventure", + "building", + "competitive", + "creative", + "fighting", + "funny", + "hangout", + "medieval", + "parkour", + "puzzle", + "racing", + "roleplay", + "sandbox", + "showcase", + "simulator", + "sports", + "strategy", + "survival", + "techdemo", + "trading", + "tycoon", + "western" + ] + + const EditBtn = document.createElement('button'); + EditBtn.classList = 'btn btn-primary btn-sm'; + EditBtn.style = 'position: absolute; right: 0; margin-right: 7px;' + EditBtn.innerHTML = ' Edit Details' + document.getElementsByClassName('card-header')[3].appendChild(EditBtn); + + EditBtn.addEventListener('click', function(){ + Editing = !Editing + + EditBtn.children[0].classList.toggle('fa-hammer') + EditBtn.children[0].classList.toggle('fa-check-double') + EditBtn.children[0].classList.toggle('fa-fade') + + document.body.setAttribute('data-polyplus-inlineEditing', Editing) + + if (Editing === false) { + const Send = new FormData() + Send.append("_csrf", document.querySelector('input[name="_csrf"]').value) + Send.append("id", GameID) + for (let input of Inputs) { + console.log('start of loop') + Send.append(input.name, input.element.value) + } + + console.log('after') + fetch('/create/place/update', {method:"POST",body:Send}) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.text() + }) + .then(data => { + console.log('Successfully edited game') + for (let input of Inputs) { + const Reference = document.querySelector(input.reference) + Reference.innerText = input.element.value + } + }) + .catch(error => { + alert('Error while saving changes') + console.log('Error while editing game') + }); + } + + /* + PlaceTitleSpan.setAttribute('contenteditable', Editing.toString()) + if (PlaceDesc !== null) { + console.log('Description exists') + PlaceDesc.setAttribute('contenteditable', Editing.toString()) + } + if (Editing === false) { + const Send = new FormData() + Send.append("_csrf", document.querySelector('input[name="_csrf"]').value) + Send.append("id", GameID) + Send.append("name", PlaceTitle.innerText || '') + + fetch('/create/place/update', {method:"POST",body:Send}) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.text() + }) + .then(data => { + console.log('Successfully edited game') + }) + .catch(error => { + console.log('Error while editing game') + }); + } + */ + }); +} + +const Data = JSON.parse('{"gameTitle": "Hyper[Fart]","bg": "#000","accent": "#007bff","secondary": "#","cardBg": "#313131","font": "","text": "#fff"}') + +async function HandleGameProfiles(Data) { + document.querySelector('h1.my-0') + .setAttribute('game-key', 'true'); + document.querySelector('div[style="min-height: 60vh;"]') + .id = 'gameprofile'; + + const Style = document.createElement('style') + + Style.innerHTML = ` + div#app { + background: ${Data.bg} !important; + } + + #gameprofile { + /*font-family: ${Data.font} !important;*/ + color: ${Data.text} !important; + } + + #gameprofile .card { + --bs-card-bg: ${Data.cardBg}; + } + + /* + #gameprofile .card.mcard[game-key] .card-header { + background: transparent; + border: none; + } + */ + + #gameprofile .card.mcard [game-key] { + background: linear-gradient(to bottom, ${Data.accent}, ${Data.secondary}); + background-clip: text; + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + } + ` + document.body.appendChild(Style) +} \ No newline at end of file diff --git a/js/polyplus-settings.js b/js/polyplus-settings.js index 847012c..c8ea396 100755 --- a/js/polyplus-settings.js +++ b/js/polyplus-settings.js @@ -22,871 +22,4 @@ document.addEventListener('DOMContentLoaded', function(){ ` Nav.insertBefore(PolyPlusItem, Nav.getElementsByTagName('hr')[0]) - - return - if (window.location.pathname.split('/')[3] === "polyplus") { - console.log('is settings') - PolyPlusItem.classList.add('active') - document.getElementsByClassName('col-lg-10')[0].innerHTML = ` - - - - - - - - - - - - - -
-

- - Pinned Games (enabled) - - -
- Pin your favorite games to the top of the homepage! -

-

- - Forum Mentions (disabled) - - -
- Get a quick link to the popular person everyone is talking about's profile! -

-

- - Best Friends (enabled) - - -
- Prioritize the bestest of friends on applicable friend lists! -

-

- - Improved Friend Lists (enabled) - - -
- - Accept or decline all friend requests with the click of a button or multi-remove existing friends! -
- * You can only remove up to 25 friends at once. -
-

-

- - Show IRL price with Brick Count (enabled) - - -
- - See the real life currency value along with Bricks across the site! -
- * Currencies were calculated on [DATE]. -
- * Currencies other than USD are purely approximations. -
- - - -

-

- - Hide Notification Badges (disabled) - - -
- Hide the annoying red circles on the sidebar! -

-

- - Simplified Profile URLs (enabled) - - -
- Makes all profile URLs simpler by allowing for you to go to "https://polytoria.com/profile/UsernameGoesHere" to redirect to the real profile URL! -

-

- - Show "OWNED" Tag on Store Main Page (enabled) - - -
- Quickly see if you own the item at a glance with a little tag in the top left corner of item cards on the main store page! -

-

- - Theme Creator (disabled) - - - -
- Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development) -

-

- - More Search Filters (enabled) - - -
- Easily find what you're looking for with more search filters side-wide! (this does not affect the main site search on the navbar) -

-

- - Apply Membership Theme for Free (disabled) - - -
- Ever want the fancy membership themes for completely free? Well now you can get apply them site-wide! - -

- -

- - Multi-Cancel Outbound Trades (enabled) - - -
- - Quickly cancel several out-bound trades (trades that you have sent) all at once -
- * You can only cancel up to 10 trades at once. -
-

-

- - Modify Navbar (disabled) - - - -
- - Customize the navbar to your liking! - -

-

- - Item Wishlist (enabled) - - -
- - Wishlist that item that you REALLY want! - -

-

- - Hide Upgrade Button (disabled) - - -
- Hide the ugly blue "Upgrade" button on the sidebar! -

-
- - -

made by Index

-
- `; - - const SaveBtn = document.getElementById('Save') - const Elements = [ - document.getElementById("PinnedGames"), - document.getElementById("ForumMentions"), - document.getElementById("BestFriends"), - document.getElementById("ImprovedFriendLists"), - document.getElementById("IRLPriceWithCurrency"), - document.getElementById("HideNotifBadges"), - document.getElementById("SimplifiedProfileURLs"), - document.getElementById("StoreOwnTag"), - document.getElementById("ThemeCreator"), - document.getElementById("MoreSearchFilters"), - document.getElementById("ApplyMembershipTheme"), - document.getElementById("MultiCancelOutTrades"), - document.getElementById("ModifyNav"), - document.getElementById("ItemWishlist"), - document.getElementById("HideUpgradeBtn") - ]; - const ExpectedSettings = { - PinnedGamesOn: true, - ForumMentsOn: false, - BestFriendsOn: true, - ImprovedFrListsOn: true, - IRLPriceWithCurrencyOn: true, - IRLPriceWithCurrencyCurrency: 0, - IRLPriceWithCurrencyPackage: 0, - HideNotifBadgesOn: false, - SimplifiedProfileURLsOn: true, - StoreOwnTagOn: true, - ThemeCreatorOn: false, - ThemeCreator: { - BGColor: null, - BGImage: null, - BGImageSize: 'fit', - PrimaryTextColor: null, - SecondaryTextColor: null, - LinkTextColor: null, - WebsiteLogo: null - }, - ModifyNavOn: false, - ModifyNav: [ - { - Label: "Play", - 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, - ApplyMembershipThemeOn: false, - ApplyMembershipThemeTheme: 0, - MultiCancelOutTradesOn: true, - ItemWishlistOn: true, - HideUpgradeBtnOn: false - } - - /* - const ResetDefaultsModal = document.getElementById('ResetDefaults-Modal') - const ThemeCreatorModal = { - Modal: document.getElementById('ThemeCreator-Modal'), - Save: document.getElementById('ThemeCreator-Modal-Save'), - BGColor: document.getElementById('ThemeCreator-Modal-BGColor'), - BGImage: document.getElementById('ThemeCreator-Modal-BGImage'), - BGImageSize: document.getElementById('ThemeCreator-Modal-BGImageSize'), - PrimaryTextColor: document.getElementById('ThemeCreator-Modal-PrimaryTextColor'), - SecondaryTextColor: document.getElementById('ThemeCreator-Modal-SecondaryTextColor'), - LinkTextColor: document.getElementById('ThemeCreator-Modal-LinkTextColor'), - WebsiteLogo: document.getElementById('ThemeCreator-Modal-WebsiteLogo') - } - var ModifyNavModal = { - Modal: document.getElementById('ModifyNav-Modal'), - Save: document.getElementById('ModifyNav-Modal-Save'), - "1Label": document.getElementById('ModifyNav-Modal-1Label'), - "1Link": document.getElementById('ModifyNav-Modal-1Link'), - "2Label": document.getElementById('ModifyNav-Modal-2Label'), - "2Link": document.getElementById('ModifyNav-Modal-2Link'), - "3Label": document.getElementById('ModifyNav-Modal-3Label'), - "3Link": document.getElementById('ModifyNav-Modal-3Link'), - "4Label": document.getElementById('ModifyNav-Modal-4Label'), - "4Link": document.getElementById('ModifyNav-Modal-4Link'), - "5Label": document.getElementById('ModifyNav-Modal-5Label'), - "5Link": document.getElementById('ModifyNav-Modal-5Link'), - } - */ - SaveBtn.addEventListener("click", function() {Save()}); - Elements.forEach(element => { - let Button = element.getElementsByTagName('button')[0] - let Options = element.getElementsByTagName('button')[1] - let Select = element.getElementsByTagName('select') || [] - - if (Button) { - Button.addEventListener('click', function() { - console.log('button clicked!!!!') - ToggleSetting(Button.getAttribute('data-setting'), element) - }); - } - - if (Options) { - Options.addEventListener('click', function() { - let Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal') - let ModalButtons = Modal.getElementsByTagName('button') - let ModalInputs = Modal.getElementsByTagName('input') - let ModalSelect = Modal.getElementsByTagName('select') - - Array.from(ModalButtons).forEach(btn => { - if (!(btn.getAttribute('data-ignore') === 'true')) { - btn.addEventListener('click', function(){ - let Setting = btn.getAttribute('data-setting') - if (Setting === '[save]') { - Array.from(ModalInputs).forEach(input => { - if (!(input.getAttribute('data-ignore') === 'true')) { - if (!(input.getAttribute('data-parent'))) { - Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] = input.value || null - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] = input.value || null - } - } - }); - Array.from(ModalSelect).forEach(select => { - if (!(select.getAttribute('data-ignore') === 'true')) { - if (!(select.getAttribute('data-parent'))) { - Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] = select.selectedIndex - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] = select.selectedIndex - } - } - }); - Save(); - setTimeout(function () { - LoadCurrent(); - Modal.close(); - }, 400) - } else if (Setting === '[cancel]') { - Modal.close(); - } else { - if (!(btn.getAttribute('data-parent'))) { - ToggleSetting(Modal.getAttribute('data-setting')[btn.getAttribute('data-setting')], null) - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - ToggleSetting(Modal.getAttribute('data-setting')[Parent][btn.getAttribute('data-setting')], null) - } - } - }); - } - }); - - Array.from(ModalInputs).forEach(input => { - if (!(input.getAttribute('data-ignore') === 'true')) { - if (!(input.getAttribute('data-parent'))) { - if (Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== "undefined") { - input.value = Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] - } - } else { - let Parent = input.getAttribute('data-parent') - if (Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== "undefined") { - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - input.value = Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] - } - } - } - }); - - Array.from(ModalSelect).forEach(select => { - if (!(select.getAttribute('data-ignore') === 'true')) { - if (!(select.getAttribute('data-parent'))) { - if (Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] !== "undefined") { - select.selectedIndex = Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] - } - } else { - let Parent = input.getAttribute('data-parent') - if (Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] !== "undefined") { - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - select.selectedIndex = Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] - } - } - } - }); - - Modal.showModal() - }); - } - - if (Select.length > 0) { - Array.from(Select).forEach(element => { - element.addEventListener('change', function() { - SetSetting(element.getAttribute('data-setting'), element, element.selectedIndex) - }); - }); - } - }); - document.getElementById('ResetDefaults').addEventListener('click', function() { - ResetDefaultsModal.showModal(); - }); - document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() { - Settings = ExpectedSettings - Save() - setTimeout(function () { - LoadCurrent(); - ResetDefaultsModal.close(); - }, 400) - }); - document.getElementById('ResetDefaults-Modal-No').addEventListener('click', function() { - ResetDefaultsModal.close(); - }); - - function LoadCurrent() { - chrome.storage.sync.get(["PolyPlus_Settings"], function(result) { - Settings = MergeObjects(result.PolyPlus_Settings || ExpectedSettings, ExpectedSettings) - - console.log(Settings) - - Elements.forEach(element => { - let Status = element.getElementsByClassName('status')[0] - console.log(element, FormatBool(Settings[element.getElementsByTagName('button')[0].getAttribute('data-setting')])) - Status.innerText = FormatBool(Settings[element.getElementsByTagName('button')[0].getAttribute('data-setting')]) - let SelectInput = element.getElementsByTagName('select')[0] - if (SelectInput) { - SelectInput.selectedIndex = Settings[SelectInput.getAttribute('data-setting')] - } - }); - }); - } - LoadCurrent(); - - function ToggleSetting(Name, Element) { - if (Settings[Name] === true) { - Settings[Name] = false; - } else { - Settings[Name] = true; - } - - if (Element != null) { - Element.getElementsByClassName('status')[0].innerText = FormatBool(Settings[Name]) - } - if (SaveBtn.getAttribute('disabled')) { - SaveBtn.removeAttribute('disabled') - } - } - - function SetSetting(Name, Element, Value) { - console.log(Settings) - Settings[Name] = Value - - if (SaveBtn.getAttribute('disabled')) { - SaveBtn.removeAttribute('disabled') - } - } - - function Save() { - SaveBtn.setAttribute('disabled', 'true') - window.localStorage.setItem('PolyPlusSettings', JSON.stringify(Settings)) - chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() { - console.log('Saved successfully!'); - }); - - console.log(Settings); - } - - let LoadThemeFromJSONBtn = document.getElementById('LoadThemeFromJSONBtn') - let SaveThemeToJSONInput = document.getElementById('SaveThemeToJSONInput') - let CopyThemeJSONBtn = document.getElementById('CopyThemeJSONBtn') - LoadThemeFromJSONBtn.addEventListener('click', function(){ - LoadThemeJSON(LoadThemeFromJSONBtn.previousElementSibling.value) - }); - document.getElementById('ThemeCreator').getElementsByTagName('button')[1].addEventListener('click', function(){ - SaveThemeToJSONInput.value = JSON.stringify(Settings.ThemeCreator) - }); - CopyThemeJSONBtn.addEventListener('click', function(){ - if (SaveThemeToJSONInput.value.length > 0) { - navigator.clipboard.writeText(SaveThemeToJSONInput.value) - } - }); - - let CurrencyDate = LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){ - CurrencyDate = new Date(JSON.parse(text).Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"}) - - document.getElementById('IRLPriceWithCurrencyCurrency').previousElementSibling.children[1].innerText = document.getElementById('IRLPriceWithCurrencyCurrency').previousElementSibling.children[1].innerText.replace('[DATE]', CurrencyDate) - }) - - function LoadThemeJSON(string) { - try { - let JSONTable = JSON.parse(string) - if (JSONTable.length === ExpectedSettings.ThemeCreator.length) { - if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) { - LoadThemeFromJSONBtn.previousElementSibling.value = '' - document.getElementById('ThemeCreator-Modal').close() - Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator) - Save(); - console.log(JSONTable.length, JSONTable, 'applied') - document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click(); - } - } else { - alert('JSON is not a theme!') - //LoadThemeFromJSONBtn.innerText = 'JSON is too short or too long!' - //setTimeout(function () {LoadThemeFromJSONBtn.innerText = 'Load'}, 1250) - } - } catch (error) { - alert('JSON is invalid!') - //LoadThemeFromJSONBtn.innerText = 'JSON is invalid!' - //setTimeout(function () {LoadThemeFromJSONBtn.innerText = 'Load'}, 1250) - } - } - - /* - 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]; - } else if (obj1[key] !== obj2[key]) { - mergedObj[key] = obj2[key]; - } - } - - // Remove keys from mergedObj if they are not present in obj2 - for (var key in mergedObj) { - if (!obj2.hasOwnProperty(key)) { - delete mergedObj[key]; - } - } - - return mergedObj; - } - */ - - 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; - } - - function FormatBool(bool){ - if (bool === true) { - return 'enabled' - } else { - return 'disabled' - } - } - - function LoadFile(path, callback) { - var xhr = new XMLHttpRequest(); - xhr.onload = function () { return callback(this.responseText); } - xhr.open("GET", path, true); - xhr.send(); - } - } }); \ No newline at end of file diff --git a/js/profile/profile.js b/js/profile/profile.js index 9dfacf1..a6bf264 100755 --- a/js/profile/profile.js +++ b/js/profile/profile.js @@ -1,12 +1,18 @@ -setTimeout(function() {}, 100); -let URLSplit = window.location.pathname.split('/'); -let UserID = URLSplit[2]; +const UserID = window.location.pathname.split('/')[2]; +const AvatarRow = document.getElementsByClassName('d-flex flex-row flex-nowrap overflow-x-scroll px-3 px-lg-0 mb-2 mb-lg-0')[0] + var Settings; var BestFriends; -var FavoriteBtn; +let FavoriteBtn; +let CalculateButton; + if (UserID) { chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { - Settings = result.PolyPlus_Settings; + Settings = result.PolyPlus_Settings || { + IRLPriceWithCurrencyOn: false, + BestFriendsOn: false, + OutfitCostOn: true + } if (Settings.IRLPriceWithCurrencyOn === true) { HandleIRLPrice() @@ -16,29 +22,43 @@ if (UserID) { HandleBestFriends() } - if (1 === 1) { - HandleOufitCost() - } - }); - - // Update the local pinned games whenever the 'PinnedGames' array is updated - chrome.storage.onChanged.addListener(function(changes, namespace) { - if ('PolyPlus_BestFriends' in changes) { - chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result) { - BestFriends = result.PolyPlus_BestFriends || []; - - if (!(BestFriends.length === 7)) { - if (Array.isArray(BestFriends) && BestFriends.includes(parseInt(UserID))) { - FavoriteBtn.innerText = 'Remove Best Friend Status' - } else { - FavoriteBtn.innerText = 'Best Friend' - } - } else { - FavoriteBtn.innerText = 'Remove Best Friend Status (max 7/7)' - } + if (Settings.OutfitCostOn === true) { + CalculateButton = document.createElement('button') + CalculateButton.classList = 'btn btn-warning btn-sm' + CalculateButton.innerText = 'Calculate Avatar Cost' + AvatarRow.parentElement.parentElement.prepend(CalculateButton) + AvatarRow.parentElement.style.marginTop = '10px' + + CalculateButton.addEventListener('click', function(){ + HandleOufitCost() }); } - }); + }); + + 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(() => { + alert('Successfully copied 3D avatar URL!') + }) + .catch(() => { + alert('Failure to copy 3D avatar URL.') + }); + }); + + /* + Way overcomplicated code when there is literally an iframe on the page with the exact same result const UserID = window.location.pathname.split('/')[2] const DefaultAvatar = { @@ -118,6 +138,7 @@ if (UserID) { }); Original.parentElement.appendChild(Clone) + */ } function HandleIRLPrice() { @@ -162,7 +183,6 @@ function HandleBestFriends() { chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result){ BestFriends = result.PolyPlus_BestFriends || []; - console.log('Best friends is enabled!') FavoriteBtn = document.createElement('button'); FavoriteBtn.classList = 'btn btn-warning btn-sm ml-2'; if (!(BestFriends.length === 7)) { @@ -184,13 +204,13 @@ function HandleBestFriends() { document.querySelectorAll('.section-title.px-3.px-lg-0.mt-3')[0].appendChild(FavoriteBtn); function Fav(UserID, btn) { - if (UserID === JSON.parse(window.localStorage.getItem('account_info')).ID) { - return - } + if (UserID === JSON.parse(window.localStorage.getItem('account_info')).ID) { return } btn.setAttribute('disabled', 'true') + chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result) { const BestFriends = result.PolyPlus_BestFriends || []; const index = BestFriends.indexOf(parseInt(UserID)); + if (index !== -1) { // Number exists, remove it BestFriends.splice(index, 1); @@ -211,33 +231,42 @@ function HandleBestFriends() { }); }); } + }); - function ClearFavs(){ - chrome.storage.sync.set({ 'PolyPlus': {"PinnedGames": pinnedGames, "BestFriends": []}, arrayOrder: true }, function() { - console.log('BestFriends saved successfully!'); - setTimeout(function() { - btn.removeAttribute('disabled') - }, 1500) - }); - } - - function ClearFavsOld(){ - chrome.storage.sync.set({ 'PolyPlus': {"PinnedGames": pinnedGames, "BestFriends": []}, arrayOrder: true }, function() { - console.log('BestFriends saved successfully!'); - setTimeout(function() { - btn.removeAttribute('disabled') - }, 1500) + chrome.storage.onChanged.addListener(function(changes, namespace) { + if ('PolyPlus_BestFriends' in changes) { + chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result) { + BestFriends = result.PolyPlus_BestFriends || []; + + if (!(BestFriends.length === 7)) { + if (Array.isArray(BestFriends) && BestFriends.includes(parseInt(UserID))) { + FavoriteBtn.innerText = 'Remove Best Friend Status' + } else { + FavoriteBtn.innerText = 'Best Friend' + } + } else { + FavoriteBtn.innerText = 'Remove Best Friend Status (max 7/7)' + } }); } }); + + function ClearBestFriends(){ + chrome.storage.sync.set({ 'PolyPlus_BestFriends': {"BestFriends": []}, arrayOrder: true }, function() { + console.log('BestFriends saved successfully!'); + setTimeout(function() { + btn.removeAttribute('disabled') + }, 1500) + }); + } } async function HandleOufitCost() { - const AvatarRow = document.getElementsByClassName('d-flex flex-row flex-nowrap overflow-x-scroll px-3 px-lg-0 mb-2 mb-lg-0')[0] - - let TotalCost = 0 - let Limiteds = 0 - let Exclusives = 0 + const AvatarCost = { + Total: 0, + Limiteds: 0, + Exclusives: 0 + } for (let item of AvatarRow.children) { const ItemID = item.getElementsByTagName('a')[0].href.split('/')[4] await fetch('https://api.polytoria.com/v1/store/'+ItemID) @@ -250,14 +279,14 @@ async function HandleOufitCost() { .then(data => { let Price = data.price if (data.isLimited === true) { - Limiteds += 1 + AvatarCost.Limiteds += 1 Price = data.averagePrice } else if (data.sales === 0) { - Exclusives += 1 + AvatarCost.Exclusives += 1 Price = 0 } - TotalCost += Price + AvatarCost.Total += Price }) .catch(error => {console.log(error)}); } @@ -265,8 +294,7 @@ async function HandleOufitCost() { const TotalCostText = document.createElement('small') TotalCostText.classList = 'text-muted' TotalCostText.style.padding = '20px' - TotalCostText.innerHTML = `${ (Limiteds > 0 || Exclusives > 0) ? '~' : '' } ${TotalCost.toLocaleString()}${ (Limiteds > 0) ? ` (has ${Limiteds} limiteds)` : '' }${ (Exclusives > 0) ? ` (has ${Exclusives} exclusives)` : '' }` + TotalCostText.innerHTML = `${ (AvatarCost.Limiteds > 0 || AvatarCost.Exclusives > 0) ? '~' : '' } ${AvatarCost.Total.toLocaleString()}${ (AvatarCost.Limiteds > 0) ? ` (has ${AvatarCost.Limiteds} limiteds)` : '' }${ (AvatarCost.Exclusives > 0) ? ` (has ${AvatarCost.Exclusives} exclusives)` : '' }` AvatarRow.parentElement.parentElement.prepend(TotalCostText) AvatarRow.parentElement.style.marginTop = '10px' - console.log(TotalCostText) } \ No newline at end of file diff --git a/js/account/avatar-sandbox.html b/js/resources/avatar-sandbox.html similarity index 100% rename from js/account/avatar-sandbox.html rename to js/resources/avatar-sandbox.html diff --git a/js/utils.js b/js/resources/utils.js similarity index 100% rename from js/utils.js rename to js/resources/utils.js diff --git a/js/rewrites/everywhere2.js b/js/rewrites/everywhere2.js deleted file mode 100755 index e101b17..0000000 --- a/js/rewrites/everywhere2.js +++ /dev/null @@ -1,374 +0,0 @@ -const start = performance.now() -var Settings; -var ExpectedSettings = { - PinnedGamesOn: false, - ForumMentsOn: false, - BestFriendsOn: false, - ImprovedFrListsOn: false, - IRLPriceWithCurrencyOn: true, - IRLPriceWithCurrencyCurrency: 0, - IRLPriceWithCurrencyPackage: 0, - HideNotifBadgesOn: true, - SimplifiedProfileURLsOn: true, - StoreOwnTagOn: true, - ThemeCreatorOn: false, - ThemeCreator: { - BGColor: null, - BGImage: null, - BGImageSize: 'fit', - PrimaryTextColor: null, - SecondaryTextColor: null, - LinkTextColor: null, - WebsiteLogo: null - }, - ModifyNavOn: false, - ModifyNav: [ - { - Label: "Play", - 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, - ApplyMembershipThemeOn: false, - ApplyMembershipThemeTheme: 0, - ForumMarkOn: true, - MultiCancelOutTradesOn: true, - ItemWishlistOn: true, - HideUpgradeBtnOn: false -} -var Theme = null; - -// Merge settings and expected settings to make sure all keys exist -let RawSettings = JSON.parse(window.localStorage.getItem('PolyPlusSettings')) || ExpectedSettings -Settings = MergeObjects(RawSettings || ExpectedSettings, ExpectedSettings); -chrome.storage.sync.get(["PolyPlus_Settings"], function(result) { - window.localStorage.setItem('PolyPlusSettings', JSON.stringify(result)) -}); - -Theme = document.createElement('style') -switch (Settings.ThemeCreator.BGImageSize) { -case 0: - Settings.ThemeCreator.BGImageSize = 'fit' - break -case 1: - Settings.ThemeCreator.BGImageSize = 'cover' - break -case 2: - Settings.ThemeCreator.BGImageSize = 'contain' - break -} -Theme.innerHTML = ` -:root { - --polyplus-navbgcolor: ${Settings.ThemeCreator.NavBGColor}; - --polyplus-navbordercolor: ${Settings.ThemeCreator.NavBorderColor}; - --polyplus-navitemcolor: ${Settings.ThemeCreator.NavItemColor}; - --polyplus-sidebarbgcolor: ${Settings.ThemeCreator.SideBGColor}; - --polyplus-sidebarbordercolor: ${Settings.ThemeCreator.SideBorderColor}; - --polyplus-sidebaritembgcolor: ${Settings.ThemeCreator.SideItemBGColor}; - --polyplus-sidebaritembordercolor: ${Settings.ThemeCreator.SideItemBorderColor}; - --polyplus-sidebaritemcolor: ${Settings.ThemeCreator.SideItemColor}; - --polyplus-sidebaritemlabelcolor: ${Settings.ThemeCreator.SideItemLabelColor}; - --polyplus-bgcolor: ${Settings.ThemeCreator.BGColor}; - --polyplus-bgimage: url(${Settings.ThemeCreator.BGImage}); - --polyplus-bgimagesize: ${Settings.ThemeCreator.BGImageSize}; - --polyplus-primarytextcolor: ${Settings.ThemeCreator.PrimaryTextColor}; - --polyplus-secondarytextcolor: ${Settings.ThemeCreator.SecondaryTextColor}; - --polyplus-linktextcolor: ${Settings.ThemeCreator.LinkTextColor}; - --polyplus-linkhoveredtextcolor: ${Settings.ThemeCreator.LinkHoveredTextColor}; - --polyplus-linkfocusedtextcolor: ${Settings.ThemeCreator.LinkFocusedTextColor}; - --polyplus-linkvisitedtextcolor: ${Settings.ThemeCreator.LinkVisitedTextColor}; - --polyplus-cardheadbgcolor: ${Settings.ThemeCreator.CardHeadBGColor}; - --polyplus-cardbodybgcolor: ${Settings.ThemeCreator.CardBodyBGColor}; - --polyplus-cardbordercolor: ${Settings.ThemeCreator.CardBorderColor}; -} - -nav { - background-color: var(--polyplus-navbgcolor) !important; - border-bottom: 1px solid var(--polyplus-navbordercolor) !important; -} - -.nav-sidebar { - background-color: var(--polyplus-sidebarbgcolor) !important; - border-right: 1px solid var(--polyplus-sidebarbordercolor) !important; -} - -#app { - background-color: var(--polyplus-bgcolor) !important; - background-image: var(--polyplus-bgimage) !important; - background-size var(--polyplus-bgimagesize) - color: var(--polyplus-primarytextcolor) !important; -} - -.text-muted { - color: var(--polyplus-secondarytextcolor) !important; -} - -a { - color: var(--polyplus-linktextcolor) !important; -} - -a:hover { - color: var(--polyplus-linkhoveredtextcolor) !important; -} - -a:focus { - color: var(--polyplus-linkfocusedtextcolor) !important; -} - -/* -a:visited { - color: var(--polyplus-linkvisitedtextcolor) !important; -} -*/ - -.card-header { - background-color: var(--polyplus-cardheadbgcolor) !important; -} - -.card { - background-color: var(--polyplus-cardbodybgcolor) !important; - border-color: var(--polyplus-cardbordercolor) !important; -} - -nav a.nav-link { - color: var(--polyplus-navitemcolor) !important; -} - -.nav-sidebar .nav-sidebar-button { - background-color: var(--polyplus-sidebaritembgcolor) !important; - border-color: var(--polyplus-sidebaritembordercolor) !important; - color: var(--polyplus-sidebaritemcolor) !important; -} - -.nav-sidebar-text { - color: var(--polyplus-sidebaritemlabelcolor) !important; -} -` - - -document.addEventListener('DOMContentLoaded', function(){ - // Check if Theme Exists, if so Load It - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { - if (!(Settings.ThemeCreator.WebsiteLogo === null)) { - document.querySelector('.nav-sidebar img').setAttribute('src', Settings.ThemeCreator.WebsiteLogo) - } - } - let end; - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true && Theme != null) { - end = performance.now() - document.body.prepend(Theme) - } - console.log(end - start) - - // Define Data - var Username = document.querySelector('a.text-reset.text-decoration-none[href^="/users"]').innerText.replace(/\s+/g,''); - var UserID = document.querySelector('.text-reset.text-decoration-none[href^="/users/"]').getAttribute('href').split('/')[2] - var Bricks = document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g,''); - - document.body.setAttribute('data-username', Username) - document.body.setAttribute('data-id', UserID) - document.body.setAttribute('data-bricks', Bricks) - document.body.setAttribute('data-URL', window.location.href) - - // Add PolyPlus Settings link to Sidebar - var parent = document.querySelector('ul.nav.nav-flush') - var clone = parent.querySelectorAll('li.nav-item')[0].cloneNode(true) - clone.querySelector('a').setAttribute('href', '/my/settings/polyplus') - clone.querySelector('span').innerText = "Poly+" - var icon = clone.querySelector('i') - var newIcon = document.createElement('i') - newIcon.classList = 'fa-regular fa-sparkles' - icon.parentElement.appendChild(newIcon) - icon.remove() - parent.appendChild(clone) - - if (Settings.ModifyNavOn && Settings.ModifyNavOn === true) { - let NavbarItems = document.querySelectorAll('#main-content nav.navbar .nav-link') - let Needed = [NavbarItems[11],NavbarItems[12],NavbarItems[13],NavbarItems[14],NavbarItems[15]] - for (let i = 0; i < Settings.ModifyNav.length; i++) { - if (Settings.ModifyNav[i].Label != null) { - Needed[i].children[1].innerText = Settings.ModifyNav[i].Label - Needed[i].setAttribute('href', Settings.ModifyNav[i].Link) - } - } - } - - if (Settings.HideUpgradeBtnOn && Settings.HideUpgradeBtnOn === true) { - document.querySelector('.nav-sidebar a[href="/upgrade"].nav-link.py-1.nav-sidebar-link').remove() - } - - if (Settings.IRLPriceWithCurrencyOn && Settings.IRLPriceWithCurrencyOn === true) { - var IRL; - var DISPLAY; - switch (Settings.IRLPriceWithCurrencyCurrency) { - case 0: - IRL = (Bricks.replace(/,/g, '') * 0.0099).toFixed(2) - DISPLAY = 'USD' - break - case 1: - IRL = (Bricks.replace(/,/g, '') * 0.009).toFixed(2) - DISPLAY = 'EUR' - break - case 2: - IRL = (Bricks.replace(/,/g, '') * 0.0131).toFixed(2) - DISPLAY = 'CAD' - break - case 3: - IRL = (Bricks.replace(/,/g, '') * 0.0077).toFixed(2) - DISPLAY = 'GBP' - break - case 4: - IRL = (Bricks.replace(/,/g, '') * 0.1691).toFixed(2) - DISPLAY = 'MXN' - break - case 5: - IRL = (Bricks.replace(/,/g, '') * 0.0144).toFixed(2) - DISPLAY = 'AUD' - break - case 6: - IRL = (Bricks.replace(/,/g, '') * 0.2338).toFixed(2) - DISPLAY = 'TRY' - break - } - let BrickBalanceCount = document.querySelectorAll('.brickBalanceCount,.brickBalanceCont') - BrickBalanceCount.forEach(element => { - element.innerText = element.innerText + " ($" + IRL + " " + DISPLAY + ")" - }); - } - - if (Settings.HideNotifBadgesOn && Settings.HideNotifBadgesOn === true) { - document.querySelectorAll('.notif-nav.notif-sidebar').forEach(element => {element.remove();}); - } -}); - -/* -document.addEventListener('DOMContentLoaded', function() { - if (document.getElementsByClassName('card-header')[0] && document.getElementsByClassName('card-header')[0].innerText === ' Page not found') { - return - } - - // Check if Theme Exists, if so Load It - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { - if (!(Settings.ThemeCreator.WebsiteLogo === null)) { - document.querySelector('.nav-sidebar img').setAttribute('src', Settings.ThemeCreator.WebsiteLogo) - } - } - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true && Theme != null) { - document.body.prepend(Theme) - } - - // Define Data - var Username = document.querySelector('a.text-reset.text-decoration-none[href^="/users"]').innerText.replace(/\s+/g,''); - var UserID = document.querySelector('.text-reset.text-decoration-none[href^="/users/"]').getAttribute('href').split('/')[2] - var Bricks = document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g,''); - - document.body.setAttribute('data-username', Username) - document.body.setAttribute('data-id', UserID) - document.body.setAttribute('data-bricks', Bricks) - document.body.setAttribute('data-URL', window.location.href) - - // Add PolyPlus Settings link to Sidebar - var parent = document.querySelector('ul.nav.nav-flush') - var clone = parent.querySelectorAll('li.nav-item')[0].cloneNode(true) - clone.querySelector('a').setAttribute('href', '/my/polyplus') - clone.querySelector('span').innerText = "Poly+" - var icon = clone.querySelector('i') - var newIcon = document.createElement('i') - newIcon.classList = 'fa-regular fa-sparkles' - icon.parentElement.appendChild(newIcon) - icon.remove() - parent.appendChild(clone) - - if (Settings.ModifyNavOn && Settings.ModifyNavOn === true) { - let NavbarItems = document.querySelectorAll('#main-content nav.navbar .nav-link') - let Needed = [NavbarItems[11],NavbarItems[12],NavbarItems[13],NavbarItems[14],NavbarItems[15]] - for (let i = 0; i < Settings.ModifyNav.length; i++) { - if (Settings.ModifyNav[i].Label != null) { - Needed[i].children[1].innerText = Settings.ModifyNav[i].Label - Needed[i].setAttribute('href', Settings.ModifyNav[i].Link) - } - } - } - - if (Settings.HideUpgradeBtnOn && Settings.HideUpgradeBtnOn === true) { - document.querySelector('.nav-sidebar a[href="/upgrade"].nav-link.py-1.nav-sidebar-link').remove() - } - - if (Settings.IRLPriceWithCurrencyOn && Settings.IRLPriceWithCurrencyOn === true) { - var IRL; - var DISPLAY; - switch (Settings.IRLPriceWithCurrencyCurrency) { - case 0: - IRL = (Bricks.replace(/,/g, '') * 0.0099).toFixed(2) - DISPLAY = 'USD' - break - case 1: - IRL = (Bricks.replace(/,/g, '') * 0.009).toFixed(2) - DISPLAY = 'EUR' - break - case 2: - IRL = (Bricks.replace(/,/g, '') * 0.0131).toFixed(2) - DISPLAY = 'CAD' - break - case 3: - IRL = (Bricks.replace(/,/g, '') * 0.0077).toFixed(2) - DISPLAY = 'GBP' - break - case 4: - IRL = (Bricks.replace(/,/g, '') * 0.1691).toFixed(2) - DISPLAY = 'MXN' - break - case 5: - IRL = (Bricks.replace(/,/g, '') * 0.0144).toFixed(2) - DISPLAY = 'AUD' - break - case 6: - IRL = (Bricks.replace(/,/g, '') * 0.2338).toFixed(2) - DISPLAY = 'TRY' - break - } - let BrickBalanceCount = document.querySelectorAll('.brickBalanceCount,.brickBalanceCont') - BrickBalanceCount.forEach(element => { - element.innerText = element.innerText + " ($" + IRL + " " + DISPLAY + ")" - }); - } - - if (Settings.HideNotifBadgesOn && Settings.HideNotifBadgesOn === true) { - document.querySelectorAll('.notif-nav.notif-sidebar').forEach(element => {element.remove();}); - } -}); -*/ - -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/rewrites/polyplus-settings.js b/js/rewrites/polyplus-settings.js deleted file mode 100755 index f0057d2..0000000 --- a/js/rewrites/polyplus-settings.js +++ /dev/null @@ -1,883 +0,0 @@ -document.body.innerHTML = ` - - - - - - - - - - - - - -
- <- go back -

Poly+ Settings

-

[CategoryName]

-

- - Pinned Games (enabled) - - -
- Pin your favorite games to the top of the homepage! -

-

- - Forum Mentions (disabled) - - -
- Get a quick link to the popular person everyone is talking about's profile! -

-

- - Best Friends (enabled) - - -
- Prioritize the bestest of friends on applicable friend lists! -

-

- - Improved Friend Lists (enabled) - - -
- - Accept or decline all friend requests with the click of a button or multi-remove existing friends! -
- * You can only remove up to 25 friends at once. -
-

-

- - Show IRL price with Brick Count (enabled) - - -
- - See the real life currency value along with Bricks across the site! -
- * Currencies were calculated on [DATE]. -
- * Currencies other than USD are purely approximations. -
- - - -

-

- - Hide Notification Badges (disabled) - - -
- Hide the annoying red circles on the sidebar! -

-

- - Simplified Profile URLs (enabled) - - -
- Makes all profile URLs simpler by allowing for you to go to "https://polytoria.com/profile/UsernameGoesHere" to redirect to the real profile URL! -

-

- - Show "OWNED" Tag on Store Main Page (enabled) - - -
- Quickly see if you own the item at a glance with a little tag in the top left corner of item cards on the main store page! -

-

- - Theme Creator (disabled) - - - -
- Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development) -

-

- - More Search Filters (enabled) - - -
- Easily find what you're looking for with more search filters side-wide! (this does not affect the main site search on the navbar) -

-

- - Apply Membership Theme for Free (disabled) - - -
- Ever want the fancy membership themes for completely free? Well now you can get apply them site-wide! - -

- -

- - Multi-Cancel Outbound Trades (enabled) - - -
- - Quickly cancel several out-bound trades (trades that you have sent) all at once -
- * You can only cancel up to 10 trades at once. -
-

-

- - Modify Navbar (disabled) - - - -
- - Customize the navbar to your liking! - -

-

- - Item Wishlist (enabled) - - -
- - Wishlist that item that you REALLY want! - -

-

- - Hide Upgrade Button (disabled) - - -
- Hide the ugly blue "Upgrade" button on the sidebar! -

-
- - -

made by Index

-
-
-
-
-
-
-
-
-
-
-
-
-
-`; - -var Settings; -var SaveBtn = document.getElementById('Save') -var Elements = [ - document.getElementById("PinnedGames"), - document.getElementById("ForumMentions"), - document.getElementById("BestFriends"), - document.getElementById("ImprovedFriendLists"), - document.getElementById("IRLPriceWithCurrency"), - document.getElementById("HideNotifBadges"), - document.getElementById("SimplifiedProfileURLs"), - document.getElementById("StoreOwnTag"), - document.getElementById("ThemeCreator"), - document.getElementById("MoreSearchFilters"), - document.getElementById("ApplyMembershipTheme"), - document.getElementById("MultiCancelOutTrades"), - document.getElementById("ModifyNav"), - document.getElementById("ItemWishlist"), - document.getElementById("HideUpgradeBtn") -]; -var ExpectedSettings = { - PinnedGamesOn: true, - ForumMentsOn: false, - BestFriendsOn: true, - ImprovedFrListsOn: true, - IRLPriceWithCurrencyOn: true, - IRLPriceWithCurrencyCurrency: 0, - IRLPriceWithCurrencyPackage: 0, - HideNotifBadgesOn: false, - SimplifiedProfileURLsOn: true, - StoreOwnTagOn: true, - ThemeCreatorOn: false, - ThemeCreator: { - BGColor: null, - BGImage: null, - BGImageSize: 'fit', - PrimaryTextColor: null, - SecondaryTextColor: null, - LinkTextColor: null, - WebsiteLogo: null - }, - ModifyNavOn: false, - ModifyNav: [ - { - Label: "Play", - 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, - ApplyMembershipThemeOn: false, - ApplyMembershipThemeTheme: 0, - MultiCancelOutTradesOn: true, - ItemWishlistOn: true, - HideUpgradeBtnOn: false -} - -var ResetDefaultsModal = document.getElementById('ResetDefaults-Modal') -var ThemeCreatorModal = { - Modal: document.getElementById('ThemeCreator-Modal'), - Save: document.getElementById('ThemeCreator-Modal-Save'), - BGColor: document.getElementById('ThemeCreator-Modal-BGColor'), - BGImage: document.getElementById('ThemeCreator-Modal-BGImage'), - BGImageSize: document.getElementById('ThemeCreator-Modal-BGImageSize'), - PrimaryTextColor: document.getElementById('ThemeCreator-Modal-PrimaryTextColor'), - SecondaryTextColor: document.getElementById('ThemeCreator-Modal-SecondaryTextColor'), - LinkTextColor: document.getElementById('ThemeCreator-Modal-LinkTextColor'), - WebsiteLogo: document.getElementById('ThemeCreator-Modal-WebsiteLogo') -} -var ModifyNavModal = { - Modal: document.getElementById('ModifyNav-Modal'), - Save: document.getElementById('ModifyNav-Modal-Save'), - "1Label": document.getElementById('ModifyNav-Modal-1Label'), - "1Link": document.getElementById('ModifyNav-Modal-1Link'), - "2Label": document.getElementById('ModifyNav-Modal-2Label'), - "2Link": document.getElementById('ModifyNav-Modal-2Link'), - "3Label": document.getElementById('ModifyNav-Modal-3Label'), - "3Link": document.getElementById('ModifyNav-Modal-3Link'), - "4Label": document.getElementById('ModifyNav-Modal-4Label'), - "4Link": document.getElementById('ModifyNav-Modal-4Link'), - "5Label": document.getElementById('ModifyNav-Modal-5Label'), - "5Link": document.getElementById('ModifyNav-Modal-5Link'), -} -SaveBtn.addEventListener("click", function() { - Save(); -}); -Elements.forEach(element => { - let Button = element.getElementsByTagName('button')[0] - let Options = element.getElementsByTagName('button')[1] - let Select = element.getElementsByTagName('select') || [] - - if (Button) { - Button.addEventListener('click', function() { - console.log('button clicked!!!!') - ToggleSetting(Button.getAttribute('data-setting'), element) - }); - } - - if (Options) { - Options.addEventListener('click', function() { - let Modal = document.getElementById(Options.getAttribute('data-modal') + '-Modal') - let ModalButtons = Modal.getElementsByTagName('button') - let ModalInputs = Modal.getElementsByTagName('input') - let ModalSelect = Modal.getElementsByTagName('select') - - Array.from(ModalButtons).forEach(btn => { - if (!(btn.getAttribute('data-ignore') === 'true')) { - btn.addEventListener('click', function(){ - let Setting = btn.getAttribute('data-setting') - if (Setting === '[save]') { - Array.from(ModalInputs).forEach(input => { - if (!(input.getAttribute('data-ignore') === 'true')) { - if (!(input.getAttribute('data-parent'))) { - Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] = input.value || null - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] = input.value || null - } - } - }); - Array.from(ModalSelect).forEach(select => { - if (!(select.getAttribute('data-ignore') === 'true')) { - if (!(select.getAttribute('data-parent'))) { - Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] = select.selectedIndex - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] = select.selectedIndex - } - } - }); - Save(); - setTimeout(function () { - LoadCurrent(); - Modal.close(); - }, 400) - } else if (Setting === '[cancel]') { - Modal.close(); - } else if (Setting === '[callback]') { - let Function = btn.getAttribute('data-onclick') - if (window[Function] && typeof(window[Function]) === 'function') { - console.log('is') - window[Function]() - } - } else { - if (!(btn.getAttribute('data-parent'))) { - ToggleSetting(Modal.getAttribute('data-setting')[btn.getAttribute('data-setting')], null) - } else { - let Parent = input.getAttribute('data-parent') - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - ToggleSetting(Modal.getAttribute('data-setting')[Parent][btn.getAttribute('data-setting')], null) - } - } - }); - } - }); - - Array.from(ModalInputs).forEach(input => { - if (!(input.getAttribute('data-ignore') === 'true')) { - if (!(input.getAttribute('data-parent'))) { - if (Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] !== "undefined") { - input.value = Settings[Modal.getAttribute('data-setting')][input.getAttribute('data-setting')] - } - } else { - let Parent = input.getAttribute('data-parent') - if (Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] !== "undefined") { - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - input.value = Settings[Modal.getAttribute('data-setting')][Parent][input.getAttribute('data-setting')] - } - } - } - }); - - Array.from(ModalSelect).forEach(select => { - if (!(select.getAttribute('data-ignore') === 'true')) { - if (!(select.getAttribute('data-parent'))) { - if (Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] !== "undefined") { - select.selectedIndex = Settings[Modal.getAttribute('data-setting')][select.getAttribute('data-setting')] - } - } else { - let Parent = input.getAttribute('data-parent') - if (Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] !== "undefined") { - if (!isNaN(parseInt(Parent))) {Parent = parseInt(Parent)} - select.selectedIndex = Settings[Modal.getAttribute('data-setting')][Parent][select.getAttribute('data-setting')] - } - } - } - }); - - Modal.showModal() - }); - } - - if (Select.length > 0) { - Array.from(Select).forEach(element => { - element.addEventListener('change', function() { - SetSetting(element.getAttribute('data-setting'), element, element.selectedIndex) - }); - }); - } -}); -document.getElementById('ResetDefaults').addEventListener('click', function() { - ResetDefaultsModal.showModal(); -}); -document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function() { - Settings = ExpectedSettings - Save() - setTimeout(function () { - LoadCurrent(); - ResetDefaultsModal.close(); - }, 400) -}); -document.getElementById('ResetDefaults-Modal-No').addEventListener('click', function() { - ResetDefaultsModal.close(); -}); - -function LoadCurrent() { - chrome.storage.sync.get(["PolyPlus_Settings"], function(result) { - Settings = MergeObjects(result.PolyPlus_Settings || ExpectedSettings, ExpectedSettings) - - console.log(Settings) - - Elements.forEach(element => { - let Status = element.getElementsByClassName('status')[0] - console.log(element, FormatBool(Settings[element.getElementsByTagName('button')[0].getAttribute('data-setting')])) - Status.innerText = FormatBool(Settings[element.getElementsByTagName('button')[0].getAttribute('data-setting')]) - let SelectInput = element.getElementsByTagName('select')[0] - if (SelectInput) { - SelectInput.selectedIndex = Settings[SelectInput.getAttribute('data-setting')] - } - }); - }); -} -LoadCurrent(); - -function ToggleSetting(Name, Element) { - if (Settings[Name] === true) { - Settings[Name] = false; - } else { - Settings[Name] = true; - } - - if (Element != null) { - Element.getElementsByClassName('status')[0].innerText = FormatBool(Settings[Name]) - } - if (SaveBtn.getAttribute('disabled')) { - SaveBtn.removeAttribute('disabled') - } -} - -function SetSetting(Name, Element, Value) { - console.log(Settings) - Settings[Name] = Value - - if (SaveBtn.getAttribute('disabled')) { - SaveBtn.removeAttribute('disabled') - } -} - -function Save() { - SaveBtn.setAttribute('disabled', 'true') - chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() { - console.log('Saved successfully!'); - }); - - console.log(Settings); -} - -let LoadThemeFromJSONBtn = document.getElementById('LoadThemeFromJSONBtn') -let SaveThemeToJSONInput = document.getElementById('SaveThemeToJSONInput') -let CopyThemeJSONBtn = document.getElementById('CopyThemeJSONBtn') -LoadThemeFromJSONBtn.addEventListener('click', function(){ - LoadThemeJSON(LoadThemeFromJSONBtn.previousElementSibling.value) -}); -document.getElementById('ThemeCreator').getElementsByTagName('button')[1].addEventListener('click', function(){ - SaveThemeToJSONInput.value = JSON.stringify(Settings.ThemeCreator) -}); -CopyThemeJSONBtn.addEventListener('click', function(){ - if (SaveThemeToJSONInput.value.length > 0) { - navigator.clipboard.writeText(SaveThemeToJSONInput.value) - } -}); - -let CurrencyDate = -LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){ - CurrencyDate = new Date(JSON.parse(text).Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"}) - - document.getElementById('IRLPriceWithCurrencyCurrency').previousElementSibling.children[1].innerText = document.getElementById('IRLPriceWithCurrencyCurrency').previousElementSibling.children[1].innerText.replace('[DATE]', CurrencyDate) -}) - -function LoadThemeJSON(string) { - try { - let JSONTable = JSON.parse(string) - if (JSONTable.length === ExpectedSettings.ThemeCreator.length) { - if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) { - LoadThemeFromJSONBtn.previousElementSibling.value = '' - document.getElementById('ThemeCreator-Modal').close() - Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator) - Save(); - console.log(JSONTable.length, JSONTable, 'applied') - document.getElementById('ThemeCreator').getElementsByTagName('button')[1].click(); - } - } else { - alert('JSON is not a theme!') - //LoadThemeFromJSONBtn.innerText = 'JSON is too short or too long!' - //setTimeout(function () {LoadThemeFromJSONBtn.innerText = 'Load'}, 1250) - } - } catch (error) { - alert('JSON is invalid!') - //LoadThemeFromJSONBtn.innerText = 'JSON is invalid!' - //setTimeout(function () {LoadThemeFromJSONBtn.innerText = 'Load'}, 1250) - } -} - -/* -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]; - } else if (obj1[key] !== obj2[key]) { - mergedObj[key] = obj2[key]; - } - } - - // Remove keys from mergedObj if they are not present in obj2 - for (var key in mergedObj) { - if (!obj2.hasOwnProperty(key)) { - delete mergedObj[key]; - } - } - - return mergedObj; -} -*/ - -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; -} - -function FormatBool(bool){ - if (bool === true) { - return 'enabled' - } else { - return 'disabled' - } -} - -function LoadFile(path, callback) { - var xhr = new XMLHttpRequest(); - xhr.onload = function () { return callback(this.responseText); } - xhr.open("GET", path, true); - xhr.send(); -} \ No newline at end of file diff --git a/js/store/item-view.js b/js/store/item-view.js index 1da702f..37c1885 100755 --- a/js/store/item-view.js +++ b/js/store/item-view.js @@ -1,139 +1,148 @@ -var ItemID = window.location.pathname.split('/')[2] +const ItemID = window.location.pathname.split('/')[2] + var ItemWishlist; +var PurchaseBtn; var WishlistBtn; setTimeout(function () { if (!(window.location.href.split('/')[4])) {return} chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ - var Settings = result.PolyPlus_Settings; - let PurchaseBtn = document.querySelector('.btn.btn-outline-success') - if (Settings.IRLPriceWithCurrencyOn === true){ - if (!(PurchaseBtn.getAttribute('disabled'))) { - let Price = PurchaseBtn.getAttribute('data-price').replace(/,/g, '') - let Span = document.createElement('span') - Span.classList = 'text-muted polyplus-own-tag' - Span.style.fontSize = '0.7rem' - Span.style.fontWeight = 'normal' - let IRL; - let DISPLAY; - switch (Settings.IRLPriceWithCurrencyCurrency) { - case 0: - IRL = (Price * 0.0099).toFixed(2) - DISPLAY = 'USD' - break - case 1: - IRL = (Price * 0.009).toFixed(2) - DISPLAY = 'EUR' - break - case 2: - IRL = (Price * 0.0131).toFixed(2) - DISPLAY = 'CAD' - break - case 3: - IRL = (Price * 0.0077).toFixed(2) - DISPLAY = 'GBP' - break - case 4: - IRL = (Price * 0.1691).toFixed(2) - DISPLAY = 'MXN' - break - case 5: - IRL = (Price * 0.0144).toFixed(2) - DISPLAY = 'AUD' - break - case 6: - IRL = (Price * 0.2338).toFixed(2) - DISPLAY = 'TRY' - break - } - Span.innerText = "($" + IRL + " " + DISPLAY + ")" - PurchaseBtn.appendChild(Span) - } + var Settings = result.PolyPlus_Settings || { + IRLPriceWithCurrencyOn: false, + IRLPriceWithCurrencyCurrency: 0, + ItemWishlistOn: true } + PurchaseBtn = document.getElementsByClassName('btn btn-outline-success')[0] + + if (Settings.IRLPriceWithCurrencyOn === true){ IRLPrice() } if (Settings.ItemWishlistOn === true && !(PurchaseBtn.getAttribute('disabled'))) { - let DescriptionText = document.querySelector('.card-text') - WishlistBtn = document.createElement('button') - chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ - ItemWishlist = result.PolyPlus_ItemWishlist || []; - - if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) { - WishlistBtn.classList = 'btn btn-danger btn-sm' - WishlistBtn.innerHTML = ` - Un-Wishlist Item - ` - } else { - WishlistBtn.classList = 'btn btn-primary btn-sm' - WishlistBtn.innerHTML = ` - Wishlist Item - ` - } - - WishlistBtn.addEventListener('click', function(){ - Wishlist() - }); - - DescriptionText.appendChild(document.createElement('br')) - DescriptionText.appendChild(WishlistBtn) - - function Wishlist() { - WishlistBtn.setAttribute('disabled', true) - chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ - ItemWishlist = result.PolyPlus_ItemWishlist || []; - - let i = ItemWishlist.indexOf(parseInt(ItemID)) - console.log(i) - if (i !== -1) { - ItemWishlist.splice(i, 1) - WishlistBtn.classList = 'btn btn-primary btn-sm' - WishlistBtn.innerHTML = ` - Wishlist Item - ` - } else { - ItemWishlist.push(parseInt(ItemID)) - WishlistBtn.classList = 'btn btn-danger btn-sm' - WishlistBtn.innerHTML = ` - Un-Wishlist Item - ` - } - - chrome.storage.sync.set({'PolyPlus_ItemWishlist': ItemWishlist, arrayOrder: true}, function() { - setTimeout(function() { - WishlistBtn.removeAttribute('disabled') - }, 1250) - }); - }); - } - }); + HandleItemWishlist() } }) }, 100) chrome.storage.onChanged.addListener(function(changes, namespace) { if ('PolyPlus_ItemWishlist' in changes) { - chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result) { - ItemWishlist = result.PolyPlus_ItemWishlist || []; + chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result) { + ItemWishlist = result.PolyPlus_ItemWishlist || []; - if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) { - WishlistBtn.classList = 'btn btn-danger btn-sm' - WishlistBtn.innerHTML = ` - Un-Wishlist Item - ` - } else { - if (!(ItemWishlist.length === 25)) { - WishlistBtn.removeAttribute('disabled') - WishlistBtn.classList = 'btn btn-primary btn-sm' - WishlistBtn.innerHTML = ` - Wishlist Item - ` - } else { - WishlistBtn.setAttribute('disabled', true) - WishlistBtn.classList = 'btn btn-primary btn-sm' - WishlistBtn.innerHTML = ` - Wishlist Item - ` - } - } - }); + if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) { + WishlistBtn.classList = 'btn btn-danger btn-sm' + WishlistBtn.innerHTML = ` + Un-Wishlist Item + ` + } else { + if (!(ItemWishlist.length === 25)) { + WishlistBtn.removeAttribute('disabled') + WishlistBtn.classList = 'btn btn-primary btn-sm' + WishlistBtn.innerHTML = ` + Wishlist Item + ` + } else { + WishlistBtn.setAttribute('disabled', true) + WishlistBtn.classList = 'btn btn-primary btn-sm' + WishlistBtn.innerHTML = ` + Wishlist Item + ` + } + } + }); } -}); \ No newline at end of file +}); + +function IRLPrice() { + if (!(PurchaseBtn.getAttribute('disabled'))) { + let Price = PurchaseBtn.getAttribute('data-price').replace(/,/g, '') + let Span = document.createElement('span') + Span.classList = 'text-muted polyplus-own-tag' + Span.style.fontSize = '0.7rem' + Span.style.fontWeight = 'normal' + let IRL; + let DISPLAY; + switch (Settings.IRLPriceWithCurrencyCurrency) { + case 0: + IRL = (Price * 0.0099).toFixed(2) + DISPLAY = 'USD' + break + case 1: + IRL = (Price * 0.009).toFixed(2) + DISPLAY = 'EUR' + break + case 2: + IRL = (Price * 0.0131).toFixed(2) + DISPLAY = 'CAD' + break + case 3: + IRL = (Price * 0.0077).toFixed(2) + DISPLAY = 'GBP' + break + case 4: + IRL = (Price * 0.1691).toFixed(2) + DISPLAY = 'MXN' + break + case 5: + IRL = (Price * 0.0144).toFixed(2) + DISPLAY = 'AUD' + break + case 6: + IRL = (Price * 0.2338).toFixed(2) + DISPLAY = 'TRY' + break + } + Span.innerText = "($" + IRL + " " + DISPLAY + ")" + PurchaseBtn.appendChild(Span) + } +} + +function HandleItemWishlist() { + const DescriptionText = document.getElementsByClassName('card-text')[0] + WishlistBtn = document.createElement('button') + chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ + ItemWishlist = result.PolyPlus_ItemWishlist || []; + + if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) { + WishlistBtn.classList = 'btn btn-danger btn-sm' + WishlistBtn.innerHTML = ` + Un-Wishlist Item + ` + } else { + WishlistBtn.classList = 'btn btn-primary btn-sm' + WishlistBtn.innerHTML = ` + Wishlist Item + ` + } + + WishlistBtn.addEventListener('click', function(){ + WishlistBtn.setAttribute('disabled', true) + chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ + ItemWishlist = result.PolyPlus_ItemWishlist || []; + + let i = ItemWishlist.indexOf(parseInt(ItemID)) + console.log(i) + if (i !== -1) { + ItemWishlist.splice(i, 1) + WishlistBtn.classList = 'btn btn-primary btn-sm' + WishlistBtn.innerHTML = ` + Wishlist Item + ` + } else { + ItemWishlist.push(parseInt(ItemID)) + WishlistBtn.classList = 'btn btn-danger btn-sm' + WishlistBtn.innerHTML = ` + Un-Wishlist Item + ` + } + + chrome.storage.sync.set({'PolyPlus_ItemWishlist': ItemWishlist, arrayOrder: true}, function() { + setTimeout(function() { + WishlistBtn.removeAttribute('disabled') + }, 1250) + }); + }); + }); + + DescriptionText.appendChild(document.createElement('br')) + DescriptionText.appendChild(WishlistBtn) + }); +} \ No newline at end of file diff --git a/js/trick-or-treat.js b/js/trick-or-treat.js deleted file mode 100755 index 9d6620e..0000000 --- a/js/trick-or-treat.js +++ /dev/null @@ -1,13 +0,0 @@ -// This was for the limited time 2023 halloween event -const HauntedStudsCount = document.querySelector('[href="/event/active"] .brickBalanceCount') -if (HauntedStudsCount !== null) { - HauntedStudsCount.innerHTML = HauntedStudsCount.innerHTML + ` (${parseInt(HauntedStudsCount.innerText) / 8} candies)` -} - -if (window.location.pathname === '/event/trick-o-toria-2023') { - const LeaderboardRows = document.getElementsByClassName('leaderboard-row') - Array.from(LeaderboardRows).forEach(row => { - const _HauntedStudsCount = row.querySelector('span[style^="color:#cd60ff;"]') - _HauntedStudsCount.innerHTML = _HauntedStudsCount.innerHTML + `
(${parseFloat(_HauntedStudsCount.innerText.replace(/,/g, '')) / 8} candies)` - }); -} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 0f9065f..f225ca9 100755 --- a/manifest.json +++ b/manifest.json @@ -32,7 +32,7 @@ { "matches": ["https://polytoria.com/places/**"], - "js": ["/js/places/place-view.js"] + "js": ["/js/places/place-view2.js"] }, { @@ -126,17 +126,7 @@ ], "web_accessible_resources": [ { - "resources": ["js/resources/currencies.json", "settings.html", "settings.js"], - "matches": ["https://polytoria.com/*"] - }, - - { - "resources": ["js/utils.js"], - "matches": ["https://polytoria.com/*"] - }, - - { - "resources": ["js/account/avatar-sandbox.html"], + "resources": ["js/resources/*"], "matches": ["https://polytoria.com/*"] } ], diff --git a/settings.html b/settings.html index bebb345..00a99f4 100755 --- a/settings.html +++ b/settings.html @@ -1,7 +1,7 @@ Poly+ Settings - +