diff --git a/Generate-UnitPrices.js b/Generate-UnitPrices.js new file mode 100755 index 0000000..55219ce --- /dev/null +++ b/Generate-UnitPrices.js @@ -0,0 +1,97 @@ +let CurrencyNames = [ + "USD", + "EUR", + "CAD", + "GBP", + "MXN", + "AUD", + "TRY" +] + +let Divides = [ + 100, + 550, + 1150, + 2750, + 6000, + 12500 +] + +let Currencies = [ + [ + 0.99, // USD + 1.12, // EUR + 1.23, // CAD + 0.81, // GBP + 19.28, // MXN + 1.42, // AUD + 15.83, // TRY + ], + + [ + 4.99, // USD + 5.59, // EUR + 6.21, // CAD + 4.05, // GBP + 96.44, // MXN + 7.38, // AUD + 80.39, // TRY + ], + + [ + 9.99, // USD + 11.18, // EUR + 12.34, // CAD + 8.10, // GBP + 192.80, // MXN + 14.76, // AUD + 158.33, // TRY + ], + + [ + 24.99, // USD + 27.39, // EUR + 29.22, // CAD + 19.20, // GBP + 475.60, // MXN + 34.92, // AUD + 396.66, // TRY + ], + + [ + 49.99, // USD + 55.94, // EUR + 58.44, // CAD + 36.40, // GBP + 951.20, // MXN + 73.84, // AUD + 793.32, // TRY + ], + + [ + 99.99, // USD + 111.88, // EUR + 116.88, // CAD + 72.80, // GBP + 1902.40, // MXN + 147.68, // AUD + 1586.64, // TRY + ] +] + +let UnitPrices = [ + {}, + {}, + {}, + {}, + {}, + {} +] + +Currencies.forEach((_value, _index) => { + Currencies[_index].forEach((value, index) => { + UnitPrices[_index][CurrencyNames[index]] = (value / Divides[_index]) + }) +}); + +console.log(JSON.stringify(UnitPrices)) \ No newline at end of file diff --git a/css/popup.css b/css/popup.css new file mode 100755 index 0000000..6e5f26a --- /dev/null +++ b/css/popup.css @@ -0,0 +1,60 @@ +@font-face { + font-family: LexendRegular; + src: url('Lexend-Regular.ttf'); +} + +@font-face { + font-family: LexendLight; + src: url('Lexend-Light.ttf'); +} + +@font-face { + font-family: LexendBold; + src: url('Lexend-Bold.ttf'); +} + +@font-face { + font-family: LexendBlack; + src: url('Lexend-Black.ttf'); +} + +body { + margin: 0; + padding: 12px; + font-family: LexendRegular; + background-color: #242424; + color: white; +} + +.button { + border-radius: 20px; + background-color: #fff; + color: #424242; + width: 95%; + padding: 10px; + border: none; + font-weight: bold; + text-decoration: none; +} + +input { + border-radius: 20px; + background-color: #fff; + color: #007bff; + width: 95%; + padding: 10px; + border: none; + font-weight: bold; +} + +h1,.h1 { + font-family: LexendBlack; +} + +h2,.h2 { + font-family: LexendBold; +} + +hr { + border-color: transparent; +} \ No newline at end of file diff --git a/css/specific.css b/css/specific.css new file mode 100755 index 0000000..963f529 --- /dev/null +++ b/css/specific.css @@ -0,0 +1,17 @@ +body[data-URL^="https://polytoria.com/my/friends"] .col-lg-3 { + margin-bottom: 20px; +} + +body[data-URL^="https://polytoria.com/create/"] .mt-2.mt-lg-0.col-lg.d-flex.align-content-between.flex-wrap { + width: 50%; +} + +body[data-URL^="https://polytoria.com/create/"] .col.d-flex.align-content-between.flex-wrap { + width: 50%; +} + +.text-truncate { + white-space: nowrap !important; /* Prevents text from wrapping to the next line */ + overflow: hidden !important; /* Hides the overflowing text */ + text-overflow: ellipsis !important; /* Adds an ellipsis (...) to indicate truncated text */ +} \ No newline at end of file diff --git a/data_structure.txt b/data_structure.txt new file mode 100755 index 0000000..9a6abb9 --- /dev/null +++ b/data_structure.txt @@ -0,0 +1,4 @@ +PolyPlus_Settings: [] +PolyPlus_PinnedGames: [] +PolyPlus_BestFriends: [] +PolyPlus_ItemWishlist: [] \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100755 index 0000000..1315998 Binary files /dev/null and b/icon.png differ diff --git a/installation.html b/installation.html new file mode 100755 index 0000000..36b8464 --- /dev/null +++ b/installation.html @@ -0,0 +1,8 @@ + + + Poly+ + + +

Thank you for installing Poly+!

+ + \ No newline at end of file diff --git a/js/account/avatar-sandbox.html b/js/account/avatar-sandbox.html new file mode 100755 index 0000000..2a3569c --- /dev/null +++ b/js/account/avatar-sandbox.html @@ -0,0 +1,129 @@ + +
+
+
+
+ + Avatar +
+
+ +
+ + + + + + + + + +
+
+
+
+
+ +
+
+ +
+
+
+
+ + Body Colors +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ +
+ +
+
+
Wearing
+
+
+
+
+
\ No newline at end of file diff --git a/js/account/avatar-sandbox.js b/js/account/avatar-sandbox.js new file mode 100755 index 0000000..42ec484 --- /dev/null +++ b/js/account/avatar-sandbox.js @@ -0,0 +1,372 @@ +let PageContainer = document.querySelector('.container.p-0.p-lg-5') +let ItemGrid; +let Wearing; +let Tabs; +let IFrame; +let TabSelected = 'hat' +let Search; +let Page = 1 +let Avatar = { + "useCharacter": true, + "items": [], + "shirt": null, + "pants": null, + "tool": {ID: -1, URL: null}, + "headColor": "#e0e0e0", + "torsoColor": "#e0e0e0", + "leftArmColor": "#e0e0e0", + "rightArmColor": "#e0e0e0", + "leftLegColor": "#e0e0e0", + "rightLegColor": "#e0e0e0" +} +let ItemCardContents = ` +
+
+
+ + + :ItemType + + +
+
+ +
:ItemName
+
+ + by :CreatorName + +
+` + +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){ + PageContainer.innerHTML = html + ItemGrid = document.getElementById('inventory') + Wearing = document.getElementById('wearing') + Tabs = document.getElementById('tabs') + IFrame = document.getElementById('viewFrame') + + Search = document.getElementById('item-search') + Search.addEventListener('change', function(){ + RefreshItems() + }); + + UpdateAvatar() + RefreshItems() + + Array.from(Tabs.children).forEach(element => { + element.addEventListener('click', function(){ + let Link = element.getElementsByTagName('a')[0] + if (!(Link.classList.contains('active'))) { + Link.classList.add('active') + Tabs.querySelector(`[data-tab="${TabSelected}"]`).classList.remove('active') + TabSelected = Link.getAttribute('data-tab') + Page = 1 + RefreshItems() + } + }); + }); + + let Clear = document.getElementById('clear') + Clear.addEventListener('click', function(){ + Avatar = { + "useCharacter": true, + "items": [], + "shirt": {ID: -1, URL: null}, + "pants": {ID: -1, URL: null}, + "tool": {ID: -1, URL: null}, + "headColor": "#e0e0e0", + "torsoColor": "#e0e0e0", + "leftArmColor": "#e0e0e0", + "rightArmColor": "#e0e0e0", + "leftLegColor": "#e0e0e0", + "rightLegColor": "#e0e0e0" + } + UpdateAvatar() + }); + + let JSONUpload = document.getElementById('jsonUpload') + JSONUpload.addEventListener('change', function(){ + let Reader = new FileReader() + Reader.addEventListener('loadend', function(){ + Avatar = JSON.parse(Reader.result) + UpdateAvatar() + + JSONUpload.value = "" + }); + + Reader.readAsText(JSONUpload.files[0]) + }); + + let JSONSave = document.getElementById('jsonSave') + JSONSave.addEventListener('click', function(){ + FormatAvatar().then(FormattedAvatar => { + let Download = document.createElement('a') + Download.href = URL.createObjectURL(new Blob([JSON.stringify(FormattedAvatar)], { + type: "application/json" + })); + Download.setAttribute('download', 'AvatarSandbox.json') + document.body.appendChild(Download) + Download.click() + document.body.removeChild(Download) + }); + }); + + let OpenInNewTab = document.getElementById('openNewTab') + OpenInNewTab.addEventListener('click', function(){ + UpdateAvatar() + }); + }); +} + +function UpdateAvatar() { + GenerateHash() + .then(hash => { + IFrame.addEventListener('load', function () { + IFrame.src = 'https://polytoria.com/ptstatic/itemview/#' + hash; + }); + IFrame.src = 'about:blank'; + }); +} + +function LoadFile(path, callback) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { return callback(this.responseText); } + xhr.open("GET", path, true); + xhr.send(); +} + +async function GenerateHash() { + let FormattedAvatar = await FormatAvatar() + for (let i = 0; i < FormattedAvatar.items.length; i++) { + FormattedAvatar.items[i] = FormattedAvatar.items[i].URL + } + if (FormattedAvatar.shirt) { + FormattedAvatar.shirt = FormattedAvatar.shirt.URL + } + if (FormattedAvatar.pants) { + FormattedAvatar.pants = FormattedAvatar.pants.URL + } + FormattedAvatar.face = FormattedAvatar.face.URL + if (FormattedAvatar.tool) { + FormattedAvatar.tool = FormattedAvatar.tool.URL + } + console.log('Formatted Avatar: ', FormattedAvatar) + console.log('Real Avatar: ', Avatar) + return btoa(encodeURIComponent(JSON.stringify(FormattedAvatar))) +} + +async function FormatAvatar() { + let LocalAvatar = structuredClone(Avatar) + + if (!LocalAvatar.face) { + LocalAvatar.face = {ID: -1, URL: "https://c0.ptacdn.com/static/3dview/DefaultFace.png"} + } + + for (let i = 0; i < LocalAvatar.items.length; i++) { + if (LocalAvatar.items[i].URL === null) { + await fetch("https://api.polytoria.com/v1/assets/serve-mesh/:id".replace(':id', LocalAvatar.items[i].ID)) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Avatar.items[i].URL = data.url + LocalAvatar.items[i].URL = data.url + }) + .catch(error => { + console.error('Fetch error:', error); + }); + } + } + + if (LocalAvatar.tool && LocalAvatar.tool.ID !== -1 && LocalAvatar.tool.URL === null) { + await fetch("https://api.polytoria.com/v1/assets/serve-mesh/:id".replace(':id', LocalAvatar.tool.ID)) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Avatar.tool.URL = data.url + LocalAvatar.tool.URL = data.url + }) + .catch(error => { + console.error('Fetch error:', error); + }); + } + + if (LocalAvatar.face.ID !== -1 && LocalAvatar.face.URL === null) { + await fetch("https://api.polytoria.com/v1/assets/serve/:id/Asset".replace(':id', LocalAvatar.face.ID)) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Avatar.face.URL = data.url + LocalAvatar.face.URL = data.url + }) + .catch(error => { + console.error('Fetch error:', error); + }); + } + + if (LocalAvatar.shirt && LocalAvatar.shirt.ID !== -1 && LocalAvatar.shirt.URL === null) { + await fetch("https://api.polytoria.com/v1/assets/serve/:id/Asset".replace(':id', LocalAvatar.shirt.ID)) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Avatar.shirt.URL = data.url + LocalAvatar.shirt.URL = data.url + }) + .catch(error => { + console.error('Fetch error:', error); + }); + } + + if (LocalAvatar.pants && LocalAvatar.pants.ID !== -1 && LocalAvatar.pants.URL === null) { + await fetch("https://api.polytoria.com/v1/assets/serve/:id/Asset".replace(':id', LocalAvatar.pants.ID)) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Avatar.pants.URL = data.url + LocalAvatar.pants.URL = data.url + }) + .catch(error => { + console.error('Fetch error:', error); + }); + } + + return LocalAvatar +} + +function RefreshItems() { + fetch(`https://api.polytoria.com/v1/store?search=${Search.value}&types%5B%5D=${TabSelected}&sort=createdAt&order=desc&page=${Page}&limit=12`) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Array.from(ItemGrid.children).forEach(element => {element.remove()}); + data = data.assets + data.forEach(item => { + let NewItemCard = document.createElement('div') + NewItemCard.classList = 'col-auto' + NewItemCard.innerHTML = ItemCardContents.replace(':ItemName', item.name).replace().replace(':ItemID', item.id).replace(':ItemType', item.type.replace(item.type.charAt(0), item.type.charAt(0).toUpperCase())).replace(':CreatorName', item.creator.name).replace(':CreatorID', item.creator.id).replace(':ItemThumbnail', item.thumbnail) + NewItemCard.getElementsByClassName('p-2')[0].addEventListener('click', function(){ + WearAsset(NewItemCard, item.name, {Name: item.creator.name, ID: item.creator.id}, item.id, item.type, item.thumbnail) + }); + + ItemGrid.appendChild(NewItemCard) + }); + }) + .catch(error => { + console.error('Fetch error:', error); + }); +} + +function WearAsset(element, name, creator, id, type, thumbnail) { + switch (type) { + case 'hat': + let Index = CheckItemID(Avatar.items, id) + if (Index === -1) { + if (Avatar.items.length !== 3) { + Avatar.items.push({Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail}) + Wearing.prepend(ItemGrid.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } else { + Avatar.items.splice(0, 1) + Avatar.items.push({Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail}) + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + } else { + console.log('remove') + Avatar.items.splice(Index, 1) + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + break + case 'face': + if (Avatar.face && Avatar.face.ID !== id) { + Avatar.face = {Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail} + Wearing.prepend(ItemGrid.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } else { + Avatar.face = {Name: "Default Face", Creator: {Name: "Polytoria", ID: 1}, ID: -1, URL: "https://c0.ptacdn.com/static/3dview/DefaultFace.png", Thumbnail: "https://c0.ptacdn.com/static/3dview/DefaultFace.png"} + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + break + case 'tool': + if (Avatar.tool && Avatar.tool.ID !== id) { + Avatar.tool = {Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail} + Wearing.prepend(ItemGrid.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } else { + Avatar.tool = null + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + break + case 'shirt': + if (Avatar.shirt.ID !== id) { + Avatar.shirt = {Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail} + Wearing.prepend(ItemGrid.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } else { + Avatar.shirt = null + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + break + case 'pants': + if (Avatar.pants.ID !== id) { + Avatar.pants = {Name: name, Creator: creator, ID: id, URL: null, Thumbnail: thumbnail} + Wearing.prepend(ItemGrid.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } else { + Avatar.pants = null + if (TabSelected === type) { + console.log('tab is', TabSelected, type) + ItemGrid.prepend(Wearing.querySelector(`.col-auto:has(a[href="/store/${id}"])`)) + } + } + break + } + + UpdateAvatar() +} + +function CheckItemID(object, id) { + for (let i = 0; i < object.length; i++) { + if (object[i] === id || object[i].ID === id) { + console.log('Index: ' + i) + return i + } + } + return -1 +} \ No newline at end of file diff --git a/js/account/avatar-sandbox2.js b/js/account/avatar-sandbox2.js new file mode 100755 index 0000000..ebad5e6 --- /dev/null +++ b/js/account/avatar-sandbox2.js @@ -0,0 +1,456 @@ +setTimeout(function () {}, 100) +const UserID = JSON.parse(window.localStorage.getItem('account_info')).ID + +let PageContainer = document.querySelector('.container.p-0.p-lg-5') +let ItemGrid; +let Wearing; +let Tabs; +let IFrame; +let TabSelected = 'hat' +let Search; +let Page = 1 +let Avatar = { + "useCharacter": true, + "items": [ + 24122 + ], + "shirt": 24118, + "pants": 24123, + "headColor": "#e0e0e0", + "torsoColor": "#e0e0e0", + "leftArmColor": "#e0e0e0", + "rightArmColor": "#e0e0e0", + "leftLegColor": "#e0e0e0", + "rightLegColor": "#e0e0e0" +} +let ItemCardContents = ` +
+
+
+ + + :ItemType + + +
+
+ +
:ItemName
+
+ + by :CreatorName + +
+` + +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){ + PageContainer.innerHTML = html + ItemGrid = document.getElementById('inventory') + Wearing = document.getElementById('wearing') + Tabs = document.getElementById('tabs') + IFrame = document.getElementById('viewFrame') + + Search = document.getElementById('item-search') + Search.addEventListener('onchange', function(){ + RefreshItems() + }); + + UpdateAvatar() + RefreshItems() + LoadWearing() + + Array.from(Tabs.children).forEach(element => { + element.addEventListener('click', function(){ + let Link = element.getElementsByTagName('a')[0] + if (!(Link.classList.contains('active'))) { + Link.classList.add('active') + Tabs.querySelector(`[data-tab="${TabSelected}"]`).classList.remove('active') + TabSelected = Link.getAttribute('data-tab') + Page = 1 + RefreshItems() + } + }); + }); + + let Clear = document.getElementById('clear') + Clear.addEventListener('click', function(){ + Avatar = { + "useCharacter": true, + "items": [ + 24122 + ], + "shirt": 24118, + "pants": 24123, + "headColor": "#e0e0e0", + "torsoColor": "#e0e0e0", + "leftArmColor": "#e0e0e0", + "rightArmColor": "#e0e0e0", + "leftLegColor": "#e0e0e0", + "rightLegColor": "#e0e0e0" + } + UpdateAvatar() + }); + + let Myself = document.getElementById('myself') + Myself.addEventListener('click', function(){ + LoadMyself() + }); + + let JSONUpload = document.getElementById('jsonUpload') + JSONUpload.addEventListener('change', function(){ + let Reader = new FileReader() + Reader.addEventListener('loadend', function(){ + Avatar = JSON.parse(Reader.result) + UpdateAvatar() + + JSONUpload.value = "" + }); + + Reader.readAsText(JSONUpload.files[0]) + }); + + let JSONSave = document.getElementById('jsonSave') + JSONSave.addEventListener('click', function(){ + let Download = document.createElement('a') + Download.href = URL.createObjectURL(new Blob([JSON.stringify(Avatar)], { + type: "application/json" + })); + Download.setAttribute('download', 'AvatarSandbox.json') + document.body.appendChild(Download) + Download.click() + document.body.removeChild(Download) + }); + + let OpenInNewTab = document.getElementById('openNewTab') + OpenInNewTab.addEventListener('click', function(){ + UpdateAvatar() + }); + }); +} + +function UpdateAvatar() { + GenerateHash() + .then(hash => { + IFrame.addEventListener('load', function () { + IFrame.src = 'https://polytoria.com/ptstatic/itemview/#' + hash; + }); + IFrame.src = 'about:blank'; + }); +} + +function LoadFile(path, callback) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { return callback(this.responseText); } + xhr.open("GET", path, true); + xhr.send(); +} + +async function GenerateHash(data) { + if (!data) { + console.log('Data not provided') + let FormattedAvatar = await FormatAvatar() + return btoa(encodeURIComponent(JSON.stringify(FormattedAvatar))) + } else { + console.log('Data provided') + return btoa(encodeURIComponent(JSON.stringify(data))) + } +} + +function RefreshItems() { + fetch(`https://api.polytoria.com/v1/store?search=${Search.value}&types%5B%5D=${TabSelected}&sort=createdAt&order=desc&page=${Page}&limit=12`) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + Array.from(ItemGrid.children).forEach(element => {element.remove()}); + data = data.assets + data.forEach(item => { + let NewItemCard = document.createElement('div') + NewItemCard.classList = 'col-auto' + NewItemCard.innerHTML = ItemCardContents + .replace(':ItemName', item.name) + .replace(':ItemID', item.id) + .replace(':ItemType', item.type) + .replace(item.type.charAt(0), item.type.charAt(0).toUpperCase()) + .replace(':CreatorName', item.creator.name) + .replace(':CreatorID', item.creator.id) + .replace(':ItemThumbnail', item.thumbnail) + NewItemCard.getElementsByClassName('p-2')[0].addEventListener('click', function(){ + WearAsset(NewItemCard, item) + }); + + ItemGrid.appendChild(NewItemCard) + }); + }) + .catch(error => { + console.error('Fetch error:', error); + }); +} + +async function FormatAvatar() { + const FormattedAvatar = structuredClone(Avatar) + + // Hats, Tools: https://api.polytoria.com/v1/assets/serve-mesh/:id + // or: https://api.polytoria.com/v1/assets/serve/:id/Asset + + Avatar.items.forEach(async (item, index) => { + if (typeof(item) === 'number') { + console.log(item) + await FetchMesh(item) + .then(URL => { + console.log('URL: ' + URL) + FormattedAvatar.items[index] = URL + }) + .catch(error => { + throw new Error(error) + }); + console.log('after url') + //Avatar.items[index] = URL + } + }); + + if (typeof(FormattedAvatar.tool) === 'number') {console.log(FormattedAvatar.tool); FormattedAvatar.tool = await FetchMesh(FormattedAvatar.tool)} + + if (FormattedAvatar.face && typeof(FormattedAvatar.face) === 'number') { + FormattedAvatar.face = await FetchAsset(FormattedAvatar.face) + } else { + FormattedAvatar.face = "https://c0.ptacdn.com/static/3dview/DefaultFace.png" + } + + if (typeof(FormattedAvatar.shirt) === 'number') {FormattedAvatar.shirt = await FetchAsset(FormattedAvatar.shirt)} + if (typeof(FormattedAvatar.pants) === 'number') {FormattedAvatar.pants = await FetchAsset(FormattedAvatar.pants)} + + console.log('Real Avatar: ', Avatar, 'Formatted: ', FormattedAvatar) + return FormattedAvatar +} + +function LoadMyself() { + fetch('https://api.polytoria.com/v1/users/:id/avatar'.replace(':id', UserID)) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + Avatar.items = [] + + data.assets.forEach(item => { + switch(item.type) { + case 'hat': + Avatar.items.push(item.id) + break + default: + Avatar[item.type] = item.id + break + } + }); + + Avatar.headColor = '#' + data.colors.head || '#cdcdcd' + Avatar.torsoColor = '#' + data.colors.torso || '#cdcdcd' + Avatar.leftArmColor = '#' + data.colors.leftArm || '#cdcdcd' + Avatar.rightArmColor = '#' + data.colors.rightArm || '#cdcdcd' + Avatar.leftLegColor = '#' + data.colors.leftLeg || '#cdcdcd' + Avatar.rightLegColor = '#' + data.colors.rightLeg || '#cdcdcd' + + UpdateAvatar() + }) + .catch(error => { + console.log(error) + }); +} + +function WearAsset(element, info) { + if (Avatar.items.indexOf(info.id) === -1 && Avatar[info.type] !== info.id) { + console.log('Equip') + switch(info.type) { + case 'hat': + Avatar.items.push(info.id) + break + default: + Avatar[info.type] = info.id + break + } + } else { + console.log('unequip') + switch(info.type) { + case 'hat': + Avatar.items.splice(Avatar.items.indexOf(info.id), 1) + break + case 'face': + Avatar.face = "https://c0.ptacdn.com/static/3dview/DefaultFace.png" + break + default: + Avatar[info.type] = undefined + break + } + } + + LoadWearing() + UpdateAvatar() +} + +async function FetchMesh(id) { + if (id === null) {return null} + console.log('https://api.polytoria.com/v1/assets/serve-mesh/:id'.replace(':id', id)) + return fetch('https://api.polytoria.com/v1/assets/serve-mesh/:id'.replace(':id', id)) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + console.log(data, 'finished', data.url) + return data.url + }) + .catch(error => { + console.log('Fetch error: ' + error) + }); +} + +async function FetchAsset(id) { + if (id === null) {return null} + return fetch('https://api.polytoria.com/v1/assets/serve/:id/Asset'.replace(':id', id)) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + return data.url + }) + .catch(error => { + console.log('Fetch error: ' + error) + }); +} + +function LoadWearing() { + const WearingItems = [ + ...Avatar.items, + Avatar.shirt, + Avatar.pants, + Avatar.face + ].filter(item => item !== null && item !== undefined); + + Array.from(Wearing.children).forEach(element => { + const ItemID = element.getElementsByTagName('a')[0].href.split('/')[2] + if (!WearingItems.includes(ItemID)) { + element.remove(); + } + }); + + WearingItems.forEach(item => { + + const ExistingElement = Wearing.querySelector(`[data-itemid="${item}"]`); + if (!ExistingElement) { + fetch(`https://api.polytoria.com/v1/store/${item}`) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok'); + } + return response.json(); + }) + .then(item => { + if (Wearing.innerHTML === 'No items to show.') { + Wearing.innerHTML = '' + } + let NewItemCard = document.createElement('div'); + NewItemCard.classList = 'col-auto'; + NewItemCard.innerHTML = ItemCardContents + .replace(':ItemName', item.name) + .replace(':ItemID', item.id) + .replace(':ItemType', item.type.charAt(0).toUpperCase() + item.type.substring(1)) + .replace(':CreatorName', item.creator.name) + .replace(':CreatorID', item.creator.id) + .replace(':ItemThumbnail', item.thumbnail); + Wearing.appendChild(NewItemCard); + NewItemCard.getElementsByClassName('p-2')[0].addEventListener('click', function () { + WearAsset(NewItemCard, item); + }); + }) + .catch(error => { + console.log('Fetch error: ' + error); + }); + } + }); + + if (Array.from(Wearing.children).length === 0) { + Wearing.innerHTML = 'No items to show.' + } +} + + +/* +function LoadWearing() { + const WearingItems = [ + ...Avatar.items, + Avatar.shirt, + Avatar.pants, + Avatar.face + ].filter(item => item !== null) + + Array.from(Wearing.children).forEach(element => { + console.log('AAAAAAAAAAAA', element) + }) +} +*/ + +/* +function LoadWearing() { + const AllItems = structuredClone(Avatar.items) + AllItems.push(Avatar.shirt) + AllItems.push(Avatar.pants) + AllItems.push(Avatar.face) + AllItems.forEach(item => { + if (item !== null) { + let Element = document.querySelector(`a[href="/store/${item}"]`) + if (Element !== null) { + console.log('exists - load wearing') + Element = Element.parentElement.parentElement + Wearing.appendChild(Element) + } else if (Element === null) { + console.log('doesn\' exist - load wearing') + fetch('https://api.polytoria.com/v1/store/:id'.replace(':id', item)) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(item => { + let NewItemCard = document.createElement('div') + NewItemCard.classList = 'col-auto' + NewItemCard.innerHTML = ItemCardContents + .replace(':ItemName', item.name) + .replace(':ItemID', item.id) + .replace(':ItemType', item.type.charAt(0).toUpperCase() + item.type.substring(1)) + .replace(':CreatorName', item.creator.name) + .replace(':CreatorID', item.creator.id) + .replace(':ItemThumbnail', item.thumbnail) + Wearing.appendChild(NewItemCard) + NewItemCard.getElementsByClassName('p-2')[0].addEventListener('click', function(){ + WearAsset(NewItemCard, item) + }); + }) + .catch(error => { + console.log('Fetch error: ' + error) + }); + } else if (item.type === TabSelected) { + console.log('item type is selected tab - load wearing') + ItemGrid.appendChild(Element) + } else { + console.log('remove item - load wearing') + Element.remove() + } + } + }); +} +*/ \ No newline at end of file diff --git a/js/account/create.js b/js/account/create.js new file mode 100755 index 0000000..bcd28ab --- /dev/null +++ b/js/account/create.js @@ -0,0 +1,7 @@ +let NavColumn = document.getElementsByClassName('col-lg-2')[0] +let LaunchCreatorBtn = document.createElement('button') +LaunchCreatorBtn.classList = 'btn btn-success w-100' +LaunchCreatorBtn.innerText = 'Launch Creator' +LaunchCreatorBtn.setAttribute('data-id', '1') +LaunchCreatorBtn.setAttribute('onclick', 'editPlace(this)') +NavColumn.appendChild(LaunchCreatorBtn) \ No newline at end of file diff --git a/js/account/friends.js b/js/account/friends.js new file mode 100755 index 0000000..fec1777 --- /dev/null +++ b/js/account/friends.js @@ -0,0 +1,212 @@ +var SelectedFriends = [] + +setTimeout(function () { + chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + Settings = result.PolyPlus_Settings; + if (Settings.ImprovedFrListsOn === true) { + var Tab = "requests" + + var FriendsContainer = document.getElementById('friends-container') + var Container = document.createElement('div') + Container.classList = 'row mb-3' + Container.innerHTML = ` +
+
+ ` + FriendsContainer.parentElement.insertBefore(Container, FriendsContainer) + var AccAllFrBtn = document.getElementById('AccAllFrBtn') + var DelAllFrBtn = document.getElementById('DelAllFrBtn') + var AccBtns = document.querySelectorAll('[onclick="acceptFriendRequest(this)"]') + var DelBtns = document.querySelectorAll('[onclick="declineFriendRequest(this)"]') + if (!(AccBtns.length === 0)) { + AccAllFrBtn.addEventListener('click', function(){ + AccBtns.forEach(element => { + setTimeout(function () {}, 145) + fetch('https://polytoria.com/api/friends/send', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-Token': document.querySelector('input[name="_csrf"]').value + }, + body: JSON.stringify({ userID: parseInt(element.getAttribute('data-user-id')) }), + }) + .catch(error => { + // Handle any errors + console.error('Error:', error); + Success = false + }); + + /* + let NewAcceptBtn = document.createElement('a') + NewAcceptBtn.style.display = 'none' + sNewAcceptBtn.classList = 'btn btn-success' + NewAcceptBtn.setAttribute('data-user-id', element.getAttribute('data-user-id')) + NewAcceptBtn.setAttribute('onclick', 'acceptFriendRequest(this)') + FriendsContainer.appendChild(NewAcceptBtn) + NewAcceptBtn.click(); + */ + }) + }); + } else { + AccAllFrBtn.setAttribute('disabled', 'true') + } + if (!(DelBtns.length === 0)) { + DelAllFrBtn.addEventListener('click', function(){ + DelBtns.forEach(element => { + setTimeout(function () {}, 110) + fetch('https://polytoria.com/api/friends/remove', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-Token': document.querySelector('input[name="_csrf"]').value + }, + body: JSON.stringify({ userID: parseInt(element.getAttribute('data-user-id')) }), + }) + .catch(error => { + // Handle any errors + console.error('Error:', error, document.querySelector('input[name="_csrf"]').value); + Success = false + }); + + /* + let NewDeclineBtn = document.createElement('a') + NewDeclineBtn.style.display = 'none' + NewDeclineBtn.classList = 'btn btn-danger' + NewDeclineBtn.setAttribute('data-user-id', element.getAttribute('data-user-id')) + NewDeclineBtn.setAttribute('onclick', 'declineFriendRequest(this)') + FriendsContainer.appendChild(NewDeclineBtn) + NewDeclineBtn.click(); + */ + }) + }); + } else { + DelAllFrBtn.setAttribute('disabled', 'true') + } + let Text = document.createElement('p') + Text.classList = 'mx-auto' + Text.style.textAlign = 'center' + Text.style.fontSize = '1.3rem' + Text.style.display = 'none' + Text.innerHTML = ` + 0 friends selected! +
+ + + + ` + FriendsContainer.parentElement.insertBefore(Text, FriendsContainer) + let Text_Span = Text.querySelector('span'); + let Text_View = document.getElementById('viewSelectionBtn'); + let Text_Clear = document.getElementById('clearSelectionBtn'); + let Text_Remove = document.getElementById('removeSelectionBtn'); + document.querySelector('[data-friends-tab="requests"]').addEventListener('click', function(){ + Tab = "requests" + Container.style.display = ''; + Text.style.display = 'none'; + document.querySelectorAll('input[type="check"]').forEach(element => {element.remove();}); + }); + document.querySelector('[data-friends-tab="friends"]').addEventListener('click', function(){ + Tab = "friends" + Container.style.display = 'none'; + Text.style.display = ''; + }); + var ConfirmRemove = 0 + Text_View.addEventListener('click', function(){}); + Text_Clear.addEventListener('click', function(){ + SelectedFriends = [] + UpdateCheckboxes(); + Text_Span.innerText = SelectedFriends.length + }); + Text_Remove.addEventListener('click', function(){ + ConfirmRemove = ConfirmRemove + 1 + switch(ConfirmRemove) { + case 0: + Text_Remove.innerText = 'Remove Selected Friends' + break + case 1: + Text_Remove.innerText = 'Are you sure?' + break + case 2: + for (let i = 0; i < SelectedFriends.length; i++) { + setTimeout(function () {}, 110) + let NewDeclineBtn = document.createElement('a') + NewDeclineBtn.style.display = 'none' + NewDeclineBtn.classList = 'btn btn-danger' + NewDeclineBtn.setAttribute('data-user-id', SelectedFriends[i]) + NewDeclineBtn.setAttribute('onclick', 'declineFriendRequest(this)') + FriendsContainer.appendChild(NewDeclineBtn) + NewDeclineBtn.click(); + } + SelectedFriends = [] + UpdateCheckboxes(); + Text_Remove.innerText = 'Remove Selected Friends' + ConfirmRemove = 0 + break + } + }); + + const observer = new MutationObserver(function (){ + if (FriendsContainer.children.length > 0 && Tab === "friends") { + LoadCheckBoxes(); + } + }); + observer.observe(FriendsContainer, {childList: true, subtree: false}); + + function LoadCheckBoxes() { + Array.from(FriendsContainer.children).forEach(element => { + let DeclineBtn = element.querySelector('a.btn.btn-danger') + let UserID = DeclineBtn.getAttribute('data-user-id') + let Column = document.createElement('div') + let EditColumn = element.querySelector('.col-9') + Column.classList = 'col-auto' + var NewCheckBox = document.createElement('button') + NewCheckBox.classList = 'polyplus-multiremovefr-checkbox' + NewCheckBox.setAttribute('style', 'padding: 20px; background-color: #191919; border: 1px solid #393939; border-radius: 1rem;') + var Index = SelectedFriends.indexOf(UserID) + if (Index !== -1) { + DeclineBtn.classList.add('disabled') + NewCheckBox.style.borderColor = 'lime' + } + EditColumn.classList.remove('col-9') + EditColumn.classList.add('col') + Column.appendChild(NewCheckBox) + EditColumn.parentElement.appendChild(Column) + NewCheckBox.addEventListener('click', function(){ + var Index = SelectedFriends.indexOf(UserID) + if (Index === -1) { + DeclineBtn.classList.add('disabled') + SelectedFriends.push(UserID) + NewCheckBox.style.borderColor = 'lime' + } else { + SelectedFriends.splice(Index, 1) + NewCheckBox.style.borderColor = '#393939' + DeclineBtn.classList.remove('disabled') + } + Text_Span.innerText = SelectedFriends.length + UpdateCheckboxes(); + }); + }); + } + + function UpdateCheckboxes(){ + document.querySelectorAll('.polyplus-multiremovefr-checkbox').forEach(element => { + let Parent = element.parentElement.parentElement.parentElement.parentElement.parentElement + let DeclineBtn = Parent.querySelector('a.btn.btn-danger') + if (element.getAttribute('disabled')) { + element.removeAttribute('disabled') + } + if (SelectedFriends.IndexOf(DeclineBtn.getAttribute('data-user-id')) === -1) { + element.style.borderColor = '#393939' + DeclineBtn.classList.remove('disabled') + if (SelectedFriends.length >= 25) { + element.setAttribute('disabled', true) + } + } else { + DeclineBtn.classList.add('disabled') + element.style.borderColor = 'lime' + } + }) + } + } + }); +}, 100); \ No newline at end of file diff --git a/js/account/home.js b/js/account/home.js new file mode 100755 index 0000000..ea9f6c1 --- /dev/null +++ b/js/account/home.js @@ -0,0 +1,143 @@ +var Settings; +var PinnedGames; +var BestFriends; + +let ContainerElement = ` +
`; +let GameContainerElement = ` +
+
+ +
+
+ :GameName +
+
+
+
+`; +let TitleElement = ` +
+
Jump right back into your favorite games
+
Pinned Games
+
`; +var FriendContainer = document.querySelector('.card:has(.friendsPopup) .card-body') + +let NewContainer = document.createElement('div'); +NewContainer.style.display = 'none' +NewContainer.classList = 'card card-dash mcard'; +NewContainer.style.animationDelay = '0.18s'; +NewContainer.innerHTML = ContainerElement; + +let NewTitle = document.createElement('div'); +NewTitle.style.display = 'none' +NewTitle.classList = 'row reqFadeAnim px-2 px-lg-0'; +NewTitle.innerHTML = TitleElement; + +let BestFriendsContainer = document.createElement('div') +BestFriendsContainer.classList = 'd-flex' +BestFriendsContainer.style = 'display: none; border-bottom: 1px solid #000; padding-bottom: 10px; margin-bottom: 10px; width: 100%;' +/* +BestFriendsContainer.style.display = 'none' +BestFriendsContainer.style.borderBottom = '1px solid #000' +BestFriendsContainer.style.paddingBottom = '10px' +BestFriendsContainer.style.marginBottom = '10px' +BestFriendsContainer.style.width = '100%' +*/ + +let Spacer = document.createElement('div') +Spacer.innerHTML = ' ' +Spacer.style.width = '50px' +Spacer.prepend(BestFriendsContainer) +FriendContainer.prepend(BestFriendsContainer) + +UpdateLocalData(); + +function UpdateLocalData() { + chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { + Settings = result.PolyPlus_Settings + }); + + chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result) { + PinnedGames = result.PolyPlus_PinnedGames || []; + chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result) { + BestFriends = result.PolyPlus_BestFriends || []; + if (Settings.PinnedGamesOn === true) { + LoadPinnedGames(); + } else { + NewContainer.style.display = 'none' + NewTitle.style.display = 'none' + } + if (Settings.BestFriendsOn === true) { + LoadBestFriends(); + } else { + BestFriendsContainer.style.display = 'none' + Spacer.style.display = 'none' + } + }); + }); +} + +function LoadPinnedGames() { + var Existing = NewContainer.children[0].children + Array.from(Existing).forEach(element => { + element.remove(); + }); + + if (PinnedGames.length === 0) { + NewContainer.style.display = 'none' + NewTitle.style.display = 'none' + } else { + NewContainer.style.display = '' + NewTitle.style.display = '' + } + + PinnedGames.forEach(element => { + fetch('https://api.polytoria.com/v1/places/:id'.replace(':id', element)) + .then(response => response.json()) + .then(data => { + let GameName = data.name; + let GameThumbnail = data.thumbnail; + + var NewGameContainer = document.createElement('a'); + NewGameContainer.innerHTML = GameContainerElement.replace(':GameName',GameName).replace(':Thumbnail',GameThumbnail); + NewGameContainer.setAttribute('href', '/places/:id'.replace(':id',element)); + + if (new Date().getDate() >= new Date(data.updatedAt).getDate()) { + console.log('Game has updated') + } + + NewContainer.children[0].appendChild(NewGameContainer); + }) + .catch(error => { + console.error('Error:', error); + }); + }); +} + +function LoadBestFriends() { + Array.from(document.querySelectorAll('[bestFriend]')).forEach(element => { + element.removeAttribute('bestFriend') + element.getElementsByClassName('friend-name')[0].style.color = 'initial'; + FriendContainer.appendChild(element) + }); + + if (BestFriends.length === 0) { + BestFriendsContainer.style.display = 'none' + } else { + BestFriendsContainer.style.display = '' + } + + BestFriends.forEach(element => { + let ExistingFriend = document.getElementById('friend-' + element) + if (ExistingFriend) { + ExistingFriend.setAttribute('bestFriend', 'true') + ExistingFriend.getElementsByClassName('friend-name')[0].style.color = 'yellow'; + BestFriendsContainer.prepend(ExistingFriend) + } + }); +} + +var SecondaryColumn = document.getElementsByClassName('col-lg-8')[0] +SecondaryColumn.insertBefore(NewContainer, SecondaryColumn.children[0]); +SecondaryColumn.insertBefore(NewTitle, SecondaryColumn.children[0]); \ No newline at end of file diff --git a/js/account/inventory.js b/js/account/inventory.js new file mode 100755 index 0000000..a57615b --- /dev/null +++ b/js/account/inventory.js @@ -0,0 +1,186 @@ +if (window.location.pathname.split('/')[3] === "inventory") { + let 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') + WishlistNav.classList.add('nav-item') + WishlistNav.innerHTML = ` + + + Item Wishlist + + ` + Nav.appendChild(WishlistNav) + + if (window.location.pathname.split('/')[4] === "wishlist") { + let ItemGrid = document.getElementsByClassName('itemgrid')[0] + let ItemCardContents = ` + +
+ :LimitedTag +
+ +
+
+
+ :ItemName +
+
+ + by :CreatorName + + + ` + + Array.from(ItemGrid.children).forEach(element => { + element.remove(); + }); + Array.from(Nav.children).forEach(element => { + element = element.children[0] + if (!(element === WishlistNav)) { + if (element.classList.contains('active')) { + element.classList.remove('active') + } + } + }); + WishlistNav.children[0].classList.add('active') + let Search = document.createElement('div') + Search.classList = 'row' + Search.innerHTML = ` +
+ +
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+ ` + ItemGrid.parentElement.prepend(document.createElement('br'), ItemGrid.parentElement.children[0]) + ItemGrid.parentElement.prepend(Search, ItemGrid.parentElement.children[0]) + + let Type = document.getElementById('polyplus-itemwish-type') + let SearchBar = document.getElementById('polyplus-itemwish-searchbar') + let IsLimited = document.getElementById('polyplus-itemwish-isLimited') + let IsAvailable = document.getElementById('polyplus-itemwish-isAvailable') + + Type.addEventListener('change', function(){ + Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked) + }); + + SearchBar.addEventListener('change', function(){ + Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked) + }); + + IsLimited.addEventListener('change', function(){ + Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked) + }); + + IsAvailable.addEventListener('change', function(){ + Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked) + }); + + chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){ + let Wishlist = result.PolyPlus_ItemWishlist || []; + console.log('wishlist: ', Wishlist) + Wishlist.forEach(element => { + let NewItemCard = document.createElement('div') + NewItemCard.classList = 'px-0' + fetch('https://api.polytoria.com/v1/store/:id'.replace(':id', element)) + .then(response => response.json()) + .then(data => { + NewItemCard.innerHTML = ItemCardContents.replace(':ItemID', data.id).replace(':ItemThumbnail', data.thumbnail).replace(':ItemName', data.name).replace(':CreatorID', data.creator.id).replace(':CreatorName', data.creator.name) + if (data.isLimited === true) { + NewItemCard.innerHTML = NewItemCard.innerHTML.replace(':LimitedTag', '
Limited
') + } else { + NewItemCard.innerHTML = NewItemCard.innerHTML.replace(':LimitedTag', '') + } + NewItemCard.setAttribute('data-id', data.id) + NewItemCard.setAttribute('data-name', data.name) + NewItemCard.setAttribute('data-type', data.type) + NewItemCard.setAttribute('data-creator', data.creator.name) + NewItemCard.setAttribute('data-limited', data.isLimited) + if (data.isLimited === false) { + NewItemCard.setAttribute('data-price', data.price) + } + + ItemGrid.appendChild(NewItemCard) + + NewItemCard.getElementsByClassName('polyplus-itemwish-removebtn')[0].addEventListener('click', function(){ + let Index = Wishlist.indexOf(parseInt(NewItemCard.getAttribute('data-id'))) + if (Index === -1) { + NewItemCard.remove(); + return + } else { + Wishlist.splice(Index, 1) + console.log(Wishlist) + NewItemCard.remove(); + } + chrome.storage.sync.set({'PolyPlus_ItemWishlist': Wishlist, arrayOrder: true}, function() { + console.log('ItemWishlist successfully saved: ' + ItemWishlist) + }); + }); + }) + .catch(error => { + console.error('Error:', error); + }); + }); + }); + } + } +} + +function Update(type, query, isLimited, isAvailable) { + let ItemGrid = document.getElementsByClassName('itemgrid')[0] + let BrickBalance = parseInt(JSON.parse(window.localStorage.getItem('account_info')).Bricks) + query = query.toLowerCase(); + let Results = Array.from(ItemGrid.children) + for (let i = 0; i < Results.length; i++) { + let Show = true + + console.log('type: ', type) + if (!(type === 'any')) { + console.log('isn\'t any') + if (!(Results[i].getAttribute('data-type') === type)) {Show = false} + } + + if (!(Results[i].getAttribute('data-name').toLowerCase().startsWith(query))) {Show = false} + + if (isLimited === true) { + if (!(Results[i].getAttribute('data-limited') === 'true')) {Show = false} + } + + if (isAvailable === true) { + if (!(parseInt(Results[i].getAttribute('data-price')) <= BrickBalance)) {Show = false} + } + + if (Show === true) { + Results[i].style.display = 'block' + } else { + Results[i].style.display = 'none' + } + } +} \ No newline at end of file diff --git a/js/account/settings-privacy.js b/js/account/settings-privacy.js new file mode 100755 index 0000000..5d5a54b --- /dev/null +++ b/js/account/settings-privacy.js @@ -0,0 +1,32 @@ +setTimeout(function () {}, 100) + +chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + if (result.PolyPlus_Settings.MoreSearchFiltersOn === true) { + let BlockedUsersCard = document.getElementsByClassName('card-body')[1] + let InputGroup = document.createElement('div') + InputGroup.classList = 'input-group mb-2' + InputGroup.innerHTML = ` + + + ` + BlockedUsersCard.insertBefore(InputGroup, BlockedUsersCard.children[0]) + let SearchBar = document.getElementById('blocked-users-search') + let ConfirmBtn = document.getElementById('blocked-users-confirm') + + ConfirmBtn.addEventListener('click', function(){ + SearchBlockedUsers(SearchBar.value); + }); + + function SearchBlockedUsers(query) { + query = query.toLowerCase(); + for (let i = 1; i < BlockedUsersCard.children.length; i++) { + let Username = BlockedUsersCard.children[i].getElementsByTagName('h5')[0].innerText.toLowerCase(); + if (Username.includes(query)) { + BlockedUsersCard.children[i].style.display = 'block' + } else { + BlockedUsersCard.children[i].style.display = 'none' + } + } + } + } +}); \ No newline at end of file diff --git a/js/account/trades-outbound.js b/js/account/trades-outbound.js new file mode 100755 index 0000000..270301c --- /dev/null +++ b/js/account/trades-outbound.js @@ -0,0 +1,110 @@ +setTimeout(function() {}, 100) +var SelectedTrades = [] + +let Parent = document.getElementsByClassName('card mcard p-5 text-center text-muted')[0].parentElement +let Text = document.createElement('p') +Text.classList = 'mx-auto' +Text.style.textAlign = 'center' +Text.style.fontSize = '1.3rem' +Text.innerHTML = ` +0 trades selected! +
+ + + +` +Parent.insertBefore(Text, Parent.children[0]) +let Text_Span = Text.querySelector('span'); +let Text_View = document.getElementById('viewSelectionBtn'); +let Text_Clear = document.getElementById('clearSelectionBtn'); +let Text_Cancel = document.getElementById('cancelSelectionBtn'); + +var ConfirmCancel = 0 +Text_View.addEventListener('click', function(){}); +Text_Clear.addEventListener('click', function(){ + SelectedTrades = [] + UpdateCheckboxes(); + Text_Span.innerText = SelectedTrades.length +}); +Text_Cancel.addEventListener('click', function(){ + ConfirmCancel = ConfirmCancel + 1 + switch(ConfirmCancel) { + case 0: + Text_Cancel.innerText = 'Cancel Selected Trades' + break + case 1: + Text_Cancel.innerText = 'Are you sure?' + break + case 2: + let Success = true + for (let i = 0; i < SelectedTrades.length; i++) { + setTimeout(function () {}, 110) + console.log(SelectedTrades[i]) + fetch('https://polytoria.com/api/trade/decline', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-Token': document.querySelector('input[name="_csrf"]').value + }, + body: JSON.stringify({ id: SelectedTrades[i] }), + }) + .catch(error => { + // Handle any errors + console.error('Error:', error); + Success = false + }); + } + SelectedTrades = [] + UpdateCheckboxes(); + Text_Cancel.innerText = 'Cancel Selected Trades' + ConfirmCancel = 0 + break + } +}); + +LoadCheckBoxes(); + +function LoadCheckBoxes() { + Array.from(document.getElementsByClassName('card-inbox')).forEach(element => { + let ViewBtn = element.querySelector('a.btn.btn-primary') + let TradeID = parseInt(ViewBtn.getAttribute('href').split('/')[3]) + var NewCheckBox = document.createElement('button') + NewCheckBox.classList = 'polyplus-multicanceltr-checkbox' + NewCheckBox.setAttribute('style', 'padding: 20px; background-color: #191919; border: 1px solid #393939; border-radius: 1rem; margin-left: 10px;') + var Index = SelectedTrades.indexOf(TradeID) + if (Index !== -1) { + NewCheckBox.style.borderColor = 'lime' + } + ViewBtn.parentElement.appendChild(NewCheckBox) + NewCheckBox.addEventListener('click', function(){ + var Index = SelectedTrades.indexOf(TradeID) + if (Index === -1) { + SelectedTrades.push(TradeID) + NewCheckBox.style.borderColor = 'lime' + } else { + SelectedTrades.splice(Index, 1) + NewCheckBox.style.borderColor = '#393939' + } + Text_Span.innerText = SelectedTrades.length + UpdateCheckboxes(); + }); + }); +} + +function UpdateCheckboxes(){ + document.querySelectorAll('.polyplus-multicanceltr-checkbox').forEach(element => { + let Parent = element.parentElement + let ViewBtn = Parent.querySelector('a.btn.btn-primary') + if (element.getAttribute('disabled')) { + element.removeAttribute('disabled') + } + if (SelectedTrades.IndexOf(ViewBtn.getAttribute('data-user-id')) === -1) { + element.style.borderColor = '#393939' + } else { + element.style.borderColor = 'lime' + if (SelectedTrades.length >= 10) { + element.setAttribute('disabled', true) + } + } + }) +} \ No newline at end of file diff --git a/js/account/transactions.js b/js/account/transactions.js new file mode 100755 index 0000000..62a34de --- /dev/null +++ b/js/account/transactions.js @@ -0,0 +1,101 @@ +setTimeout(function () {}, 100) + +let Currencies; + +LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){ + Currencies = JSON.parse(text) + console.log(new Date(Currencies.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"}), Currencies) +}) + +let Nav = document.querySelector('.nav-pills') +let DIV = document.createElement('div') +DIV.innerHTML = ` + + + + +` +Nav.appendChild(document.createElement('hr')) +Nav.appendChild(DIV) + +let Input = document.getElementById('polyplus-brickconverter-input') +let Output = document.getElementById('polyplus-brickconverter-output') +let Type = document.getElementById('polyplus-brickconverter-type') +chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + Type.selectedIndex = result.PolyPlus_Settings.IRLPriceWithCurrencyCurrency || 0 +}); +let Package = document.getElementById('polyplus-brickconverter-package') + +Input.addEventListener('change', function(){ + Update() +}); + +Type.addEventListener('change', function(){ + Update() +}); + +Package.addEventListener('change', function(){ + Update() +}); + +function Update(){ + let DISPLAY = Type.options[Type.selectedIndex].value + let IRL = (parseInt(Input.value.replace(/,/g, '')) * Currencies.Data[Package.selectedIndex][DISPLAY]).toFixed(2) + /* + var IRL; + var DISPLAY; + switch (Type.selectedIndex) { + case 0: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0099).toFixed(2) + DISPLAY = 'USD' + break + case 1: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.009).toFixed(2) + DISPLAY = 'EUR' + break + case 2: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0131).toFixed(2) + DISPLAY = 'CAD' + break + case 3: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0077).toFixed(2) + DISPLAY = 'GBP' + break + case 4: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.1691).toFixed(2) + DISPLAY = 'MXN' + break + case 5: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0144).toFixed(2) + DISPLAY = 'AUD' + break + case 6: + IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.2338).toFixed(2) + DISPLAY = 'TRY' + break + } + */ + Output.value = "$" + IRL + " " + DISPLAY +} + +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/background.js b/js/background.js new file mode 100755 index 0000000..3c3b1ba --- /dev/null +++ b/js/background.js @@ -0,0 +1,105 @@ +chrome.contextMenus.create({ + title: 'Copy Asset ID', + id: 'PolyPlus-CopyID', + contexts: ['link'], + documentUrlPatterns: ['https://polytoria.com/*'], + targetUrlPatterns: [ + "https://polytoria.com/places/**", + "https://polytoria.com/users/**", + "https://polytoria.com/store/**" + ] +}); + +chrome.contextMenus.create({ + title: 'Copy Avatar Hash', + id: 'PolyPlus-CopyAvatarHash', + contexts: ['image'], + documentUrlPatterns: ['https://polytoria.com/*'], + targetUrlPatterns: [ + "https://c0.ptacdn.com/thumbnails/avatars/**", + "https://c0.ptacdn.com/thumbnails/avatars/**" + ] +}); + +chrome.contextMenus.onClicked.addListener(function (info, tab){ + if (info.menuItemId === 'PolyPlus-CopyID') { + let ID = parseInt(info.linkUrl.split('/')[4]) + chrome.scripting + .executeScript({ + target: {tabId: tab.id}, + func: CopyAssetID, + args: [ID] + }) + .then(() => console.log("Copied ID!")); + } + + if (info.menuItemId === 'PolyPlus-CopyAvatarHash') { + let Hash = new URL(info.srcUrl).pathname.split('/')[3].replace('-icon', '').replace('.png', '') + chrome.scripting + .executeScript({ + target: {tabId: tab.id}, + func: CopyAvatarHash, + args: [Hash] + }) + .then(() => console.log("Copied ID!")); + } +}); + +/* +chrome.webNavigation.onCompleted.addListener(function (details){ + console.log('TAB CREATED') + + chrome.scripting + .executeScript({ + target: {tabId: details.tabId}, + func: HandleJoinPlace, + args: [details.url] + }) +}, { + url: [{ urlMatches: "https://polytoria.com/join-place/*" }] +}); +*/ + +function CopyAssetID(id) { + navigator.clipboard + .writeText(id) + .then(() => { + alert('Successfully copied ID!') + }) + .catch(() => { + alert('Failure to copy ID.') + }); +} + +function CopyAvatarHash(hash) { + navigator.clipboard + .writeText(hash) + .then(() => { + alert('Successfully copied avatar hash!') + }) + .catch(() => { + alert('Failure to copy avatar hash.') + }); +} + +function HandleJoinPlace(url) { + console.log('HANDLING JOINING PLACE') + const PlaceID = new URL(url).pathname.split('/')[2] + fetch('https://polytoria.com/api/places/join',{ + method: 'POST', + body: { + placeID:PlaceID + } + }) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + if (data.success !== true) {throw new Error(data.message)} + window.location.href = 'polytoria://client/' + data.token + }) + .catch(error => {console.log(error)}) +} \ No newline at end of file diff --git a/js/everywhere.js b/js/everywhere.js new file mode 100755 index 0000000..832197a --- /dev/null +++ b/js/everywhere.js @@ -0,0 +1,274 @@ +var Settings; +const 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 +} +let Theme = null; + +chrome.storage.sync.get(["PolyPlus_Settings"], function(result) { + // Merge settings and expected settings to make sure all keys exist + let RawSettings = result.PolyPlus_Settings + Settings = MergeObjects(RawSettings || ExpectedSettings, ExpectedSettings); + //chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() {}); + + // If theme exists, create a style element to represent it + if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { + 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() { + 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 + const UserData = { + Username: document.querySelector('a.text-reset.text-decoration-none[href^="/users"]').innerText.replace(/\s+/g,''), + ID: document.querySelector('.text-reset.text-decoration-none[href^="/users/"]').getAttribute('href').split('/')[2], + Bricks: document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g,'') + } + + window.localStorage.setItem('account_info', JSON.stringify(UserData)) + document.body.setAttribute('data-URL', window.location.href) + + // Add PolyPlus Settings link to Sidebar + const Parent = document.querySelector('ul.nav.nav-flush') + const Clone = Parent.querySelectorAll('li.nav-item')[0].cloneNode(true) + Clone.getElementsByTagName('a')[0].href = '/my/settings/polyplus' + Clone.getElementsByTagName('span')[0].innerText = "Poly+" + const Icon = Clone.querySelector('i') + Icon.classList = 'fa-regular fa-sparkles' + + 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].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 = (UserData.Bricks.replace(/,/g, '') * 0.0099).toFixed(2) + DISPLAY = 'USD' + break + case 1: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.009).toFixed(2) + DISPLAY = 'EUR' + break + case 2: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.0131).toFixed(2) + DISPLAY = 'CAD' + break + case 3: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.0077).toFixed(2) + DISPLAY = 'GBP' + break + case 4: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.1691).toFixed(2) + DISPLAY = 'MXN' + break + case 5: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.0144).toFixed(2) + DISPLAY = 'AUD' + break + case 6: + IRL = (UserData.Bricks.replace(/,/g, '') * 0.2338).toFixed(2) + DISPLAY = 'TRY' + break + } + let BrickBalanceCount = [document.querySelector('.text-success .brickBalanceCount'), document.querySelector('.text-success .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/forum/forum-search.js b/js/forum/forum-search.js new file mode 100755 index 0000000..44613d0 --- /dev/null +++ b/js/forum/forum-search.js @@ -0,0 +1,53 @@ +setTimeout(function () {}, 100) +var Settings; +chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + Settings = result.PolyPlus_Settings; + + if (!(Settings.MoreSearchFiltersOn === true)) { + return + } + + let Form = document.querySelector('form[action="/forum/search"]') + let SearchBtn = document.querySelector('button[type="submit"]') + let CreatedByFilter = document.createElement('div') + CreatedByFilter.classList = 'input-group mt-2' + CreatedByFilter.innerHTML = ` +
+ + +
+ ` + console.log(SearchBtn) + Form.insertBefore(CreatedByFilter, SearchBtn.parentElement) + let CreatedByFilter_Checkbox = CreatedByFilter.querySelector('input[type="checkbox"]') + let CreatedByFilter_Input = CreatedByFilter.querySelector('input[type="text"]') + let CreatedByValue = GetURLParameter("createdBy") + console.log(CreatedByValue) + if (CreatedByValue) { + CreatedByFilter_Checkbox.setAttribute('checked', true) + CreatedByFilter_Input.setAttribute('value', CreatedByValue) + CreatedByFilter_Input.removeAttribute('disabled') + document.querySelectorAll('.forum-entry').forEach(element => { + console.log(element.querySelectorAll('a[href^="/users/"]')[1].innerText) + if (!(element.querySelectorAll('a[href^="/users/"]')[1].innerText === CreatedByValue)) { + element.remove(); + } + }); + } + /* + CreatedByFilter_Checkbox.addEventListener('click', function(){ + let Status = CreatedByFilter_Checkbox.getAttribute('checked') + if (Status === true) { + CreatedByFilter_Input.removeAttribute('disabled') + } else { + CreatedByFilter_Input.setAttribute('disabled', true) + } + }); + */ +}); + +function GetURLParameter(param) { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + return urlParams.get(param); +} \ No newline at end of file diff --git a/js/forum/forum-view.js b/js/forum/forum-view.js new file mode 100755 index 0000000..f999098 --- /dev/null +++ b/js/forum/forum-view.js @@ -0,0 +1,173 @@ +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: ` +