Importing Utility Module!!!!!!!!!

- Repetitive code is now way easier to edit as it is now stored in the utility module rather than the same code in several different files

- Changed "Theme Creator" Copy JSON button to have the text "Copy" rather than rely on an icon due to me forgetting to import fontawesome

- Hopefully fixed the store page randomly not working by not showing IRL prices or not showing the owned tags (may rewrite the entire code for that file since it is pretty old like Early Summer 2023)

- Fixed clicking on "Poly+" in the sidebar on the settings page sending you to an invalid page (due to browser security stuff) which wasn't happening to me before public beta

- Disabled importing theme data JSON for now to ensure security
This commit is contained in:
Index 2024-02-10 10:25:28 -06:00
parent d4cc322040
commit 3d6b265de0
9 changed files with 360 additions and 475 deletions

View file

@ -1,11 +1,19 @@
setTimeout(function () {}, 100) setTimeout(function () {}, 100)
/*
let Currencies; let Currencies;
LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){ LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){
Currencies = JSON.parse(text) Currencies = JSON.parse(text)
console.log(new Date(Currencies.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"}), Currencies) console.log(new Date(Currencies.Date).toLocaleDateString("en-US", {day:"numeric",month:"long",year:"numeric"}), Currencies)
}) })
*/
let Utilities;
(async () => {
Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
})();
let Nav = document.querySelector('.nav-pills') let Nav = document.querySelector('.nav-pills')
let DIV = document.createElement('div') let DIV = document.createElement('div')
@ -21,6 +29,7 @@ DIV.innerHTML = `
<option value="AUD">Australian Dollar (AUD)</option> <option value="AUD">Australian Dollar (AUD)</option>
<option value="TRY">Turkish Lira (TRY)</option> <option value="TRY">Turkish Lira (TRY)</option>
</select> </select>
<!--
<select id="polyplus-brickconverter-package" class="form-select bg-dark"> <select id="polyplus-brickconverter-package" class="form-select bg-dark">
<option value="0" selected>$0.99 USD</option> <option value="0" selected>$0.99 USD</option>
<option value="1">$4.99 USD</option> <option value="1">$4.99 USD</option>
@ -29,6 +38,7 @@ DIV.innerHTML = `
<option value="4">c</option> <option value="4">c</option>
<option value="5">d</option> <option value="5">d</option>
</select> </select>
-->
` `
Nav.appendChild(document.createElement('hr')) Nav.appendChild(document.createElement('hr'))
Nav.appendChild(DIV) Nav.appendChild(DIV)
@ -39,9 +49,9 @@ let Type = document.getElementById('polyplus-brickconverter-type')
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Type.selectedIndex = result.PolyPlus_Settings.IRLPriceWithCurrencyCurrency || 0 Type.selectedIndex = result.PolyPlus_Settings.IRLPriceWithCurrencyCurrency || 0
}); });
let Package = document.getElementById('polyplus-brickconverter-package') //let Package = document.getElementById('polyplus-brickconverter-package')
Input.addEventListener('change', function(){ Input.addEventListener('input', function(){
Update() Update()
}); });
@ -49,48 +59,18 @@ Type.addEventListener('change', function(){
Update() Update()
}); });
/*
Package.addEventListener('change', function(){ Package.addEventListener('change', function(){
Update() Update()
}); });
function Update(){
let DISPLAY = Type.options[Type.selectedIndex].value
let IRL = (parseInt(Input.value.replace(/,/g, '')) * Currencies.Data[Package.selectedIndex][DISPLAY]).toFixed(2)
/*
var IRL;
var DISPLAY;
switch (Type.selectedIndex) {
case 0:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0099).toFixed(2)
DISPLAY = 'USD'
break
case 1:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.009).toFixed(2)
DISPLAY = 'EUR'
break
case 2:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0131).toFixed(2)
DISPLAY = 'CAD'
break
case 3:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0077).toFixed(2)
DISPLAY = 'GBP'
break
case 4:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.1691).toFixed(2)
DISPLAY = 'MXN'
break
case 5:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.0144).toFixed(2)
DISPLAY = 'AUD'
break
case 6:
IRL = (parseInt(Input.value.replace(/,/g, '')) * 0.2338).toFixed(2)
DISPLAY = 'TRY'
break
}
*/ */
Output.value = "$" + IRL + " " + DISPLAY
async function Update(){
//let DISPLAY = Type.options[Type.selectedIndex].value
//let IRL = (parseInt(Input.value.replace(/,/g, '')) * Currencies.Data[Package.selectedIndex][DISPLAY]).toFixed(2)
const Result = await Utilities.CalculateIRL(Input.value, Type.selectedIndex)
console.log(Input.value, Type.options[Type.selectedIndex].value, Result)
Output.value = "$" + Result.bricks + " " + Result.display
} }
function LoadFile(path, callback) { function LoadFile(path, callback) {

View file

@ -1,62 +1,14 @@
var Settings; var Settings;
const ExpectedSettings = {
PinnedGamesOn: false,
ForumMentsOn: false,
BestFriendsOn: false,
ImprovedFrListsOn: false,
IRLPriceWithCurrencyOn: true,
IRLPriceWithCurrencyCurrency: 0,
IRLPriceWithCurrencyPackage: 0,
HideNotifBadgesOn: true,
StoreOwnTagOn: true,
ThemeCreatorOn: false,
ThemeCreator: {
BGColor: null,
BGImage: null,
BGImageSize: 'fit',
PrimaryTextColor: null,
SecondaryTextColor: null,
LinkTextColor: null,
WebsiteLogo: null
},
ModifyNavOn: false,
ModifyNav: [
{
Label: "Play",
Link: "https://polytoria.com/places"
},
{
Label: "Store",
Link: "https://polytoria.com/store"
},
{
Label: "Guilds",
Link: "https://polytoria.com/guilds"
},
{
Label: "People",
Link: "https://polytoria.com/users"
},
{
Label: "Forum",
Link: "https://polytoria.com/forum"
}
],
MoreSearchFiltersOn: true,
ApplyMembershipThemeOn: false,
ApplyMembershipThemeTheme: 0,
ForumMarkOn: true,
MultiCancelOutTradesOn: true,
ItemWishlistOn: true,
HideUpgradeBtnOn: false
}
let Theme = null; let Theme = null;
(async () => {
let Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
chrome.storage.sync.get(["PolyPlus_Settings"], function(result) { chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
// Merge settings and expected settings to make sure all keys exist // Merge settings and expected settings to make sure all keys exist
let RawSettings = result.PolyPlus_Settings const RawSettings = result.PolyPlus_Settings
Settings = MergeObjects(RawSettings || ExpectedSettings, ExpectedSettings); Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings);
//chrome.storage.sync.set({ 'PolyPlus_Settings': Settings, arrayOrder: true }, function() {});
// If theme exists, create a style element to represent it // If theme exists, create a style element to represent it
if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) {
@ -162,7 +114,7 @@ chrome.storage.sync.get(["PolyPlus_Settings"], function(result) {
} }
}); });
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', async function() {
if (document.getElementsByClassName('card-header')[0] && document.getElementsByClassName('card-header')[0].innerText === ' Page not found') { if (document.getElementsByClassName('card-header')[0] && document.getElementsByClassName('card-header')[0].innerText === ' Page not found') {
return return
} }
@ -196,10 +148,11 @@ document.addEventListener('DOMContentLoaded', function() {
Icon.classList = 'fa-regular fa-sparkles' Icon.classList = 'fa-regular fa-sparkles'
if (Settings.ModifyNavOn && Settings.ModifyNavOn === true) { if (Settings.ModifyNavOn && Settings.ModifyNavOn === true) {
let NavbarItems = document.querySelectorAll('#main-content nav.navbar .nav-link') let NavbarItems = document.querySelectorAll('.navbar-nav.me-auto a.nav-link[href]')
let Needed = [NavbarItems[11],NavbarItems[12],NavbarItems[13],NavbarItems[14],NavbarItems[15]] let Needed = [NavbarItems[10],NavbarItems[11],NavbarItems[12],NavbarItems[13],NavbarItems[14]]
for (let i = 0; i < Settings.ModifyNav.length; i++) { for (let i = 0; i < Settings.ModifyNav.length; i++) {
if (Settings.ModifyNav[i].Label != null) { if (Settings.ModifyNav[i].Label != null) {
console.log(Needed[i], Needed[i].children[1])
Needed[i].children[1].innerText = Settings.ModifyNav[i].Label Needed[i].children[1].innerText = Settings.ModifyNav[i].Label
Needed[i].href = Settings.ModifyNav[i].Link Needed[i].href = Settings.ModifyNav[i].Link
} }
@ -211,48 +164,16 @@ document.addEventListener('DOMContentLoaded', function() {
} }
if (Settings.IRLPriceWithCurrencyOn && Settings.IRLPriceWithCurrencyOn === true) { if (Settings.IRLPriceWithCurrencyOn && Settings.IRLPriceWithCurrencyOn === true) {
var IRL; const IRL = await Utilities.CalculateIRL(UserData.Bricks, Settings.IRLPriceWithCurrencyCurrency)
var DISPLAY; const BrickBalanceCount = [document.querySelector('.text-success .brickBalanceCount'), document.querySelector('.text-success .brickBalanceCont')]
switch (Settings.IRLPriceWithCurrencyCurrency) { BrickBalanceCount.forEach(element => {element.innerText = element.innerText + ` ($${IRL.bricks} ${IRL.display})`});
case 0:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.0099).toFixed(2)
DISPLAY = 'USD'
break
case 1:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.009).toFixed(2)
DISPLAY = 'EUR'
break
case 2:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.0131).toFixed(2)
DISPLAY = 'CAD'
break
case 3:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.0077).toFixed(2)
DISPLAY = 'GBP'
break
case 4:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.1691).toFixed(2)
DISPLAY = 'MXN'
break
case 5:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.0144).toFixed(2)
DISPLAY = 'AUD'
break
case 6:
IRL = (UserData.Bricks.replace(/,/g, '') * 0.2338).toFixed(2)
DISPLAY = 'TRY'
break
}
let BrickBalanceCount = [document.querySelector('.text-success .brickBalanceCount'), document.querySelector('.text-success .brickBalanceCont')]
BrickBalanceCount.forEach(element => {
element.innerText = element.innerText + ` ($${IRL} ${DISPLAY})`
});
} }
if (Settings.HideNotifBadgesOn && Settings.HideNotifBadgesOn === true) { if (Settings.HideNotifBadgesOn && Settings.HideNotifBadgesOn === true) {
document.querySelectorAll('.notif-nav.notif-sidebar').forEach(element => {element.remove();}); document.querySelectorAll('.notif-nav.notif-sidebar').forEach(element => {element.remove();});
} }
}); });
})();
function MergeObjects(obj1, obj2) { function MergeObjects(obj1, obj2) {
var mergedObj = {}; var mergedObj = {};

View file

@ -1,7 +1,5 @@
const InExtensionSettings = (window.location.pathname.split('/')[3] === "polyplus") const InExtensionSettings = (window.location.pathname.split('/')[3] === "polyplus")
if (InExtensionSettings === true) { if (InExtensionSettings === true) { window.location.href = chrome.runtime.getURL('settings.html') }
window.location.href = chrome.runtime.getURL('settings.html')
}
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
const Nav = document.getElementsByClassName('nav nav-pills')[0] const Nav = document.getElementsByClassName('nav nav-pills')[0]

View file

@ -1,14 +1,22 @@
/*
HOW TO USE IN CONTENT SCRIPTS:
(async () => {
let Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
})();
*/
export default { export default {
DefaultSettings: { DefaultSettings: {
PinnedGamesOn: false, PinnedGamesOn: true,
ForumMentsOn: false, ForumMentsOn: true,
BestFriendsOn: false, BestFriendsOn: false,
ImprovedFrListsOn: false, ImprovedFrListsOn: false,
IRLPriceWithCurrencyOn: true, IRLPriceWithCurrencyOn: true,
IRLPriceWithCurrencyCurrency: 0, IRLPriceWithCurrencyCurrency: 0,
IRLPriceWithCurrencyPackage: 0, IRLPriceWithCurrencyPackage: 0,
HideNotifBadgesOn: true, HideNotifBadgesOn: false,
SimplifiedProfileURLsOn: true,
StoreOwnTagOn: true, StoreOwnTagOn: true,
ThemeCreatorOn: false, ThemeCreatorOn: false,
ThemeCreator: { ThemeCreator: {
@ -46,20 +54,22 @@ export default {
MoreSearchFiltersOn: true, MoreSearchFiltersOn: true,
ApplyMembershipThemeOn: false, ApplyMembershipThemeOn: false,
ApplyMembershipThemeTheme: 0, ApplyMembershipThemeTheme: 0,
ForumMarkOn: true,
MultiCancelOutTradesOn: true, MultiCancelOutTradesOn: true,
ItemWishlistOn: true, ItemWishlistOn: true,
HideUpgradeBtnOn: false HideUpgradeBtnOn: false
}, },
CalculateIRL: async function(bricks, to) { CalculateIRL: async function(bricks, to, brickPackage) {
/*
const response = await fetch(chrome.runtime.getURL('/js/resources/currencies.json')) const response = await fetch(chrome.runtime.getURL('/js/resources/currencies.json'))
if (!response.ok) { if (!response.ok) {
throw new Error('Getting currency data failure') throw new Error('Getting currency data failure')
} }
const data = await response.json() const data = await response.json()
*/
let IRL; let IRL;
let DISPLAY; let DISPLAY;
//const UnitPrice = data.Data[brickPackage][to]
switch (to) { switch (to) {
case 0: case 0:
IRL = (bricks.replace(/,/g, '') * 0.0099).toFixed(2) IRL = (bricks.replace(/,/g, '') * 0.0099).toFixed(2)

View file

@ -1,28 +1,30 @@
const ItemID = window.location.pathname.split('/')[2] const ItemID = window.location.pathname.split('/')[2]
var Utilities;
var Settings;
var ItemWishlist; var ItemWishlist;
var PurchaseBtn; var PurchaseBtn;
var WishlistBtn; var WishlistBtn;
setTimeout(function () { (async () => {
if (!(window.location.href.split('/')[4])) {return}
Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
if (!(window.location.href.split('/')[4])) {return} if (!(window.location.href.split('/')[4])) {return}
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
var Settings = result.PolyPlus_Settings || { Settings = result.PolyPlus_Settings || {}
IRLPriceWithCurrencyOn: false,
IRLPriceWithCurrencyCurrency: 0,
ItemWishlistOn: true
}
PurchaseBtn = document.getElementsByClassName('btn btn-outline-success')[0] PurchaseBtn = document.getElementsByClassName('btn btn-outline-success')[0]
console.log(PurchaseBtn)
if (Settings.IRLPriceWithCurrencyOn === true){ IRLPrice() } if (Settings.IRLPriceWithCurrencyOn === true){ IRLPrice() }
if (Settings.ItemWishlistOn === true && !(PurchaseBtn.getAttribute('disabled'))) { if (Settings.ItemWishlistOn === true && !(PurchaseBtn.getAttribute('disabled'))) {
console.log('AAAA')
HandleItemWishlist() HandleItemWishlist()
} }
}) })
}, 100) })();
chrome.storage.onChanged.addListener(function(changes, namespace) { chrome.storage.onChanged.addListener(function(changes, namespace) {
if ('PolyPlus_ItemWishlist' in changes) { if ('PolyPlus_ItemWishlist' in changes) {
@ -53,46 +55,15 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
} }
}); });
function IRLPrice() { async function IRLPrice() {
if (!(PurchaseBtn.getAttribute('disabled'))) { if (!(PurchaseBtn.getAttribute('disabled'))) {
let Price = PurchaseBtn.getAttribute('data-price').replace(/,/g, '') const Price = PurchaseBtn.getAttribute('data-price')
let Span = document.createElement('span') const Span = document.createElement('span')
Span.classList = 'text-muted polyplus-own-tag' Span.classList = 'text-muted polyplus-own-tag'
Span.style.fontSize = '0.7rem' Span.style.fontSize = '0.7rem'
Span.style.fontWeight = 'normal' Span.style.fontWeight = 'normal'
let IRL; const Result = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrencyCurrency)
let DISPLAY; Span.innerText = "($" + Result.bricks + " " + Result.display + ")"
switch (Settings.IRLPriceWithCurrencyCurrency) {
case 0:
IRL = (Price * 0.0099).toFixed(2)
DISPLAY = 'USD'
break
case 1:
IRL = (Price * 0.009).toFixed(2)
DISPLAY = 'EUR'
break
case 2:
IRL = (Price * 0.0131).toFixed(2)
DISPLAY = 'CAD'
break
case 3:
IRL = (Price * 0.0077).toFixed(2)
DISPLAY = 'GBP'
break
case 4:
IRL = (Price * 0.1691).toFixed(2)
DISPLAY = 'MXN'
break
case 5:
IRL = (Price * 0.0144).toFixed(2)
DISPLAY = 'AUD'
break
case 6:
IRL = (Price * 0.2338).toFixed(2)
DISPLAY = 'TRY'
break
}
Span.innerText = "($" + IRL + " " + DISPLAY + ")"
PurchaseBtn.appendChild(Span) PurchaseBtn.appendChild(Span)
} }
} }

View file

@ -1,13 +1,25 @@
setTimeout(function () {}, 100) const UserID = JSON.parse(window.localStorage.getItem('account_info')).ID
var Settings = {IRLPriceWithCurrencyOn: true, IRLPriceWithCurrencyCurrency: 0, StoreOwnTagOn: true};
var UserID = JSON.parse(window.localStorage.getItem('account_info')).ID var Settings;
var ItemGrid = document.getElementById('assets')
var Utilities;
(async () => {
Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
Update()
})();
const ItemGrid = document.getElementById('assets')
var Inventory = []; var Inventory = [];
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Settings = result.PolyPlus_Settings; Settings = result.PolyPlus_Settings || Utilities.DefaultSettings;
console.log(Settings)
}); });
function Update() { function Update() {
console.log('update')
if (Settings.IRLPriceWithCurrencyOn === true) { if (Settings.IRLPriceWithCurrencyOn === true) {
Array.from(ItemGrid.children).forEach(element => {LoadIRLPrices(element)}); Array.from(ItemGrid.children).forEach(element => {LoadIRLPrices(element)});
} }
@ -15,9 +27,7 @@ function Update() {
const observer = new MutationObserver(async function (list){ const observer = new MutationObserver(async function (list){
for (const record of list) { for (const record of list) {
console.log('record')
for (const element of record.addedNodes) { for (const element of record.addedNodes) {
console.log('element', element.tagName, element.classList)
if (element.tagName === "DIV" && element.classList.value === 'mb-3 itemCardCont') { if (element.tagName === "DIV" && element.classList.value === 'mb-3 itemCardCont') {
if (Settings.IRLPriceWithCurrencyOn === true) {LoadIRLPrices(element)} if (Settings.IRLPriceWithCurrencyOn === true) {LoadIRLPrices(element)}
if (Settings.StoreOwnTagOn === true) { if (Settings.StoreOwnTagOn === true) {
@ -49,56 +59,23 @@ const observer = new MutationObserver(async function (list){
observer.observe(ItemGrid, {attributes: false,childList: true,subtree: false}); observer.observe(ItemGrid, {attributes: false,childList: true,subtree: false});
function LoadIRLPrices(element) { async function LoadIRLPrices(element) {
console.log('LOAD IRL PRICES!!!')
if (element.tagName != "DIV") {return} if (element.tagName != "DIV") {return}
if (element.querySelector('small.text-primary')) {return} if (element.querySelector('small.text-primary')) {return}
let Parent = element.getElementsByTagName('small')[1] const Parent = element.getElementsByTagName('small')[1]
if (Parent.innerText === "") { if (Parent.innerText === "") { return }
return
}
let Span = document.createElement('span') let Span = document.createElement('span')
Span.classList = 'text-muted polyplus-price-tag' Span.classList = 'text-muted polyplus-price-tag'
Span.style.fontSize = '0.7rem' Span.style.fontSize = '0.7rem'
let Price = parseInt(Parent.innerText.replace(/,/g, '')) const Price = Parent.innerText
var IRL; const Result = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrencyCurrency)
var DISPLAY; Span.innerText = "($" + Result.bricks + " " + Result.display + ")"
switch (Settings.IRLPriceWithCurrencyCurrency) {
case 0:
IRL = (Price * 0.0099).toFixed(2)
DISPLAY = 'USD'
break
case 1:
IRL = (Price * 0.009).toFixed(2)
DISPLAY = 'EUR'
break
case 2:
IRL = (Price * 0.0131).toFixed(2)
DISPLAY = 'CAD'
break
case 3:
IRL = (Price * 0.0077).toFixed(2)
DISPLAY = 'GBP'
break
case 4:
IRL = (Price * 0.1691).toFixed(2)
DISPLAY = 'MXN'
break
case 5:
IRL = (Price * 0.0144).toFixed(2)
DISPLAY = 'AUD'
break
case 6:
IRL = (Price * 0.2338).toFixed(2)
DISPLAY = 'TRY'
break
}
Span.innerText = "($" + IRL + " " + DISPLAY + ")"
Parent.appendChild(Span) Parent.appendChild(Span)
} }
function LoadOwnedTags(element) { function LoadOwnedTags(element) {
let Item = CheckInventory(parseInt(element.querySelector('[href^="/store/"]').getAttribute('href').split('/')[2])) let Item = CheckInventory(parseInt(element.querySelector('[href^="/store/"]').getAttribute('href').split('/')[2]))
console.log(Item, Item.id)
if (Item.id) { if (Item.id) {
var Tag = document.createElement('span') var Tag = document.createElement('span')
Tag.classList = 'badge bg-primary polyplus-own-tag' Tag.classList = 'badge bg-primary polyplus-own-tag'
@ -108,7 +85,7 @@ function LoadOwnedTags(element) {
} else { } else {
Tag.innerHTML = 'owned<br><span class="text-muted" style="font-size: 0.65rem;">#' + Item.serial Tag.innerHTML = 'owned<br><span class="text-muted" style="font-size: 0.65rem;">#' + Item.serial
} }
element.querySelector('img').parentElement.appendChild(Tag) element.getElementsByTagName('img')[0].parentElement.appendChild(Tag)
} }
} }

View file

@ -128,6 +128,11 @@
{ {
"resources": ["js/resources/*"], "resources": ["js/resources/*"],
"matches": ["https://polytoria.com/*"] "matches": ["https://polytoria.com/*"]
},
{
"resources": ["settings.html", "settings.js"],
"matches": ["https://polytoria.com/*"]
} }
], ],
"short_name": "Poly+", "short_name": "Poly+",

View file

@ -152,7 +152,7 @@
<input id="SaveThemeToJSONInput" type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true" disabled> <input id="SaveThemeToJSONInput" type="text" class="form-control bg-dark mb-2" placeholder="JSON..." data-ignore="true" disabled>
</div> </div>
<div class="col-auto"> <div class="col-auto">
<button id="CopyThemeJSONBtn" class="btn btn-warning"><i class="fa-duotone fa-clipboard"></i></button> <button id="CopyThemeJSONBtn" class="btn btn-warning"><!--<i class="fa-duotone fa-clipboard"></i>--> Copy</button>
</div> </div>
</div> </div>

View file

@ -2,6 +2,7 @@ const SaveBtn = document.getElementById('Save')
const Elements = Array.from(document.getElementsByClassName('setting-container')) const Elements = Array.from(document.getElementsByClassName('setting-container'))
var Settings; var Settings;
/*
var ExpectedSettings = { var ExpectedSettings = {
PinnedGamesOn: true, PinnedGamesOn: true,
ForumMentsOn: false, ForumMentsOn: false,
@ -52,6 +53,15 @@ var ExpectedSettings = {
ItemWishlistOn: true, ItemWishlistOn: true,
HideUpgradeBtnOn: false HideUpgradeBtnOn: false
} }
*/
var ExpectedSettings;
var Utilities;
(async () => {
Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
ExpectedSettings = Utilities.DefaultSettings
})();
const ResetDefaultsModal = document.getElementById('ResetDefaults-Modal') const ResetDefaultsModal = document.getElementById('ResetDefaults-Modal')
var ThemeCreatorModal = { var ThemeCreatorModal = {
@ -280,6 +290,12 @@ document.getElementById('ThemeCreator').getElementsByTagName('button')[1].addEve
CopyThemeJSONBtn.addEventListener('click', function(){ CopyThemeJSONBtn.addEventListener('click', function(){
if (SaveThemeToJSONInput.value.length > 0) { if (SaveThemeToJSONInput.value.length > 0) {
navigator.clipboard.writeText(SaveThemeToJSONInput.value) navigator.clipboard.writeText(SaveThemeToJSONInput.value)
.then(() => {
alert('Successfully copied theme data to clipboard!')
})
.catch(() => {
alert('Failure to copy theme data to clipboard.')
});
} }
}); });
@ -291,12 +307,19 @@ LoadFile(chrome.runtime.getURL('js/resources/currencies.json'), function(text){
}) })
function LoadThemeJSON(string) { function LoadThemeJSON(string) {
alert('This feature has been disabled for now.')
return
try { try {
let JSONTable = JSON.parse(string) let JSONTable = JSON.parse(string)
if (JSONTable.length === ExpectedSettings.ThemeCreator.length) { 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) { if (confirm('Are you sure you\'d like to replace this theme with the theme specified in the JSON?') === true) {
LoadThemeFromJSONBtn.previousElementSibling.value = '' LoadThemeFromJSONBtn.previousElementSibling.value = ''
document.getElementById('ThemeCreator-Modal').close() document.getElementById('ThemeCreator-Modal').close()
/*
for (let i = 0; i < JSONTable.length; i++) {
JSONTable[i] = new Sanitzer(JSONTable[i])
}
*/
Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator) Settings.ThemeCreator = MergeObjects(JSONTable, ExpectedSettings.ThemeCreator)
Save(); Save();
console.log(JSONTable.length, JSONTable, 'applied') console.log(JSONTable.length, JSONTable, 'applied')