Add Update Notifier+Update Simplified Profile URLs

- Added Update Notifier that runs every day at 12 PM

- Changed Simplified Profile URLs from /profile/[username] to /users/@[username]

- Removed version_name from manifest.json so that it's easy to find the version number on browser extensions page
This commit is contained in:
Index 2024-02-10 21:14:32 -06:00
parent a39ae5ad31
commit f0b07d2ddc
4 changed files with 35 additions and 126 deletions

View file

@ -5,28 +5,20 @@ chrome.action.onClicked.addListener((tab) => {
chrome.tabs.create({ active: true, url: chrome.runtime.getURL('settings.html') });
});
// REGISTER AN ALARM FOR DAILY UPDATE CHECK (chatgpt cause I'm lazy and have to release Poly+ on February 8th aka today at the time of writing this)
// Calculate the milliseconds until the next 12 PM
/*
const now = new Date();
const msUntilNext12PM = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
12, // 12 PM hour
0, // 0 minutes
0 // 0 seconds
) - now;
// Convert milliseconds to minutes
const minutesUntilNext12PM = msUntilNext12PM / (1000 * 60);
// Create the alarm
chrome.alarms.create("PolyPlus-UpdateCheck", {
periodInMinutes: 24 * 60, // 24 hours
delayInMinutes: minutesUntilNext12PM, // Time until next 12 PM
// REGISTER AN ALARM FOR DAILY UPDATE CHECK
chrome.alarms.create('PolyPlus-UpdateCheck', {
when: Date.now() + (GetNext12PM())
});
*/
function GetNext12PM() {
const Now = new Date();
const Next = new Date();
Next.setHours(12, 0, 0, 0);
if (Now.getHours() >= 12) {
Next.setDate(Next.getDate() + 1);
}
return Next - Now;
}
// HANDLE ALARMS FIRING
chrome.alarms.onAlarm.addListener(function(alarm){
@ -40,16 +32,16 @@ chrome.alarms.onAlarm.addListener(function(alarm){
})
.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+!",
message: "A new update is available for Poly+! (v" + data.version + ")",
requiresInteraction: true
}, function(notificationID) {
chrome.notifications.onClicked.addListener(function (id) {
if (id === notificationID) {
chrome.tabs.create({url: 'https://github.com/IndexingGitHub/PolyPlus', active: true})
chrome.tabs.create({url: 'https://github.com/IndexingGitHub/PolyPlus/releases', active: true})
chrome.notifications.clear(notificationID)
}
})

View file

@ -6,7 +6,7 @@ var BestFriends;
let FavoriteBtn;
let CalculateButton;
if (UserID) {
if (UserID && !isNaN(UserID)) {
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
Settings = result.PolyPlus_Settings || {
IRLPriceWithCurrencyOn: false,
@ -56,89 +56,28 @@ if (UserID) {
alert('Failure to copy 3D avatar URL.')
});
});
} else if (UserID && UserID[0] === "@") {
const Username = window.location.pathname.split('/')[2].substring(1)
/*
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 = {
"useCharacter": true,
"items": [],
"shirt": null,
"pants": null,
"tool": null,
"headColor": "#111111",
"torsoColor": "#111111",
"leftArmColor": "#111111",
"rightArmColor": "#111111",
"leftLegColor": "#111111",
"rightLegColor": "#111111",
"face": "https://c0.ptacdn.com/static/3dview/DefaultFace.png"
let Reference = new URLSearchParams(new URL(window.location.href).search).get('ref')
if (Reference === null) {
Reference = ""
}
const Avatar = structuredClone(DefaultAvatar)
const Original = document.querySelector('.container .dropdown-item:nth-child(2)')
const Clone = Original.cloneNode(true)
Clone.classList.remove('text-danger')
Clone.classList.add('text-primary')
Clone.href = '#'
Clone.innerHTML = `
<i class="fa-duotone fa-book"></i>
Copy 3D Avatar URL
`
Clone.addEventListener('click', function(){
fetch('https://api.polytoria.com/v1/users/:id/avatar'.replace(':id', UserID))
.then(response => {
if (!response.ok) {
throw new Error('Network not ok')
}
fetch("https://api.polytoria.com/v1/users/find?username=" + Username)
.then(response => {
if (!response.ok) {
window.location.href = window.location.origin + decodeURIComponent(Reference)
} else {
return response.json()
})
.then(data => {
data.assets.forEach(item => {
switch(item.type) {
case 'hat':
Avatar.items.push(item.path)
break
case 'tool':
Avatar.tool = item.path
break
case 'face':
Avatar.face = item.path
break
case 'shirt':
Avatar.shirt = item.path
break
case 'pants':
Avatar.pants = item.path
break
}
});
Avatar.headColor = '#' + data.colors.head || '#cdcdcd'
Avatar.torsoColor = '#' + data.colors.torso || '#cdcdcd'
Avatar.leftArmColor = '#' + data.colors.leftArm || '#cdcdcd'
Avatar.rightArmColor = '#' + data.colors.rightArm || '#cdcdcd'
Avatar.leftLegColor = '#' + data.colors.leftLeg || '#cdcdcd'
Avatar.rightLegColor = '#' + data.colors.rightLeg || '#cdcdcd'
const URL = 'https://polytoria.com/ptstatic/itemview/#' + btoa(encodeURIComponent(JSON.stringify(Avatar)))
console.log('URL: ', URL)
navigator.clipboard.writeText(URL)
const SwalCopied = document.createElement('script')
SwalCopied.innerHTML = `
window.Swal.fire({title: "Copied", icon: "success", html: "The 3D avatar URL has been copied to clipboard!<br><a href='${URL}' target='_blank'>Preview it here!</a>"})
`
document.body.prepend(SwalCopied)
SwalCopied.remove()
})
.catch(error => {
console.log(error)
});
});
Original.parentElement.appendChild(Clone)
*/
}
})
.then(data => {
window.location.href = "https://polytoria.com/users/" + data.id
})
.catch(error => {
console.log("An error occurred:", error);
});
}
function HandleIRLPrice() {

View file

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

View file

@ -2,7 +2,6 @@
"manifest_version": 3,
"name": "Poly+",
"version": "1.0",
"version_name": "Public Beta",
"description": "Power-up your Polytoria experience with Poly+! Created by Index.",
"permissions": ["storage", "contextMenus", "tabs", "scripting", "alarms", "notifications"],
"content_scripts": [