quality of life improvements and 1 new feature

- added expanding of messages on the inbox page to quickly see the entire message content (maybe add quick reply feature too?)

- local settings page now uses Polytoria's CSS and isn't weird anymore

- clicking on the extension now opens the settings page instead of a old popup menu

- added debug menu at /my/settings/polyplus-debug to quickly clear all pinned games, clear all best friends, and quick editing of a setting's value

- simplified profile URLs are no longer a setting and are on by default (haven't fully deleted the settings code only deleted the if statement checking if it's enabled)

- simplified profile URLs now have an optional reference URL parameter to fall back on if the user doesn't exist (may replace with history.back or whatever the function is to go to the last location history page)

- forum mentions have been rewritten and no longer require ID caching because they use simplified profile URLs so the user ID is only fetcehd if you click on the URL if the user doesn't exist it sends you back to the forum post. the code is also now way shorter and simpler

- removed "Launch Creator" button because it has been re-added officially

- work in progress unix timestamp markdown for forum posts (not working right now for some reason will fix soon)

- small changes that I'm too lazy to list here
This commit is contained in:
Index 2024-01-23 17:27:49 -06:00
parent a6e742756a
commit 3e01832005
18 changed files with 548 additions and 280 deletions

View file

@ -11,7 +11,7 @@ body[data-URL^="https://polytoria.com/create/"] .col.d-flex.align-content-betwee
} }
.text-truncate { .text-truncate {
white-space: nowrap !important; /* Prevents text from wrapping to the next line */ white-space: nowrap !important;
overflow: hidden !important; /* Hides the overflowing text */ overflow: hidden !important;
text-overflow: ellipsis !important; /* Adds an ellipsis (...) to indicate truncated text */ text-overflow: ellipsis !important;
} }

View file

@ -1,7 +0,0 @@
let NavColumn = document.getElementsByClassName('col-lg-2')[0]
let LaunchCreatorBtn = document.createElement('button')
LaunchCreatorBtn.classList = 'btn btn-success w-100'
LaunchCreatorBtn.innerText = 'Launch Creator'
LaunchCreatorBtn.setAttribute('data-id', '1')
LaunchCreatorBtn.setAttribute('onclick', 'editPlace(this)')
NavColumn.appendChild(LaunchCreatorBtn)

47
js/account/inbox.js Normal file
View file

@ -0,0 +1,47 @@
HandleExpandMessages()
function HandleExpandMessages() {
const Messages = document.getElementById('messages')
for (let message of Messages.children) {
let Expanded = false
let ContentDiv = null
const ViewButton = message.querySelector('a.btn[href^="/inbox/messages"]')
const MessageID = ViewButton.getAttribute('href').split('/')[3]
const ExpandButton = document.createElement('button')
ExpandButton.classList = 'btn btn-outline-warning px-4 mt-1'
ExpandButton.innerText = 'Expand'
ViewButton.parentElement.appendChild(ExpandButton)
ExpandButton.addEventListener('click', function(){
if (ContentDiv === null) {
fetch('https://polytoria.com/inbox/messages/'+MessageID)
.then(response => {
if (!response.ok) {
throw new Error('Network not ok')
}
return response.text()
})
.then(data => {
const Doc = new DOMParser().parseFromString(data, 'text/html')
const MessageContent = Doc.querySelector('p.mb-0').innerText
ContentDiv = document.createElement('div')
ContentDiv.classList = 'py-2'
ContentDiv.innerText = MessageContent
message.appendChild(ContentDiv)
})
.catch(error => {
console.log(error)
});
}
Expanded = !Expanded
ExpandButton.innerText = (Expanded === false) ? 'Expand' : 'Minimize'
ContentDiv.style.display = (Expanded === false) ? 'none' : 'block'
});
}
}

View file

@ -1,3 +1,57 @@
const Manifest = chrome.runtime.getManifest()
// WHEN CLICKING ON EXTENSION ICON OPEN THE SETTINGS PAGE
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.create({ active: true, url: chrome.runtime.getURL('settings.html') });
});
// REGISTER AN ALARM FOR DAILY UPDATE CHECK
/*
chrome.alarms.create("PolyPlus-UpdateCheck", {
periodInMinutes: 24 * 60,
when: Date.now() + (12 - new Date().getHours()) * 60 * 60 * 1000,
});
*/
// Create a date object with the current date and the desired time
/*
var date = new Date();
date.setHours(19, 31, 0, 0); // 7:25 PM
// Create an alarm that fires at 7:25 PM and repeats every day
chrome.alarms.create("PolyPlus-UpdateCheck", {
periodInMinutes: 24 * 60,
when: date.getTime()
});
*/
// HANDLE ALARMS FIRING
chrome.alarms.onAlarm.addListener(function(alarm){
if (alarm.name === 'PolyPlus-UpdateCheck') {
fetch('https://polyplus.vercel.app/data/version.json')
.then(response => {
if (!response.ok) {
throw new Error('Network not ok')
}
return response.json()
})
.then(data => {
if (data.version > Manifest.version) {
console.log('Update available')
chrome.notifications.create({
type: "basic",
iconUrl: chrome.runtime.getURL("icon.png"),
title: "New Update Available",
message: "A new update is available for Poly+!",
})
}
})
.catch(error => {console.log(error)})
}
});
// COPY ASSET ID CONTEXT MENU ITEM REGISTRATION
chrome.contextMenus.create({ chrome.contextMenus.create({
title: 'Copy Asset ID', title: 'Copy Asset ID',
id: 'PolyPlus-CopyID', id: 'PolyPlus-CopyID',
@ -10,6 +64,7 @@ chrome.contextMenus.create({
] ]
}); });
// COPY AVATAR HASH CONTEXT MENU ITEM REGISTRATION
chrome.contextMenus.create({ chrome.contextMenus.create({
title: 'Copy Avatar Hash', title: 'Copy Avatar Hash',
id: 'PolyPlus-CopyAvatarHash', id: 'PolyPlus-CopyAvatarHash',
@ -21,6 +76,7 @@ chrome.contextMenus.create({
] ]
}); });
// HANDLE CONTEXT MENU ITEMS
chrome.contextMenus.onClicked.addListener(function (info, tab){ chrome.contextMenus.onClicked.addListener(function (info, tab){
if (info.menuItemId === 'PolyPlus-CopyID') { if (info.menuItemId === 'PolyPlus-CopyID') {
let ID = parseInt(info.linkUrl.split('/')[4]) let ID = parseInt(info.linkUrl.split('/')[4])
@ -45,21 +101,6 @@ chrome.contextMenus.onClicked.addListener(function (info, tab){
} }
}); });
/*
chrome.webNavigation.onCompleted.addListener(function (details){
console.log('TAB CREATED')
chrome.scripting
.executeScript({
target: {tabId: details.tabId},
func: HandleJoinPlace,
args: [details.url]
})
}, {
url: [{ urlMatches: "https://polytoria.com/join-place/*" }]
});
*/
function CopyAssetID(id) { function CopyAssetID(id) {
navigator.clipboard navigator.clipboard
.writeText(id) .writeText(id)
@ -102,4 +143,8 @@ function HandleJoinPlace(url) {
window.location.href = 'polytoria://client/' + data.token window.location.href = 'polytoria://client/' + data.token
}) })
.catch(error => {console.log(error)}) .catch(error => {console.log(error)})
}
export default {
hi: 1
} }

53
js/debug.js Normal file
View file

@ -0,0 +1,53 @@
// DEBUG MENU FOR CLEARING PINNED GAMES AND BEST FRIENDS
document.querySelector('#main-content .container').innerHTML = `
<button class="btn btn-warning" id="clear-pins">Clear Pinned Games</button>
<br>
<button class="btn btn-warning" id="clear-bf">Clear Best Friends</button>
<br>
<label for="settingName">Edit Setting Value</label>
<div class="input-group">
<input type="text" name="settingName" id="edit-setting-name" class="form-control" placeholder="Setting Name..">
<input type="text" id="edit-setting-value" class="form-control" placeholder="New Value..">
<button class="btn btn-warning" id="edit-setting">Submit</button>
</div>
`
const ClearPins = document.getElementById('clear-pins')
const ClearBF = document.getElementById('clear-bf')
const EditSettingName = document.getElementById('edit-setting-name')
const EditSettingValue = document.getElementById('edit-setting-value')
const EditSettingBtn = document.getElementById('edit-setting')
ClearPins.addEventListener('click', function(){
chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() {
alert('Successfully cleared Pinned Games.')
});
});
ClearBF.addEventListener('click', function(){
chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() {
alert('Successfully cleared Best Friends.')
});
});
EditSettingBtn.addEventListener('click', function(){
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
result = result.PolyPlus_Settings
let NewValue = EditSettingValue.value
if (NewValue === "true") {NewValue = true}
if (NewValue === "false") {NewValue = false}
if (parseInt(NewValue)) {NewValue = parseInt(NewValue)}
result[EditSettingName.value] = NewValue
chrome.storage.sync.set({ 'PolyPlus_Settings': result }, function() {
alert('Successfully set: "' + EditSettingName.value + '" to ' + NewValue)
});
alert('Successfully cleared Best Friends.')
});
});

173
js/forum/forum-view-old.js Executable file
View file

@ -0,0 +1,173 @@
var idCache = []
let url = "https://polytoria.com/users/:id"
console.log('loaded!')
function LowAttentionSpanMode() {
let PostContent = document.querySelector('.mcard p:nth-child(3)').textContent
let Captions = CombineArray(PostContent.split(' ')).map((x, i) => `<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;
}

220
js/forum/forum-view.js Executable file → Normal file
View file

@ -1,173 +1,47 @@
var idCache = [] const ForumText = document.querySelectorAll('p:not(.text-muted):not(.mb-0)')
let url = "https://polytoria.com/users/:id"
var Settings = []
console.log('loaded!') chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
Settings = result.PolyPlus_Settings || []
function LowAttentionSpanMode() {
let PostContent = document.querySelector('.mcard p:nth-child(3)').textContent if (Settings.ForumMentsOn === true || 1 === 2) {
let Captions = CombineArray(PostContent.split(' ')).map((x, i) => `<span data-index="${i}" style="display: none;">${x}</span>`).join('') HandleForumMentions()
let NumberOfCaptions = (PostContent.split(' ').length) - 1 }
Swal.fire({
title: "No Attention Span Mode", if (1 === 1) {
html: ` HandleUnixTimestamps()
<video src="${chrome.runtime.getURL('low-attention-span.mp4')}" loop autoplay muted play> }
<div id="polyplus-captions">${Captions}</div> });
`
}); function HandleForumMentions() {
let CaptionsElement = document.getElementById('polyplus-captions') const Regex = /@([\w.]+)/g
let Index = 0 for (let text of ForumText) {
//LoopIteration() let FormattedText = text.innerHTML
let match;
function LoopIteration() { while ((match = Regex.exec(text.innerText)) !== null) {
Array.from(CaptionsElement.children).forEach(element => { const Username = match[0].substring(1)
element.style.display = 'none' FormattedText = FormattedText.replaceAll(match[0], `<a href="/profile/reufihfuighqre8uogqre?ref=${encodeURIComponent(window.location.pathname)}" class="polyplus-mention">${match[0]}</a>`)
}); }
if (CaptionsElement.children[Index] === undefined) { text.innerHTML = FormattedText
Swal.close() }
return }
}
CaptionsElement.children[Index].style.display = 'block' function HandleUnixTimestamps() {
setTimeout(function () { const Regex = /<t:[A-Za-z0-9]+>/gm
console.log(Index, 'Next Caption') //const Regex = /&lt;t:[A-Za-z0-9]+&gt;/i
Index++
LoopIteration() for (let text of ForumText) {
}, 1100) //let FormattedText = text.innerHTML
} let match;
while ((match = Regex.exec(text.innerText)) !== null) {
function CombineArray(arr) { console.log(match[0])
let CombinedArray = []; const Timestamp = new Date(parseInt(match[0].substring(3).slice(0, -1))*1000)
let CurrentCombinedItem = ""; const Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for (let i = 0; i < arr.length; i++) { const Result = `${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()}`
if ((CurrentCombinedItem + " " + arr[i]).length <= 6) { text.innerHTML = text.innerText.replaceAll(Regex.exec(text.innerText)[0], Result)
if (CurrentCombinedItem !== "") { }
CurrentCombinedItem += " "; //text.innerHTML = FormattedText
} }
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,22 +0,0 @@
var Settings = []
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
Settings = result.PolyPlus_Settings || []
if (Settings.ForumMentsOn === true || 1 === 1) {
HandleForumMentions()
}
});
function HandleForumMentions() {
const ForumText = document.querySelectorAll('p:not(.text-muted):not(.mb-0)')
const IDCache = {}
for (let text of ForumText) {
if (/@([\w.]+)/g.test(text.innerText) === true) {
const FormattedText = text.innerText.replace(/@([\w.]+)/g, '<a href="#" class="polyplus-mention">@$1</a>')
console.log(FormattedText)
fetch('https://api.polytoria.com/v1/users/find?username=')
}
}
}

View file

@ -1,7 +1,7 @@
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Settings = result.PolyPlus_Settings; Settings = result.PolyPlus_Settings || [];
if (Settings.ApplyMembershipThemeOn === false) {return} if (Settings.ApplyMembershipThemeOn !== true) {return}
MembershipTheme = Settings.ApplyMembershipThemeTheme === 0 ? 'plus': 'plusdx' MembershipTheme = Settings.ApplyMembershipThemeTheme === 0 ? 'plus': 'plusdx'
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){

View file

@ -32,8 +32,10 @@
}) })
.then(data => { .then(data => {
if (data.success !== true) {throw new Error(data.message)} if (data.success !== true) {throw new Error(data.message)}
window.location.href = 'polytoria://client/' + data.token setTimeout(function(){
window.location.href = 'https://polytoria.com/places/' + PlaceID window.location.href = 'polytoria://client/' + data.token
window.location.href = 'https://polytoria.com/places/' + PlaceID
}, 5000)
}) })
.catch(error => {console.log(error)}) .catch(error => {console.log(error)})
}) })

View file

@ -43,26 +43,6 @@ let PinnedGames;
HandleGameProfiles() HandleGameProfiles()
} }
}); });
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.includes(parseInt(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 HandlePinnedGames() { async function HandlePinnedGames() {
@ -101,6 +81,26 @@ async function HandlePinnedGames() {
}); });
document.querySelectorAll('.card-header')[2].appendChild(PinBtn); 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.includes(parseInt(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)'
}
}
});
}
});
}); });
} }

View file

@ -1,6 +1,4 @@
const InExtensionSettings = (window.location.pathname.split('/')[3] === "polyplus") const InExtensionSettings = (window.location.pathname.split('/')[3] === "polyplus")
console.log(window.location.pathname.split('/')[3], InExtensionSettings)
if (InExtensionSettings === true) { if (InExtensionSettings === true) {
window.location.href = chrome.runtime.getURL('settings.html') window.location.href = chrome.runtime.getURL('settings.html')
} }

View file

@ -1,20 +1,21 @@
let Username = window.location.href.split('/')[4] const Username = window.location.pathname.split('/')[2]
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { let Reference = new URLSearchParams(new URL(window.location.href).search).get('ref')
Settings = result.PolyPlus_Settings; if (Reference === null) {
Reference = ""
}
if (Settings.SimplifiedProfileURLsOn === true) { fetch("https://api.polytoria.com/v1/users/find?username=" + Username)
fetch("https://api.polytoria.com/v1/users/find?username=" + Username) .then(response => {
.then(response => response.json()) if (!response.ok) {
.then(data => { window.location.href = window.location.origin + decodeURIComponent(Reference)
window.location.href = "https://polytoria.com/users/" + data.id } else {
}) return response.json()
.catch(error => { }
console.log("An error occurred:", error); })
}); .then(data => {
} window.location.href = "https://polytoria.com/users/" + data.id
})
if (!(parseInt(userID))) { .catch(error => {
return console.log("An error occurred:", error);
} });
});

95
js/utils.js Normal file
View file

@ -0,0 +1,95 @@
export default {
DefaultSettings: {
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
},
CalculateIRL: async function(bricks, to) {
const response = await fetch(chrome.runtime.getURL('/js/resources/currencies.json'))
if (!response.ok) {
throw new Error('Getting currency data failure')
}
const data = await response.json()
let IRL;
let DISPLAY;
switch (to) {
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
}
return {bricks: IRL, display: DISPLAY}
}
}

View file

@ -3,8 +3,8 @@
"name": "Poly+", "name": "Poly+",
"version": "1.0", "version": "1.0",
"version_name": "Beta", "version_name": "Beta",
"description": "This extension adds quality of life improvements and features to Polytoria's website.", "description": "This extension adds quality of life improvements and features to Polytoria's website. Created by Index",
"permissions": ["storage", "contextMenus", "tabs", "scripting", "webNavigation"], "permissions": ["storage", "contextMenus", "tabs", "scripting", "alarms", "notifications"],
"content_scripts": [ "content_scripts": [
{ {
"matches": ["https://polytoria.com/*"], "matches": ["https://polytoria.com/*"],
@ -25,6 +25,11 @@
"run_at": "document_idle" "run_at": "document_idle"
}, },
{
"matches": ["https://polytoria.com/my/settings/polyplus-debug/*"],
"js": ["/js/debug.js"]
},
{ {
"matches": ["https://polytoria.com/places/**"], "matches": ["https://polytoria.com/places/**"],
"js": ["/js/places/place-view.js"] "js": ["/js/places/place-view.js"]
@ -42,7 +47,7 @@
{ {
"matches": ["https://polytoria.com/forum/post/**"], "matches": ["https://polytoria.com/forum/post/**"],
"js": ["/js/forum/new-forum-view.js"] "js": ["/js/forum/forum-view.js"]
}, },
{ {
@ -87,12 +92,6 @@
"run_at": "document_idle" "run_at": "document_idle"
}, },
{
"matches": ["https://polytoria.com/create/","https://polytoria.com/create/place"],
"js": ["/js/account/create.js"],
"run_at": "document_idle"
},
{ {
"matches": ["https://polytoria.com/my/settings/privacy"], "matches": ["https://polytoria.com/my/settings/privacy"],
"js": ["/js/account/settings-privacy.js"] "js": ["/js/account/settings-privacy.js"]
@ -111,6 +110,11 @@
{ {
"matches": ["https://polytoria.com/my/avatar?sandbox=true"], "matches": ["https://polytoria.com/my/avatar?sandbox=true"],
"js": ["/js/account/avatar-sandbox2.js"] "js": ["/js/account/avatar-sandbox2.js"]
},
{
"matches": ["https://polytoria.com/inbox/*", "https://polytoria.com/inbox?*"],
"js": ["/js/account/inbox.js"]
} }
], ],
"background": { "background": {
@ -126,6 +130,11 @@
"matches": ["https://polytoria.com/*"] "matches": ["https://polytoria.com/*"]
}, },
{
"resources": ["js/utils.js"],
"matches": ["https://polytoria.com/*"]
},
{ {
"resources": ["js/account/avatar-sandbox.html"], "resources": ["js/account/avatar-sandbox.html"],
"matches": ["https://polytoria.com/*"] "matches": ["https://polytoria.com/*"]
@ -133,7 +142,6 @@
], ],
"short_name": "Poly+", "short_name": "Poly+",
"action": { "action": {
"default_popup": "popup.html",
"default_title": "Poly+", "default_title": "Poly+",
"default_icon": { "default_icon": {
"16": "/icon.png", "16": "/icon.png",

View file

@ -2,12 +2,10 @@
<html style="border-radius: 20px;"> <html style="border-radius: 20px;">
<head> <head>
<title>Poly+</title> <title>Poly+</title>
<link rel="stylesheet" href="/css/popup.css" type="text/css">
<script src="/js/popup.js"></script>
</head> </head>
<body> <body>
<div style="text-align: center; width: 300px;"> <div style="text-align: center; width: 300px; padding: 10px;">
<a class="button" href="https://polytoria.com/my/polyplus">Settings</a> <a class="btn" href="https://polytoria.com/my/settings/polyplus">Settings</a>
</div> </div>
</body> </body>
</html> </html>

View file

@ -1,10 +1,11 @@
<html> <html>
<head> <head>
<title>Poly+ Settings</title> <title>Poly+ Settings</title>
<link rel="stylesheet" href="https://c0.ptacdn.com/static/app.0e097f99.css">
</head> </head>
<body> <body data-bs-theme="dark">
<style> <style>
html { html, body, #page {
background: #202020; background: #202020;
color: #fff; color: #fff;
} }
@ -91,6 +92,7 @@
} }
*/ */
/*
button { button {
border: none; border: none;
padding: 5px; padding: 5px;
@ -105,6 +107,7 @@
button.btn-warning { button.btn-warning {
background: orange; background: orange;
} }
*/
</style> </style>
<dialog class="w-50" id="ResetDefaults-Modal"> <dialog class="w-50" id="ResetDefaults-Modal">
<div class="modal-header"> <div class="modal-header">