bug fixes and remove prettier github action

This commit is contained in:
Index 2024-05-31 20:43:09 -05:00
parent 4bf9139a60
commit 1a2af482aa
15 changed files with 211 additions and 327 deletions

View file

@ -1,51 +0,0 @@
name: Prettier Format and Commit
on:
push:
branches:
- main
- 'refs/heads/*'
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: Install dependencies
run: npm install
- name: Pull latest changes
run: git pull
- name: Run Prettier
run: npx prettier --write .
- name: Commit changes
id: commit
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
if git diff-index --quiet HEAD; then
echo "No changes to commit."
echo "changes_committed=false" >> $GITHUB_ENV
else
git commit -m "chore: format code with Prettier"
echo "changes_committed=true" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push changes
if: env.changes_committed == 'true'
run: git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3
.gitignore vendored
View file

@ -1,2 +1 @@
.DS_Store .DS_Store
/node_modules/

View file

@ -1,17 +0,0 @@
{
"arrowParens": "always",
"bracketSpacing": false,
"printWidth": 200,
"singleQuote": true,
"trailingComma": "none",
"useTabs": true,
"plugins": ["prettier-plugin-jinja-template"],
"overrides": [
{
"files": "*.html",
"options": {
"parser": "jinja-template"
}
}
]
}

View file

@ -11,7 +11,7 @@ let Utilities;
chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) { chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) {
Settings = result.PolyPlus_Settings || Utilities.DefaultSettings; Settings = result.PolyPlus_Settings || Utilities.DefaultSettings;
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
IRLPrice(); IRLPrice();
} }

View file

@ -18,7 +18,7 @@ if (UserID) {
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.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
IRLPrice(); IRLPrice();
} }

View file

@ -6,7 +6,7 @@ let Utilities;
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.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
(async () => { (async () => {
Utilities = await import(chrome.runtime.getURL('resources/utils.js')); Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
Utilities = Utilities.default; Utilities = Utilities.default;
@ -40,7 +40,7 @@ const observer = new MutationObserver(async function (list) {
for (const record of list) { for (const record of list) {
for (const element of record.addedNodes) { for (const element of record.addedNodes) {
if (element.tagName === 'DIV' && element.classList.value === 'col-auto mb-3') { if (element.tagName === 'DIV' && element.classList.value === 'col-auto mb-3') {
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
IRLPrice(element); IRLPrice(element);
} }
} }

View file

@ -1,8 +1,8 @@
const AssetID = window.location.pathname.split('/')[2]; const AssetID = window.location.pathname.split('/')[2];
const LibraryType = document.querySelectorAll('ol a')[1].innerText; const LibraryType = document.querySelectorAll('ol a')[1].innerText.toLowerCase();
const LibraryTypes = ['Models', 'Audio', 'Decal', 'Mesh']; const LibraryTypes = ['model', 'audio', 'decal', 'mesh'];
if (LibraryTypes.indexOf(LibraryType) !== -1) { if (LibraryTypes.filter((x) => !LibraryTypes.some(element => element.startsWith(LibraryType))).length > 0) {
chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { chrome.storage.sync.get(['PolyPlus_Settings'], function (result) {
Settings = result.PolyPlus_Settings || {}; Settings = result.PolyPlus_Settings || {};
@ -19,21 +19,21 @@ if (LibraryTypes.indexOf(LibraryType) !== -1) {
Dropdown.insertBefore(DownloadLink, Dropdown.children[Dropdown.children.length - 1]); Dropdown.insertBefore(DownloadLink, Dropdown.children[Dropdown.children.length - 1]);
switch (LibraryType) { switch (LibraryType) {
case 'Models': case LibraryType.startsWith('model'):
DownloadLink.href = 'https://api.polytoria.com/v1/models/get-model?id=' + AssetID; DownloadLink.href = 'https://api.polytoria.com/v1/models/get-model?id=' + AssetID;
break; break;
case 'Audio': case LibraryType.startsWith('audio'):
const AudioBlob = new Blob([document.getElementsByTagName('audio')[0]], {type: 'octet-steam'}); const AudioBlob = new Blob([document.getElementsByTagName('audio')[0]], {type: 'octet-steam'});
DownloadLink.href = URL.createObjectURL(AudioBlob); DownloadLink.href = URL.createObjectURL(AudioBlob);
DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.mp3'; DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.mp3';
case 'Decal': case LibraryType.startsWith('decal'):
const DecalBlob = new Blob([document.getElementsByClassName('store-thumbnail')[0]], {type: 'image/png'}); const DecalBlob = new Blob([document.getElementsByClassName('store-thumbnail')[0]], {type: 'image/png'});
DownloadLink.href = URL.createObjectURL(DecalBlob); DownloadLink.href = URL.createObjectURL(DecalBlob);
DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.png'; DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.png';
break; break;
} }
if (LibraryType === 'Mesh') { if (LibraryType.startsWith('mesh')) {
let MeshURL = null; let MeshURL = null;
DownloadLink.addEventListener('click', async function () { DownloadLink.addEventListener('click', async function () {
if (MeshURL !== null) { if (MeshURL !== null) {

View file

@ -67,7 +67,7 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
} }
} }
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
IRLPrice(); IRLPrice();
} }

View file

@ -11,7 +11,7 @@ let Theme = ``;
Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings); Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings);
// If theme exists, create a style element to represent it // If theme exists, create a style element to represent it
if (Settings.ThemeCreator.Enabled && Settings.ThemeCreator.Enabled === true) { if (Settings.ThemeCreator && Settings.ThemeCreator.Enabled === true) {
switch (Settings.ThemeCreator.BGImageSize) { switch (Settings.ThemeCreator.BGImageSize) {
case 0: case 0:
Settings.ThemeCreator.BGImageSize = 'fit'; Settings.ThemeCreator.BGImageSize = 'fit';
@ -113,8 +113,8 @@ let Theme = ``;
} }
}); });
if (Settings.HideUserAds.Enabled === true) { if (Settings.HideUserAds && Settings.HideUserAds.Enabled === true) {
if (Settings.HideUserAds.Banners === true) { if (Settings.HideUserAds.Banners && Settings.HideUserAds.Banners === true) {
Theme += ` Theme += `
div[style^="max-width: 728px;"]:has(a[href^="/ads"]) { div[style^="max-width: 728px;"]:has(a[href^="/ads"]) {
display: none; display: none;
@ -122,7 +122,7 @@ let Theme = ``;
`; `;
} }
if (Settings.HideUserAds.Rectangles === true) { if (Settings.HideUserAds.Rectangles && Settings.HideUserAds.Rectangles === true) {
Theme += ` Theme += `
div[style^="max-width: 300px;"]:has(a[href^="/ads"]) { div[style^="max-width: 300px;"]:has(a[href^="/ads"]) {
display: none; display: none;
@ -154,7 +154,7 @@ let Theme = ``;
const UserData = JSON.parse(window.localStorage.getItem('p+account_info')); const UserData = JSON.parse(window.localStorage.getItem('p+account_info'));
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
const IRLResult = await Utilities.CalculateIRL(document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g, ''), Settings.IRLPriceWithCurrency.Currency); const IRLResult = await Utilities.CalculateIRL(document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g, ''), Settings.IRLPriceWithCurrency.Currency);
// Desktop // Desktop
document.querySelector('.text-success .brickBalanceCount').innerHTML += ` (${IRLResult.icon}${IRLResult.result} ${IRLResult.display})`; document.querySelector('.text-success .brickBalanceCount').innerHTML += ` (${IRLResult.icon}${IRLResult.result} ${IRLResult.display})`;

View file

@ -31,7 +31,7 @@ var Utilities;
Utilities.InjectResource('registerTooltips'); Utilities.InjectResource('registerTooltips');
} }
if (Settings.IRLPriceWithCurrency.Enabled === true && ItemOwned === false) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true && ItemOwned === false) {
IRLPrice(); IRLPrice();
} }
@ -54,11 +54,10 @@ var Utilities;
} }
if (document.getElementById('resellers') !== null) { if (document.getElementById('resellers') !== null) {
if (Settings.HoardersList.Enabled === true) { if (Settings.HoardersList && Settings.HoardersList.Enabled === true) {
console.log(parseInt(Settings.HoardersList.MinCopies));
HoardersList(parseInt(Settings.HoardersList.MinCopies), Settings.HoardersList.AvatarsEnabled); HoardersList(parseInt(Settings.HoardersList.MinCopies), Settings.HoardersList.AvatarsEnabled);
} }
} else if (document.getElementById('timer') && /\d/.test(document.getElementById('timer').innerText)) { } else if (Settings.ItemOwnerCheckOn === true && document.getElementById('timer') && /\d/.test(document.getElementById('timer').innerText)) {
CheckOwner(); CheckOwner();
} }
}); });
@ -301,16 +300,17 @@ function TryOnItems() {
TryOnModal.classList = 'polyplus-modal'; TryOnModal.classList = 'polyplus-modal';
TryOnModal.setAttribute('style', 'width: 450px; border: 1px solid #484848; background-color: #181818; border-radius: 20px; overflow: hidden;'); TryOnModal.setAttribute('style', 'width: 450px; border: 1px solid #484848; background-color: #181818; border-radius: 20px; overflow: hidden;');
TryOnModal.innerHTML = ` TryOnModal.innerHTML = `
<div class="row text-muted mb-2" style="font-size: 0.8rem;"> <div class="row text-muted mb-2" style="font-size: 0.8rem;">
<div class="col"> <div class="col">
<h5 class="mb-0" style="color: #fff;">Preview</h5> <h5 class="mb-0" style="color: #fff;">Preview</h5>
Try this avatar on your avatar before purchasing it! Try this avatar on your avatar before purchasing it!
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<button class="btn btn-info w-100 mx-auto" onclick="this.parentElement.parentElement.parentElement.close();">X</button> <button class="btn btn-info w-100 mx-auto" onclick="this.parentElement.parentElement.parentElement.close();">X</button>
</div> </div>
</div> </div>
<div class="modal-body"></div> </div>
<div class="modal-body"></div>
`; `;
document.body.prepend(TryOnModal); document.body.prepend(TryOnModal);
@ -400,16 +400,27 @@ async function HoardersList(min, avatars) {
} }
} }
let AvatarsFetched = 0;
let Hoarders = await new Promise(async (resolve, reject) => { let Hoarders = await new Promise(async (resolve, reject) => {
const Sorted = Object.values(Formatted) const FormattedValues = Object.values(Formatted).filter((x, index) => x.copies >= 2)
.filter((x, index) => x.copies >= min)
.sort((a, b) => b.copies - a.copies);
if (avatars === true) { if (avatars === true) {
for (let hoarder of Sorted) { for (let hoarder of FormattedValues) {
const Avatar = (await (await fetch('https://api.polytoria.com/v1/users/' + hoarder.user.id)).json()).thumbnail.icon; if (AvatarsFetched < 15) {
hoarder.user.avatar = Avatar; try {
AvatarsFetched++
const Avatar = (await (await fetch('https://api.polytoria.com/v1/users/' + hoarder.user.id)).json());
console.log(hoarder.user.username, Avatar)
hoarder.user.avatar = Avatar.thumbnail.icon;
} catch(error) {
hoarder.user.avatar = ''
console.log(hoarder.user.username + ` (${hoarder.user.id}) - avatar failed`)
}
}
} }
} }
const Sorted = FormattedValues
.filter((x, index) => x.copies >= min)
.sort((a, b) => b.copies - a.copies);
resolve(Sorted); resolve(Sorted);
}); });
let AmountOfHoarders = Hoarders.length; let AmountOfHoarders = Hoarders.length;
@ -421,91 +432,79 @@ async function HoardersList(min, avatars) {
} }
TabContent.innerHTML = ` TabContent.innerHTML = `
<div id="p+hoarders-container"> <div id="p+hoarders-container">
${ ${ Groups[Page] !== undefined ? Groups[Page].map((x) => `
Groups[Page] !== undefined <div class="card mb-3">
? Groups[Page].map( <div class="card-body">
(x) => ` <div class="row">
<div class="card mb-3"> ${ avatars === true ? `
<div class="card-body"> <div class="col-auto">
<div class="row"> <img src="${x.user.avatar}" alt="${x.user.username}" width="72" class="rounded-circle border border-2 border-secondary bg-dark">
${ </div>
avatars === true ` : ''
? `
<div class="col-auto">
<img src="${x.user.avatar}" alt="${x.user.username}" width="72" class="rounded-circle border border-2 border-secondary bg-dark">
</div>
`
: ''
} }
<div class="col d-flex align-items-center"> <div class="col d-flex align-items-center">
<div> <div>
<h6 class="mb-1"> <h6 class="mb-1">
<a class="text-reset" href="/users/${x.user.id}">${x.user.username}</a> <a class="text-reset" href="/u/${x.user.username}">${x.user.username}</a>
</h6> </h6>
<small class="text-muted">${x.copies} Copies <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="#${x.serials.sort((a, b) => a - b).join(', #')}"></i></small> <small class="text-muted">${x.copies} Copies <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="#${x.serials.sort((a, b) => a - b).join(', #')}"></i></small>
</div> </div>
</div> </div>
<div class="col-auto d-flex align-items-center"> <div class="col-auto d-flex align-items-center">
<!-- <a class="btn btn-warning" type="button" href="/trade/new/${x.user.id}">
<div> <i class="fad fa-exchange-alt me-1"></i>
<h5 style="margin: 0px;margin-right: 10px;">${((x.copies / InitialOwners.total) * 100).toFixed(2)}%</h5> <span class="d-none d-sm-inline">Trade</span>
</div> </a>
--> </div>
<a class="btn btn-warning" type="button" href="/trade/new/${x.user.id}"> </div>
<i class="fad fa-exchange-alt me-1"></i> </div>
<span class="d-none d-sm-inline">Trade</span> </div>
</a> `
</div> ).join('') : `
</div> <div class="card mb-3">
</div> <div class="card-body text-center py-5 text-muted">
</div> <h1 class="display-3"><i class="fa-solid fa-rectangle-history-circle-user"></i></h1>
` <h5> No hoarders </h5>
).join('') <p class="mb-0">This item is fresh and doesn't have any hoarders yet! Come back later!</p>
: ` </div>
<div class="card mb-3"> </div>
<div class="card-body text-center py-5 text-muted"> `}
<h1 class="display-3"><i class="fa-solid fa-rectangle-history-circle-user"></i></h1> </div>
<h5> No hoarders </h5> <nav aria-label="Hoarders">
<p class="mb-0">This item is fresh and doesn't have any hoarders yet! Come back later!</p> <ul class="pagination justify-content-center">
</div> <li style="margin-top: auto; margin-bottom: auto;">
</div> <select class="form-select form-select-sm" style="height: 37px !important;" id="p+hoarders-min-copies">
` <option value="2">Min. 2+ Copies</option>
} <option value="3">Min. 3+ Copies</option>
</div> <option value="5">Min. 5+ Copies</option>
<nav aria-label="Hoarders"> <option value="10">Min. 10+ Copies</option>
<ul class="pagination justify-content-center"> <option value="15">Min. 15+ Copies</option>
<li style="margin-top: auto; margin-bottom: auto;"> <option value="35">Min. 35+ Copies</option>
<select class="form-select form-select-sm" style="height: 37px !important;" id="p+hoarders-min-copies"> </select>
<option value="2">Min. 2+ Copies</option> </li>
<option value="3">Min. 3+ Copies</option> <li class="page-item disabled">
<option value="5">Min. 5+ Copies</option> <a class="page-link" href="#!" id="p+hoarders-first-pg">«</a>
<option value="10">Min. 10+ Copies</option> </li>
<option value="15">Min. 15+ Copies</option> <li class="page-item disabled">
<option value="35">Min. 35+ Copies</option> <a class="page-link" href="#!" tabindex="-1" id="p+hoarders-prev-pg"></a>
</select> </li>
</li> <li class="page-item active">
<li class="page-item disabled"> <a class="page-link">
<a class="page-link" href="#!" id="p+hoarders-first-pg">«</a> <span class="visually-hidden">Page</span>
</li> <span id="p+hoarders-current-pg">1</span>
<li class="page-item disabled"> </a>
<a class="page-link" href="#!" tabindex="-1" id="p+hoarders-prev-pg"></a> </li>
</li> <li class="page-item">
<li class="page-item active"> <a class="page-link" href="#!" id="p+hoarders-next-pg"></a>
<a class="page-link"> </li>
<span class="visually-hidden">Page</span> <li class="page-item">
<span id="p+hoarders-current-pg">1</span> <a class="page-link" href="#!" id="p+hoarders-last-pg">»</a>
</a> </li>
</li> </ul>
<li class="page-item"> </nav>
<a class="page-link" href="#!" id="p+hoarders-next-pg"></a> <small class="text-muted text-center mt-1 mb-3 d-block" style="font-size: 0.7rem;">feature of Poly+</small>
</li> `;
<li class="page-item">
<a class="page-link" href="#!" id="p+hoarders-last-pg">»</a>
</li>
</ul>
</nav>
`;
Utilities.InjectResource('registerTooltips'); Utilities.InjectResource('registerTooltips');
const Container = document.getElementById('p+hoarders-container'); const Container = document.getElementById('p+hoarders-container');
@ -582,53 +581,47 @@ async function HoardersList(min, avatars) {
Current.innerText = Page + 1; Current.innerText = Page + 1;
if (Groups[Page] !== undefined) { if (Groups[Page] !== undefined) {
Container.innerHTML = Groups[Page].map( Container.innerHTML = Groups[Page].map((x) => `
(x) => ` <div class="card mb-3">
<div class="card mb-3"> <div class="card-body">
<div class="card-body"> <div class="row">
<div class="row"> ${ avatars === true ? `
${ <div class="col-auto">
avatars === true <img src="${x.user.avatar}" alt="${x.user.username}" width="72" class="rounded-circle border border-2 border-secondary bg-dark">
? ` </div>
<div class="col-auto"> ` : ''
<img src="${x.user.avatar}" alt="${x.user.username}" width="72" class="rounded-circle border border-2 border-secondary bg-dark">
</div>
`
: ''
} }
<div class="col d-flex align-items-center"> <div class="col d-flex align-items-center">
<div> <div>
<h6 class="mb-1"> <h6 class="mb-1">
<a class="text-reset" href="/users/${x.user.id}">${x.user.username}</a> <a class="text-reset" href="/users/${x.user.id}">${x.user.username}</a>
</h6> </h6>
<small class="text-muted">${x.copies} Copies <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="#${x.serials.sort((a, b) => a - b).join(', #')}"></i></small> <small class="text-muted">${x.copies} Copies <i class="fa-solid fa-circle-info" data-bs-toggle="tooltip" data-bs-title="#${x.serials.sort((a, b) => a - b).join(', #')}"></i></small>
</div> </div>
</div> </div>
<div class="col-auto d-flex align-items-center"> <div class="col-auto d-flex align-items-center">
<a class="btn btn-warning" type="button" href="/trade/new/${x.user.id}"> <a class="btn btn-warning" type="button" href="/trade/new/${x.user.id}">
<i class="fad fa-exchange-alt me-1"></i> <i class="fad fa-exchange-alt me-1"></i>
<span class="d-none d-sm-inline">Trade</span> <span class="d-none d-sm-inline">Trade</span>
</a> </a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
` `
).join(''); ).join('');
Utilities.InjectResource('registerTooltips'); Utilities.InjectResource('registerTooltips');
} else { } else {
Container.innerHTML = ` Container.innerHTML = `
<div class="card mb-3"> <div class="card mb-3">
<div class="card-body text-center py-5 text-muted"> <div class="card-body text-center py-5 text-muted">
<h1 class="display-3"><i class="fa-solid fa-rectangle-history-circle-user"></i></h1> <h1 class="display-3"><i class="fa-solid fa-rectangle-history-circle-user"></i></h1>
<h5> No hoarders </h5> <h5> No hoarders </h5>
<p class="mb-0">This item is fresh and doesn't have any hoarders yet! Come back later!</p> <p class="mb-0">This item is fresh and doesn't have any hoarders yet! Come back later!</p>
</div> </div>
</div> </div>
`; `;
MinCopies.disabled = true;
} }
if (Page > 0) { if (Page > 0) {

View file

@ -15,7 +15,7 @@ chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) {
Utilities = await import(chrome.runtime.getURL('resources/utils.js')); Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
Utilities = Utilities.default; Utilities = Utilities.default;
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
Array.from(ItemGrid.children).forEach((element) => { Array.from(ItemGrid.children).forEach((element) => {
LoadIRLPrices(element); LoadIRLPrices(element);
}); });
@ -59,7 +59,7 @@ const observer = new MutationObserver(async function (list) {
for (const record of list) { for (const record of list) {
for (const element of record.addedNodes) { for (const element of record.addedNodes) {
if (element.tagName === 'DIV' && element.classList.value === 'mb-3 itemCardCont') { if (element.tagName === 'DIV' && element.classList.value === 'mb-3 itemCardCont') {
if (Settings.IRLPriceWithCurrency.Enabled === true) { if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
LoadIRLPrices(element); LoadIRLPrices(element);
} }

37
package-lock.json generated
View file

@ -1,37 +0,0 @@
{
"name": "PolyPlus",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"devDependencies": {
"prettier": "^3.2.5",
"prettier-plugin-jinja-template": "^1.4.0"
}
},
"node_modules/prettier": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz",
"integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==",
"dev": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/prettier-plugin-jinja-template": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/prettier-plugin-jinja-template/-/prettier-plugin-jinja-template-1.4.0.tgz",
"integrity": "sha512-9i7HwTAryhOTtY1ENyZBZA+KNaPphSaI/sXbQno5a6/DgiP6ZAnUiax4cOKiutEwiSDhVfLbTXEfHS5QAUVWBg==",
"dev": true,
"peerDependencies": {
"prettier": "^3.0.0"
}
}
}
}

View file

@ -1,9 +0,0 @@
{
"scripts": {
"format": "prettier --write ."
},
"devDependencies": {
"prettier": "^3.2.5",
"prettier-plugin-jinja-template": "^1.4.0"
}
}

View file

@ -109,15 +109,15 @@ export default {
TextureTypes: ['shirt', 'pants', 'face'], TextureTypes: ['shirt', 'pants', 'face'],
CalculateIRL: async function (bricks, to, brickPackage) { CalculateIRL: async function (bricks, to, brickPackage) {
/* /*
Disabled for now: currency retrieval from currencies.json Disabled for now: currency retrieval from currencies.json
const response = await fetch(chrome.runtime.getURL('resources/currencies.json')) const response = await fetch(chrome.runtime.getURL('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()
const UnitPrice = data.Data[brickPackage][to] const UnitPrice = data.Data[brickPackage][to]
*/ */
let Icon = '$'; let Icon = '$';
let Result = 'N/A'; let Result = 'N/A';
@ -212,10 +212,17 @@ export default {
}; };
}, },
InjectResource: function (path, element) { InjectResource: function (path, element) {
// Function by devjin0617 on GitHub /*
// Gist: https://gist.github.com/devjin0617/3e8d72d94c1b9e69690717a219644c7a Function by devjin0617 on GitHub
// Slightly modified to use constants and fit the rest of the code style more Gist: https://gist.github.com/devjin0617/3e8d72d94c1b9e69690717a219644c7a
// Function only used for registering bootstrap tooltips currently Slightly modified to use constants and fit the rest of the code style more
Function only used for registering bootstrap tooltips and getting the signed-in user's username, user ID, and brick count currently
*/
/*
Potentially make this use chrome.runtime.sendMessage in the background.js script soon
*/
if (element === undefined) { if (element === undefined) {
element = 'body'; element = 'body';

View file

@ -1,6 +1,7 @@
const SaveBtn = document.getElementById('Save'); const SaveBtn = document.getElementById('Save');
const Elements = Array.from(document.getElementsByClassName('setting-container')); const Elements = Array.from(document.getElementsByClassName('setting-container'));
var RecentSave;
var Settings; var Settings;
var Utilities; var Utilities;
@ -12,16 +13,14 @@ var Utilities;
document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames; document.getElementById('PinnedGames-limit').innerText = Utilities.Limits.PinnedGames;
document.getElementById('BestFriends-limit').innerText = Utilities.Limits.BestFriends; document.getElementById('BestFriends-limit').innerText = Utilities.Limits.BestFriends;
document.getElementById('ImprovedFrLists-limit').innerText = Utilities.Limits.ImprovedFrLists; document.getElementById('ImprovedFrLists-limit').innerText = Utilities.Limits.ImprovedFrLists;
document.getElementById('ItemWishlist-limit').innerText = Utilities.Limits.ItemWishlist; //document.getElementById('ItemWishlist-limit').innerText = Utilities.Limits.ItemWishlist;
})(); })();
// Handle buttons at the bottom of the page // Handle buttons at the bottom of the page
document.getElementById('ResetDefaults').addEventListener('click', function () { document.getElementById('ResetDefaults').addEventListener('click', function () {
document.getElementById('ResetDefaults-Modal').showModal(); document.getElementById('ResetDefaults-Modal').showModal();
}); });
SaveBtn.addEventListener('click', function () { SaveBtn.addEventListener('click', Save);
Save();
});
// Handle modal buttons for Reset Defaults modal // Handle modal buttons for Reset Defaults modal
document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function () { document.getElementById('ResetDefaults-Modal-Yes').addEventListener('click', function () {
@ -36,16 +35,8 @@ document.getElementById('ResetDefaults-Modal-No').addEventListener('click', func
document.getElementById('ResetDefaults-Modal').close(); document.getElementById('ResetDefaults-Modal').close();
}); });
// Handle leaving the settings page before saving
window.onbeforeunload = function () {
if (SaveBtn.getAttribute('disabled') !== undefined) {
return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved.";
}
};
// Loop thru each setting container and handle toggling, selecting, opening modal, etc // Loop thru each setting container and handle toggling, selecting, opening modal, etc
Elements.forEach((element) => { Elements.forEach((element) => {
console.log('Handle Element', element);
let Button = element.getElementsByTagName('button')[0]; let Button = element.getElementsByTagName('button')[0];
let Options = element.getElementsByTagName('button')[1]; let Options = element.getElementsByTagName('button')[1];
let Select = element.getElementsByTagName('select')[0]; let Select = element.getElementsByTagName('select')[0];
@ -93,16 +84,20 @@ Elements.forEach((element) => {
if (Setting === '[save]') { if (Setting === '[save]') {
// Save Modal Button // Save Modal Button
// Save Modal Inputs
Array.from(ModalInputs) Array.from(ModalInputs)
.filter((x) => !x.classList.contains('ignore')) .filter((x) => !x.classList.contains('ignore'))
.forEach((input) => { .forEach((input) => {
SetSetting(input, input.value, false, Modal.getAttribute('data-setting')); SetSetting(input, input.value, false, Modal.getAttribute('data-setting'));
}); });
// Save Modal Select Menus
Array.from(ModalSelect) Array.from(ModalSelect)
.filter((x) => !x.classList.contains('ignore')) .filter((x) => !x.classList.contains('ignore'))
.forEach((select) => { .forEach((select) => {
SetSetting(select, select.selectedIndex, false, Modal.getAttribute('data-setting')); SetSetting(select, select.selectedIndex, false, Modal.getAttribute('data-setting'));
}); });
Save(); Save();
setTimeout(function () { setTimeout(function () {
LoadCurrent(); LoadCurrent();
@ -156,17 +151,18 @@ Elements.forEach((element) => {
function LoadCurrent() { function LoadCurrent() {
chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { chrome.storage.sync.get(['PolyPlus_Settings'], function (result) {
Settings = MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings, Utilities.DefaultSettings); Settings = MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings, Utilities.DefaultSettings);
RecentSave = structuredClone(Settings)
console.log('Current Settings: ', Settings); console.log('Current Settings: ', Settings);
Elements.forEach((element) => { Elements.forEach((element) => {
console.log('For Each Update');
UpdateElementState(element); UpdateElementState(element);
}); });
}); });
} }
function SetSetting(element, value, update, modalParent) { function SetSetting(element, value, update, modalParent) {
document.title = '*unsaved | Poly+ Settings'
const name = element.getAttribute('data-setting'); const name = element.getAttribute('data-setting');
let parent = element.getAttribute('data-parent'); let parent = element.getAttribute('data-parent');
@ -181,7 +177,6 @@ function SetSetting(element, value, update, modalParent) {
if (parent !== null) { if (parent !== null) {
let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)]; let Parent = Object.values(Settings)[Object.keys(Settings).indexOf(parent)];
if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) { if (!isNaN(element.getAttribute('data-parent')) && element.getAttribute('data-parent') !== null) {
console.log('is numbere!!!!');
Parent = Parent[parseInt(element.getAttribute('data-parent'))]; Parent = Parent[parseInt(element.getAttribute('data-parent'))];
} }
Parent[name] = value; Parent[name] = value;
@ -193,11 +188,16 @@ function SetSetting(element, value, update, modalParent) {
} }
if (SaveBtn.getAttribute('disabled')) { if (SaveBtn.getAttribute('disabled')) {
SaveBtn.removeAttribute('disabled'); SaveBtn.removeAttribute('disabled');
}
const getInObject = function (a, b) { // Handle leaving the settings page before saving
return Object.values(a)[Object.keys(a).indexOf(b)]; window.onbeforeunload = function (e) {
}; return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved."
};
}
if (AreIdentical(Settings, RecentSave) === true) {
document.title = 'Poly+ Settings'
SaveBtn.disabled = true
}
} }
function GetSettingValue(element, modalParent) { function GetSettingValue(element, modalParent) {
@ -217,40 +217,31 @@ function GetSettingValue(element, modalParent) {
} else { } else {
Status = Object.values(Parent)[Object.keys(Parent).indexOf(name)]; Status = Object.values(Parent)[Object.keys(Parent).indexOf(name)];
} }
/*
if (!isNaN(element.getAttribute('data-parent'))) {
Parent = Parent[parseInt(element.getAttribute('data-parent'))]
}
Status = Object.values(Parent)[Object.keys(Parent).indexOf(Status)]
*/
} else { } else {
Status = Settings[Status]; Status = Settings[Status];
} }
console.log('Get Value Result', Status);
if (element.tagName === 'SELECT' && element.getAttribute('data-useValue') === 'true') {
Status = Array.from(element.children).indexOf(element.querySelector('option[value="' + Status + '"]'))
}
return Status; return Status;
} }
function UpdateElementState(element, status) { function UpdateElementState(element, status) {
console.log('Update Element State', element, status);
const Button = element.getElementsByClassName('toggle-btn')[0]; const Button = element.getElementsByClassName('toggle-btn')[0];
if (status === undefined) { if (status === undefined) {
console.log('Update Element State, no status provided');
status = GetSettingValue(Button); status = GetSettingValue(Button);
} }
if (status === true) { if (status === true) {
console.log('Is Enabled so Set False');
element.classList.add('enabled'); element.classList.add('enabled');
element.classList.remove('disabled'); element.classList.remove('disabled');
Button.innerText = 'Disable'; Button.innerText = 'Disable';
Button.classList.add('btn-danger'); Button.classList.add('btn-danger');
Button.classList.remove('btn-success'); Button.classList.remove('btn-success');
} else { } else {
console.log('Is Disabled so Set True');
element.classList.add('disabled'); element.classList.add('disabled');
element.classList.remove('enabled'); element.classList.remove('enabled');
Button.innerText = 'Enable'; Button.innerText = 'Enable';
@ -260,15 +251,12 @@ function UpdateElementState(element, status) {
let SelectInput = element.getElementsByTagName('select')[0]; let SelectInput = element.getElementsByTagName('select')[0];
if (SelectInput) { if (SelectInput) {
console.log('Select Found');
SelectInput.selectedIndex = GetSettingValue(SelectInput); SelectInput.selectedIndex = GetSettingValue(SelectInput);
} }
let Checkbox = Array.from(element.getElementsByTagName('input')); let Checkbox = Array.from(element.getElementsByTagName('input'));
if (Checkbox.length > 0) { if (Checkbox.length > 0) {
console.log('Checkbox/Input(s) Found', Checkbox);
Checkbox.forEach((check) => { Checkbox.forEach((check) => {
console.log('check', GetSettingValue(check));
check.checked = GetSettingValue(check); check.checked = GetSettingValue(check);
}); });
} }
@ -277,10 +265,14 @@ function UpdateElementState(element, status) {
function Save() { function Save() {
document.title = 'Poly+ Settings'; document.title = 'Poly+ Settings';
SaveBtn.setAttribute('disabled', 'true'); SaveBtn.setAttribute('disabled', 'true');
chrome.storage.sync.set({PolyPlus_Settings: Settings, arrayOrder: true}, function () { chrome.storage.sync.set({PolyPlus_Settings: Settings}, function () {
console.log('Saved successfully!'); console.log('Saved successfully!');
RecentSave = Settings
}); });
// Handle leaving the settings page after saving
window.onbeforeunload = null
console.log('Save:', Settings); console.log('Save:', Settings);
} }
@ -353,6 +345,11 @@ function MergeObjects(obj1, obj2) {
return mergedObj; return mergedObj;
} }
function AreIdentical(obj1, obj2) {
if (obj1.length !== obj2.length) { return false }
return JSON.stringify(obj1) === JSON.stringify(obj2)
}
function FormatBool(bool) { function FormatBool(bool) {
if (bool === true) { if (bool === true) {
return 'enabled'; return 'enabled';
@ -397,6 +394,7 @@ function CheckForUpdates() {
} }
CheckForUpdatesButton.addEventListener('click', CheckForUpdates); CheckForUpdatesButton.addEventListener('click', CheckForUpdates);
/*
fetch(chrome.runtime.getURL('resources/currencies.json')) fetch(chrome.runtime.getURL('resources/currencies.json'))
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
@ -411,6 +409,7 @@ fetch(chrome.runtime.getURL('resources/currencies.json'))
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
}); });
*/
chrome.storage.local.get(['PolyPlus_OutOfDate', 'PolyPlus_LiveVersion', 'PolyPlus_ReleaseNotes', 'PolyPlus_SkipUpdate'], function (result) { chrome.storage.local.get(['PolyPlus_OutOfDate', 'PolyPlus_LiveVersion', 'PolyPlus_ReleaseNotes', 'PolyPlus_SkipUpdate'], function (result) {
const OutOfDate = result.PolyPlus_OutOfDate || false; const OutOfDate = result.PolyPlus_OutOfDate || false;