February 8th is going to be a good day

- New Icon

- Moved avatar-sandbox.html and utils.js to /resources

- Browser automatically allows resources to be used from the resources folder

- Code Improvements

- Deleted trick-or-treat.js

- Bug Fixes
This commit is contained in:
Index 2024-02-07 17:06:33 -06:00
parent 3e01832005
commit 976cdfbf25
22 changed files with 580 additions and 2596 deletions

BIN
icon.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

@ -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')

View file

@ -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')

View file

@ -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 => {

View file

@ -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 = `
<a href="/store/:ItemID" class="text-reset">
<div class="card mb-2">
: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 = `
<div class="col-auto">

View file

@ -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) => `<span data-index="${i}" style="display: none;">${x}</span>`).join('')
let NumberOfCaptions = (PostContent.split(' ').length) - 1
Swal.fire({
title: "No Attention Span Mode",
html: `
<video src="${chrome.runtime.getURL('low-attention-span.mp4')}" loop autoplay muted play>
<div id="polyplus-captions">${Captions}</div>
`
});
let CaptionsElement = document.getElementById('polyplus-captions')
let Index = 0
//LoopIteration()
function LoopIteration() {
Array.from(CaptionsElement.children).forEach(element => {
element.style.display = 'none'
});
if (CaptionsElement.children[Index] === undefined) {
Swal.close()
return
}
CaptionsElement.children[Index].style.display = 'block'
setTimeout(function () {
console.log(Index, 'Next Caption')
Index++
LoopIteration()
}, 1100)
}
function CombineArray(arr) {
let CombinedArray = [];
let CurrentCombinedItem = "";
for (let i = 0; i < arr.length; i++) {
if ((CurrentCombinedItem + " " + arr[i]).length <= 6) {
if (CurrentCombinedItem !== "") {
CurrentCombinedItem += " ";
}
CurrentCombinedItem += arr[i];
} else {
CombinedArray.push(CurrentCombinedItem);
CurrentCombinedItem = arr[i];
}
}
if (CurrentCombinedItem !== "") {
CombinedArray.push(CurrentCombinedItem);
}
return CombinedArray;
}
}
setTimeout(LowAttentionSpanMode, 525)
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
let text = document.querySelectorAll('p.mb-0 + p')
if (result.PolyPlus_Settings.ForumMarkOn === true) {
text.forEach(element => {
element.innerHTML = MarkdownText(element.innerText)
});
}
if (result.PolyPlus_Settings.ForumMentsOn === true) {
text.forEach(element => {
let output = element.innerText.replace(/@([\w.]+)/g, '<a class="polyplus-mention" href="https://example.com/">@$1</a>');
output = output.replace(/\n/g, '<br>');
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 <h3> tag
const headingText = line.substring(3).trim();
return `<h3>${headingText}</h3>`;
} else if (line.startsWith('##')) {
// Secondary heading: remove the '##' and wrap in <h2> tag
const headingText = line.substring(2).trim();
return `<h2>${headingText}</h2>`;
} else if (line.startsWith('#')) {
// Big heading: remove the '#' and wrap in <h1> tag
const headingText = line.substring(1).trim();
return `<h1>${headingText}</h1>`;
} else {
// Apply formatting to the line
let formattedLine = line.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>'); // Bold
formattedLine = formattedLine.replace(/__(.*?)__/g, '<u>$1</u>'); // Underline
formattedLine = formattedLine.replace(/\*(.*?)\*/g, '<em>$1</em>'); // Italics
formattedLine = formattedLine.replace(/~~(.*?)~~/g, '<s>$1</s>'); // Strikethrough
return formattedLine;
}
});
// Join the formatted lines back into a single string
const formattedText = formattedLines.join('\n\n');
return formattedText;
}

View file

@ -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, '<a href="https://example.com/">@$1</a>');
output = output.replace(/\n/g, '<br>');
element.innerHTML = output;
const links = element.querySelectorAll('a');
if (!(links.length > 3)) {
processLinks(links);
}
});
});

View file

@ -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], `<a href="/profile/reufihfuighqre8uogqre?ref=${encodeURIComponent(window.location.pathname)}" class="polyplus-mention">${match[0]}</a>`)
FormattedText = FormattedText.replaceAll(match[0], `<a href="/profile/${Username}?ref=${encodeURIComponent(window.location.pathname)}" class="polyplus-mention">${match[0]}</a>`)
}
text.innerHTML = FormattedText
}
}
function HandleUnixTimestamps() {
const Regex = /<t:[A-Za-z0-9]+>/gm
//const Regex = /&lt;t:[A-Za-z0-9]+&gt;/i
const Regex = /&lt;t:[A-Za-z0-9]+&gt;/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 = `<code style="color: orange;">${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})</code>`
FormattedText = FormattedText.replaceAll(match[0], Result)
console.log(FormattedText)
}
//text.innerHTML = FormattedText
text.innerHTML = FormattedText
}
}

View file

@ -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(){

View file

@ -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 => {

View file

@ -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 = '<i class="fa-duotone fa-star"></i> Un-pin';
} else {
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin';
if (PinnedGames.length !== 5) {
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin'
} else {
PinBtn.setAttribute('disabled', true)
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin (max 5/5)'
}
}
PinBtn.addEventListener('click', function() {

313
js/places/place-view2.js Normal file
View file

@ -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 = '<i class="fa-duotone fa-star"></i> Un-pin';
} else {
if (PinnedGames.length !== 5) {
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin'
} else {
PinBtn.setAttribute('disabled', true)
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> 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 = '<i class="fa-duotone fa-star"></i> Pin'
} else {
PinnedGames[GameID] = {lastVisited: new Date()}
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> 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 = '<i class="fa-duotone fa-star"></i> Un-pin'
} else {
if (PinnedGames.length !== 5) {
PinBtn.removeAttribute('disabled')
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin'
} else {
PinBtn.setAttribute('disabled', true)
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> 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 = '<i class="fa-duotone fa-hammer"></i> <span>Edit Details</span>'
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)
}

View file

@ -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 = `
<style>
#page {
margin-top: 7.5rem;
}
h1 {
font-size: 4.6rem;
color: rgb(48, 48, 48);
}
h1 span.indent {
border-left: 10px solid rgb(48, 48, 48);
margin-right: 15px;
}
h1 span.highlight {
color: red;
}
h2 {
color: rgb(48, 48, 48);
}
h2 span.indent {
border-left: 7.5px solid rgb(48, 48, 48);
margin-right: 15px;
}
p span:first-child {
font-size: 1.4rem;
}
span.desc {
color: rgb(120, 120, 120);
}
.goback {
color: rgb(120, 120, 120);
text-decoration: none;
}
dialog {
background-color: #080808;
color: #c4c4c4;
border: 1px solid #3bafff;
border-radius: 10px;
}
.input-group-text {
background-color: #000;
border-color: #000;
color: #fff;
}
label {
font-size: 0.8rem;
margin-bottom: 2.75px;
}
dialog::backdrop {
background-color: rgba(0, 0, 0, 0.73);
}
dialog .modal-header p {
margin-bottom: 0px;
color: #fff;
}
dialog .modal-body p:first-child {
font-size: 0.9rem;
}
/*
p span span.status {
font-size: 0.16rem !important;
color: #cee;
}
*/
</style>
<dialog class="w-50" id="ResetDefaults-Modal">
<div class="modal-header">
<p>Are you Sure?</p>
</div>
<div class="modal-body">
<p>Are you sure you'd like to reset all settings to their respective defaults? (this action is irreversible)</p>
<button id="ResetDefaults-Modal-Yes" class="btn btn-danger">Yes</button>
<button id="ResetDefaults-Modal-No" class="btn btn-primary">No</button>
</div>
</dialog>
<dialog class="w-50" id="ThemeCreator-Modal" data-setting="ThemeCreator">
<div class="modal-header">
<p>Theme Creator</p>
</div>
<div class="modal-body">
<p>Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development)</p>
<!--
<div class="mx-auto" style="width: 450px; height: 350px; border: 2.5px solid #fff;">
<div class="row h-100">
<div class="col-md-1 h-100" style="padding: 25px; border-right: 2.5px solid #fff; padding-left: 0px !important;"></div>
<div class="col h-100" style="padding-left: 0px !important;">
<div style="padding: 10px; width: 100%; border-bottom: 2.5px solid #fff; margin-bottom: 3.5px"></div>
<h2 class="mb-1">Heading</h2>
<p>This is a preview!</p>
</div>
</div>
</div>
-->
<hr class="mt-2 mb-3">
<label>Save Theme to JSON</label>
<div class="row">
<div class="col">
<input id="SaveThemeToJSONInput" type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true" disabled>
</div>
<div class="col-auto">
<button id="CopyThemeJSONBtn" class="btn btn-warning"><i class="fa-duotone fa-clipboard"></i></button>
</div>
</div>
<label>Load Theme from JSON</label>
<input type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true">
<button id="LoadThemeFromJSONBtn" class="btn btn-primary mb-2" data-ignore="true" data-onclick="LoadThemeJSON(this.previousElementSibling.value)">Load</button>
<hr class="mt-2 mb-3">
<div class="card mb-2">
<div class="card-header">Navigation</div>
<div class="card-body">
<label>Navbar Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavBGColor">
<label>Navbar Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavBorderColor">
<label>Sidebar Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideBGColor">
<label>Sidebar Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideBorderColor">
<hr class="navbar-divider">
<label>Navbar Item Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavItemColor">
<label>Sidebar Item Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemBGColor">
<label>Sidebar Item Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemBorderColor">
<label>Sidebar Item Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemColor">
<label>Sidebar Item Label Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemLabelColor">
</div>
</div>
<div class="card mb-2">
<div class="card-header">Background</div>
<div class="card-body">
<label>Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="BGColor">
<label>Background Image (URL)</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="BGImage">
<label>Background Image Size (if there is a background image)</label>
<select class="form-select bg-dark mb-2" data-setting="BGImageSize">
<option value="fit" selected>Fit (default)</option>
<option value="cover">Cover</option>
<option value="contain">Contain</option>
</select>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Text</div>
<div class="card-body">
<label>Primary Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="PrimaryTextColor">
<label>Secondary Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SecondaryTextColor">
<div class="row">
<div class="col">
<label>Link (state: default) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkTextColor">
</div>
<div class="col">
<label>Link (state: hovered) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkHoveredTextColor">
</div>
<div class="col">
<label>Link (state: focused) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkFocusedTextColor">
</div>
<!--
<div class="col">
<label>Link (state: visited) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkVisitedTextColor">
</div>
-->
</div>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Cards</div>
<div class="card-body">
<label>Card (Header) Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardHeadBGColor">
<label>Card (Body) Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardBodyBGColor">
<label>Card Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardBorderColor">
</div>
</div>
<div class="card mb-2">
<div class="card-header">Branding</div>
<div class="card-body">
<label>Website Logo (URL)</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="WebsiteLogo">
</div>
</div>
<button class="btn btn-success" data-setting="[save]">Save</button>
<button class="btn btn-secondary" data-setting="[cancel]">Cancel</button>
</div>
</dialog>
<dialog class="w-50" id="ModifyNav-Modal" data-setting="ModifyNav">
<div class="modal-header">
<p>Modify Navbar</p>
</div>
<div class="modal-body">
<p>Customize the navbar to your liking!</p>
<hr class="mt-2 mb-3">
<div class="card mb-2">
<div class="card-header">#1 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-1Label" class="form-control bg-dark mb-2" placeholder="Play" data-parent="0" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-1Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/places/" data-parent="0" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#2 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-2Label" class="form-control bg-dark mb-2" placeholder="Store" data-parent="1" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-2Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/store/" data-parent="1" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#3 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-3Label" class="form-control bg-dark mb-2" placeholder="Guilds" data-parent="2" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-3Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/guilds/" data-parent="2" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#4 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-4Label" class="form-control bg-dark mb-2" placeholder="People" data-parent="3" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-4Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/users/" data-parent="3" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#5 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-5Label" class="form-control bg-dark mb-2" placeholder="Forum" data-parent="4" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-5Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/forum" data-parent="4" data-setting="Link">
</div>
</div>
<button id="ModifyNav-Modal-Save" class="btn btn-success" data-setting="[save]">Save</button>
<button id="ModifyNav-Modal-Save" class="btn btn-secondary" data-setting="[cancel]">Cancel</button>
</div>
</dialog>
<div>
<p id="PinnedGames">
<span>
Pinned Games (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="PinnedGamesOn">Toggle</button>
</span>
<br>
<span class="desc">Pin your favorite games to the top of the homepage!</span>
</p>
<p id="ForumMentions">
<span>
Forum Mentions (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ForumMentsOn">Toggle</button>
</span>
<br>
<span class="desc">Get a quick link to the popular person everyone is talking about's profile!</span>
</p>
<p id="BestFriends">
<span>
Best Friends (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="BestFriendsOn">Toggle</button>
</span>
<br>
<span class="desc">Prioritize the bestest of friends on applicable friend lists!</span>
</p>
<p id="ImprovedFriendLists">
<span>
Improved Friend Lists (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ImprovedFrListsOn">Toggle</button>
</span>
<br>
<span class="desc">
Accept or decline all friend requests with the click of a button or multi-remove existing friends!
<br>
<span style="font-size: 0.8rem; color: orange;">* You can only remove up to 25 friends at once.</span>
</span>
</p>
<p id="IRLPriceWithCurrency">
<span>
Show IRL price with Brick Count (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="IRLPriceWithCurrencyOn">Toggle</button>
</span>
<br>
<span class="desc mb-4">
See the real life currency value along with Bricks across the site!
<br>
<span style="font-size: 0.8rem; color: orange;">* Currencies were calculated on [DATE].</span>
<br>
<span style="font-size: 0.8rem; color: orange;">* Currencies other than USD are purely approximations.</span>
</span>
<select id="IRLPriceWithCurrencyCurrency" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="IRLPriceWithCurrencyCurrency">
<option value="USD" selected>United States Dollar (USD)</option>
<option value="EUR">Euro (EUR)</option>
<option value="CAD">Canadian Dollar (CAD)</option>
<option value="GBP">Great British Pound (GBP)</option>
<option value="MXN">Mexican Peso (MXN)</option>
<option value="AUD">Australian Dollar (AUD)</option>
<option value="TRY">Turkish Lira (TRY)</option>
</select>
<select id="IRLPriceWithCurrencyPackage" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="IRLPriceWithCurrencyPackage">
<option value="0" selected>$0.99 USD</option>
<option value="1">$4.99 USD</option>
<option value="2">$9.99 USD</option>
<option value="3">$24.99 USD</option>
<option value="4">$49.99 USD</option>
<option value="5">$99.99 USD</option>
</select>
</p>
<p id="HideNotifBadges">
<span>
Hide Notification Badges (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="HideNotifBadgesOn">Toggle</button>
</span>
<br>
<span class="desc">Hide the annoying red circles on the sidebar!</span>
</p>
<p id="SimplifiedProfileURLs">
<span>
Simplified Profile URLs (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="SimplifiedProfileURLsOn">Toggle</button>
</span>
<br>
<span class="desc">Makes all profile URLs simpler by allowing for you to go to "https://polytoria.com/profile/UsernameGoesHere" to redirect to the real profile URL!</span>
</p>
<p id="StoreOwnTag">
<span>
Show "OWNED" Tag on Store Main Page (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="StoreOwnTagOn">Toggle</button>
</span>
<br>
<span class="desc">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!</span>
</p>
<p id="ThemeCreator">
<span>
Theme Creator (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ThemeCreatorOn">Toggle</button>
<button id="ThemeCreator-Options" class="btn btn-primary btn-sm" data-modal="ThemeCreator">Options</button>
</span>
<br>
<span class="desc">Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development)</span>
</p>
<p id="MoreSearchFilters">
<span>
More Search Filters (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="MoreSearchFiltersOn">Toggle</button>
</span>
<br>
<span class="desc">Easily find what you're looking for with more search filters side-wide! (this does not affect the main site search on the navbar)</span>
</p>
<p id="ApplyMembershipTheme">
<span>
Apply Membership Theme for <b>Free</b> (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ApplyMembershipThemeOn">Toggle</button>
</span>
<br>
<span class="desc">Ever want the fancy membership themes for completely <b>free</b>? Well now you can get apply them site-wide!</span>
<select id="ApplyMembershipThemeTheme" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="ApplyMembershipThemeTheme">
<option value="Plus" selected>Plus</option>
<option value="PlusDX">Plus Deluxe</option>
</select>
</p>
<p id="ForumMarkdown" style="display: none;">
<span>
Forum Markdown (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ForumMarkOn">Toggle</button>
</span>
<br>
<span class="desc">
Format forum posts to make them look epic!
</span>
</p>
<p id="MultiCancelOutTrades">
<span>
Multi-Cancel Outbound Trades (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="MultiCancelOutTradesOns">Toggle</button>
</span>
<br>
<span class="desc">
Quickly cancel several out-bound trades (trades that you have sent) all at once
<br>
<span style="font-size: 0.8rem; color: orange;">* You can only cancel up to 10 trades at once.</span>
</span>
</p>
<p id="ModifyNav">
<span>
Modify Navbar (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ModifyNavOn">Toggle</button>
<button id="ModifyNav-Options" class="btn btn-primary btn-sm" data-modal="ModifyNav">Options</button>
</span>
<br>
<span class="desc">
Customize the navbar to your liking!
</span>
</p>
<p id="ItemWishlist">
<span>
Item Wishlist (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ItemWishlistOn">Toggle</button>
</span>
<br>
<span class="desc">
Wishlist that item that you REALLY want!
</span>
</p>
<p id="HideUpgradeBtn">
<span>
Hide Upgrade Button (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="HideUpgradeBtnOn">Toggle</button>
</span>
<br>
<span class="desc">Hide the ugly blue "Upgrade" button on the sidebar!</span>
</p>
<hr>
<button id="Save" class="btn btn-primary" disabled="true">Save</button>
<button id="ResetDefaults" class="btn btn-warning">Reset to Default Settings</button>
<p class="text-muted mt-2" style="font-size: 0.8rem;">made by Index</p>
</div>
`;
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();
}
}
});

View file

@ -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) {
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()
});
}
});
// 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 || [];
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 = `
<i class="fa-duotone fa-book"></i>
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.')
});
});
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)'
}
});
}
});
/*
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() {
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)
});
}
function ClearFavsOld(){
chrome.storage.sync.set({ 'PolyPlus': {"PinnedGames": pinnedGames, "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) ? '~' : '' }<i class="pi pi-brick me-2"></i> ${TotalCost.toLocaleString()}${ (Limiteds > 0) ? ` (has ${Limiteds} limiteds)` : '' }${ (Exclusives > 0) ? ` (has ${Exclusives} exclusives)` : '' }`
TotalCostText.innerHTML = `${ (AvatarCost.Limiteds > 0 || AvatarCost.Exclusives > 0) ? '~' : '' }<i class="pi pi-brick me-2"></i> ${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)
}

View file

@ -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;
}

View file

@ -1,883 +0,0 @@
document.body.innerHTML = `
<style>
#page {
margin-top: 7.5rem;
}
h1 {
font-size: 4.6rem;
color: rgb(48, 48, 48);
}
h1 span.indent {
border-left: 10px solid rgb(48, 48, 48);
margin-right: 15px;
}
h1 span.highlight {
color: red;
}
h2 {
color: rgb(48, 48, 48);
}
h2 span.indent {
border-left: 7.5px solid rgb(48, 48, 48);
margin-right: 15px;
}
p span:first-child {
font-size: 1.4rem;
}
span.desc {
color: rgb(120, 120, 120);
}
.goback {
color: rgb(120, 120, 120);
text-decoration: none;
}
dialog {
background-color: #080808;
color: #c4c4c4;
border: 1px solid #3bafff;
border-radius: 10px;
}
.input-group-text {
background-color: #000;
border-color: #000;
color: #fff;
}
label {
font-size: 0.8rem;
margin-bottom: 2.75px;
}
dialog::backdrop {
background-color: rgba(0, 0, 0, 0.73);
}
dialog .modal-header p {
margin-bottom: 0px;
color: #fff;
}
dialog .modal-body p:first-child {
font-size: 0.9rem;
}
/*
p span span.status {
font-size: 0.16rem !important;
color: #cee;
}
*/
</style>
<dialog class="w-50" id="ResetDefaults-Modal">
<div class="modal-header">
<p>Are you Sure?</p>
</div>
<div class="modal-body">
<p>Are you sure you'd like to reset all settings to their respective defaults? (this action is irreversible)</p>
<button id="ResetDefaults-Modal-Yes" class="btn btn-danger">Yes</button>
<button id="ResetDefaults-Modal-No" class="btn btn-primary">No</button>
</div>
</dialog>
<dialog class="w-50" id="ThemeCreator-Modal" data-setting="ThemeCreator">
<div class="modal-header">
<p>Theme Creator</p>
</div>
<div class="modal-body">
<p>Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development)</p>
<!--
<div class="mx-auto" style="width: 450px; height: 350px; border: 2.5px solid #fff;">
<div class="row h-100">
<div class="col-md-1 h-100" style="padding: 25px; border-right: 2.5px solid #fff; padding-left: 0px !important;"></div>
<div class="col h-100" style="padding-left: 0px !important;">
<div style="padding: 10px; width: 100%; border-bottom: 2.5px solid #fff; margin-bottom: 3.5px"></div>
<h2 class="mb-1">Heading</h2>
<p>This is a preview!</p>
</div>
</div>
</div>
-->
<hr class="mt-2 mb-3">
<label>Save Theme to JSON</label>
<div class="row">
<div class="col">
<input id="SaveThemeToJSONInput" type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true" disabled>
</div>
<div class="col-auto">
<button id="CopyThemeJSONBtn" class="btn btn-warning"><i class="fa-duotone fa-clipboard"></i></button>
</div>
</div>
<label>Load Theme from JSON</label>
<input type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true">
<button id="LoadThemeFromJSONBtn" class="btn btn-primary mb-2" data-ignore="true" data-onclick="LoadThemeJSON(this.previousElementSibling.value)">Load</button>
<hr class="mt-2 mb-3">
<div class="card mb-2">
<div class="card-header">Navigation</div>
<div class="card-body">
<label>Navbar Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavBGColor">
<label>Navbar Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavBorderColor">
<label>Sidebar Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideBGColor">
<label>Sidebar Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideBorderColor">
<hr class="navbar-divider">
<label>Navbar Item Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="NavItemColor">
<label>Sidebar Item Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemBGColor">
<label>Sidebar Item Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemBorderColor">
<label>Sidebar Item Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemColor">
<label>Sidebar Item Label Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SideItemLabelColor">
</div>
</div>
<div class="card mb-2">
<div class="card-header">Background</div>
<div class="card-body">
<label>Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="BGColor">
<label>Background Image (URL)</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="BGImage">
<label>Background Image Size (if there is a background image)</label>
<select class="form-select bg-dark mb-2" data-setting="BGImageSize">
<option value="fit" selected>Fit (default)</option>
<option value="cover">Cover</option>
<option value="contain">Contain</option>
</select>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Text</div>
<div class="card-body">
<label>Primary Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="PrimaryTextColor">
<label>Secondary Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="SecondaryTextColor">
<div class="row">
<div class="col">
<label>Link (state: default) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkTextColor">
</div>
<div class="col">
<label>Link (state: hovered) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkHoveredTextColor">
</div>
<div class="col">
<label>Link (state: focused) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkFocusedTextColor">
</div>
<!--
<div class="col">
<label>Link (state: visited) Text Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="LinkVisitedTextColor">
</div>
-->
</div>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Cards</div>
<div class="card-body">
<label>Card (Header) Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardHeadBGColor">
<label>Card (Body) Background Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardBodyBGColor">
<label>Card Border Color</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="CardBorderColor">
</div>
</div>
<div class="card mb-2">
<div class="card-header">Branding</div>
<div class="card-body">
<label>Website Logo (URL)</label>
<input class="form-control bg-dark mb-2" placeholder="..." data-setting="WebsiteLogo">
</div>
</div>
<button class="btn btn-success" data-setting="[save]">Save</button>
<button class="btn btn-secondary" data-setting="[cancel]">Cancel</button>
</div>
</dialog>
<dialog class="w-50" id="ModifyNav-Modal" data-setting="ModifyNav">
<div class="modal-header">
<p>Modify Navbar</p>
</div>
<div class="modal-body">
<p>Customize the navbar to your liking!</p>
<hr class="mt-2 mb-3">
<div class="card mb-2">
<div class="card-header">#1 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-1Label" class="form-control bg-dark mb-2" placeholder="Play" data-parent="0" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-1Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/places/" data-parent="0" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#2 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-2Label" class="form-control bg-dark mb-2" placeholder="Store" data-parent="1" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-2Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/store/" data-parent="1" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#3 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-3Label" class="form-control bg-dark mb-2" placeholder="Guilds" data-parent="2" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-3Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/guilds/" data-parent="2" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#4 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-4Label" class="form-control bg-dark mb-2" placeholder="People" data-parent="3" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-4Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/users/" data-parent="3" data-setting="Link">
</div>
</div>
<div class="card mb-2">
<div class="card-header">#5 Navbar Item</div>
<div class="card-body">
<label>Label</label>
<input id="ModifyNav-Modal-5Label" class="form-control bg-dark mb-2" placeholder="Forum" data-parent="4" data-setting="Label">
<label>Link</label>
<input id="ModifyNav-Modal-5Link" class="form-control bg-dark mb-2" placeholder="https://polytoria.com/forum" data-parent="4" data-setting="Link">
</div>
</div>
<button id="ModifyNav-Modal-Save" class="btn btn-success" data-setting="[save]">Save</button>
<button id="ModifyNav-Modal-Save" class="btn btn-secondary" data-setting="[cancel]">Cancel</button>
</div>
</dialog>
<div id="page" class="container w-75 mx-auto">
<a class="goback" onclick="history.back();"><- go back</a>
<h1><span class="indent"></span>Poly<span class="highlight">+</span> Settings</h1>
<h2><span class="indent"></span> [CategoryName]</h2>
<p id="PinnedGames">
<span>
Pinned Games (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="PinnedGamesOn">Toggle</button>
</span>
<br>
<span class="desc">Pin your favorite games to the top of the homepage!</span>
</p>
<p id="ForumMentions">
<span>
Forum Mentions (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ForumMentsOn">Toggle</button>
</span>
<br>
<span class="desc">Get a quick link to the popular person everyone is talking about's profile!</span>
</p>
<p id="BestFriends">
<span>
Best Friends (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="BestFriendsOn">Toggle</button>
</span>
<br>
<span class="desc">Prioritize the bestest of friends on applicable friend lists!</span>
</p>
<p id="ImprovedFriendLists">
<span>
Improved Friend Lists (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ImprovedFrListsOn">Toggle</button>
</span>
<br>
<span class="desc">
Accept or decline all friend requests with the click of a button or multi-remove existing friends!
<br>
<span style="font-size: 0.8rem; color: orange;">* You can only remove up to 25 friends at once.</span>
</span>
</p>
<p id="IRLPriceWithCurrency">
<span>
Show IRL price with Brick Count (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="IRLPriceWithCurrencyOn">Toggle</button>
</span>
<br>
<span class="desc mb-4">
See the real life currency value along with Bricks across the site!
<br>
<span style="font-size: 0.8rem; color: orange;">* Currencies were calculated on [DATE].</span>
<br>
<span style="font-size: 0.8rem; color: orange;">* Currencies other than USD are purely approximations.</span>
</span>
<select id="IRLPriceWithCurrencyCurrency" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="IRLPriceWithCurrencyCurrency">
<option value="USD" selected>United States Dollar (USD)</option>
<option value="EUR">Euro (EUR)</option>
<option value="CAD">Canadian Dollar (CAD)</option>
<option value="GBP">Great British Pound (GBP)</option>
<option value="MXN">Mexican Peso (MXN)</option>
<option value="AUD">Australian Dollar (AUD)</option>
<option value="TRY">Turkish Lira (TRY)</option>
</select>
<select id="IRLPriceWithCurrencyPackage" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="IRLPriceWithCurrencyPackage">
<option value="0" selected>$0.99 USD</option>
<option value="1">$4.99 USD</option>
<option value="2">$9.99 USD</option>
<option value="3">$24.99 USD</option>
<option value="4">$49.99 USD</option>
<option value="5">$99.99 USD</option>
</select>
</p>
<p id="HideNotifBadges">
<span>
Hide Notification Badges (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="HideNotifBadgesOn">Toggle</button>
</span>
<br>
<span class="desc">Hide the annoying red circles on the sidebar!</span>
</p>
<p id="SimplifiedProfileURLs">
<span>
Simplified Profile URLs (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="SimplifiedProfileURLsOn">Toggle</button>
</span>
<br>
<span class="desc">Makes all profile URLs simpler by allowing for you to go to "https://polytoria.com/profile/UsernameGoesHere" to redirect to the real profile URL!</span>
</p>
<p id="StoreOwnTag">
<span>
Show "OWNED" Tag on Store Main Page (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="StoreOwnTagOn">Toggle</button>
</span>
<br>
<span class="desc">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!</span>
</p>
<p id="ThemeCreator">
<span>
Theme Creator (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ThemeCreatorOn">Toggle</button>
<button id="ThemeCreator-Options" class="btn btn-primary btn-sm" data-modal="ThemeCreator">Options</button>
</span>
<br>
<span class="desc">Unleash your creativity and customize the Polytoria website to your liking! (this feature is still in development)</span>
</p>
<p id="MoreSearchFilters">
<span>
More Search Filters (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="MoreSearchFiltersOn">Toggle</button>
</span>
<br>
<span class="desc">Easily find what you're looking for with more search filters side-wide! (this does not affect the main site search on the navbar)</span>
</p>
<p id="ApplyMembershipTheme">
<span>
Apply Membership Theme for <b>Free</b> (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ApplyMembershipThemeOn">Toggle</button>
</span>
<br>
<span class="desc">Ever want the fancy membership themes for completely <b>free</b>? Well now you can get apply them site-wide!</span>
<select id="ApplyMembershipThemeTheme" class="form-select form-select-sm mb-2" style="width:350px;" data-setting="ApplyMembershipThemeTheme">
<option value="Plus" selected>Plus</option>
<option value="PlusDX">Plus Deluxe</option>
</select>
</p>
<p id="ForumMarkdown" style="display: none;">
<span>
Forum Markdown (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ForumMarkOn">Toggle</button>
</span>
<br>
<span class="desc">
Format forum posts to make them look epic!
</span>
</p>
<p id="MultiCancelOutTrades">
<span>
Multi-Cancel Outbound Trades (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="MultiCancelOutTradesOns">Toggle</button>
</span>
<br>
<span class="desc">
Quickly cancel several out-bound trades (trades that you have sent) all at once
<br>
<span style="font-size: 0.8rem; color: orange;">* You can only cancel up to 10 trades at once.</span>
</span>
</p>
<p id="ModifyNav">
<span>
Modify Navbar (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ModifyNavOn">Toggle</button>
<button id="ModifyNav-Options" class="btn btn-primary btn-sm" data-modal="ModifyNav">Options</button>
</span>
<br>
<span class="desc">
Customize the navbar to your liking!
</span>
</p>
<p id="ItemWishlist">
<span>
Item Wishlist (<span class="status">enabled</span>)
<button class="btn btn-warning btn-sm" data-setting="ItemWishlistOn">Toggle</button>
</span>
<br>
<span class="desc">
Wishlist that item that you REALLY want!
</span>
</p>
<p id="HideUpgradeBtn">
<span>
Hide Upgrade Button (<span class="status">disabled</span>)
<button class="btn btn-warning btn-sm" data-setting="HideUpgradeBtnOn">Toggle</button>
</span>
<br>
<span class="desc">Hide the ugly blue "Upgrade" button on the sidebar!</span>
</p>
<hr>
<button id="Save" class="btn btn-primary" disabled="true">Save</button>
<button id="ResetDefaults" class="btn btn-warning">Reset to Default Settings</button>
<p class="text-muted mt-2" style="font-size: 0.8rem;">made by Index</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
`;
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();
}

View file

@ -1,13 +1,57 @@
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){
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'))) {
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 || [];
if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) {
WishlistBtn.classList = 'btn btn-danger btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Un-Wishlist Item
`
} else {
if (!(ItemWishlist.length === 25)) {
WishlistBtn.removeAttribute('disabled')
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
} else {
WishlistBtn.setAttribute('disabled', true)
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
}
}
});
}
});
function IRLPrice() {
if (!(PurchaseBtn.getAttribute('disabled'))) {
let Price = PurchaseBtn.getAttribute('data-price').replace(/,/g, '')
let Span = document.createElement('span')
@ -49,10 +93,10 @@ setTimeout(function () {
Span.innerText = "($" + IRL + " " + DISPLAY + ")"
PurchaseBtn.appendChild(Span)
}
}
}
if (Settings.ItemWishlistOn === true && !(PurchaseBtn.getAttribute('disabled'))) {
let DescriptionText = document.querySelector('.card-text')
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 || [];
@ -70,13 +114,6 @@ setTimeout(function () {
}
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 || [];
@ -103,37 +140,9 @@ setTimeout(function () {
}, 1250)
});
});
}
});
}
})
}, 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 || [];
if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) {
WishlistBtn.classList = 'btn btn-danger btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Un-Wishlist Item
`
} else {
if (!(ItemWishlist.length === 25)) {
WishlistBtn.removeAttribute('disabled')
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
} else {
WishlistBtn.setAttribute('disabled', true)
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
}
}
DescriptionText.appendChild(document.createElement('br'))
DescriptionText.appendChild(WishlistBtn)
});
}
});
}

View file

@ -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 + ` <span style="color: orange;">(${parseInt(HauntedStudsCount.innerText) / 8} candies)</style>`
}
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 + `<br><span style="color: orange;">(${parseFloat(_HauntedStudsCount.innerText.replace(/,/g, '')) / 8} candies)</span>`
});
}

View file

@ -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/*"]
}
],

View file

@ -1,7 +1,7 @@
<html>
<head>
<title>Poly+ Settings</title>
<link rel="stylesheet" href="https://c0.ptacdn.com/static/app.0e097f99.css">
<link rel="stylesheet" href="https://c0.ptacdn.com/static/app.64aa42f6.css">
</head>
<body data-bs-theme="dark">
<style>