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:
parent
a39ae5ad31
commit
f0b07d2ddc
4 changed files with 35 additions and 126 deletions
|
|
@ -5,28 +5,20 @@ chrome.action.onClicked.addListener((tab) => {
|
||||||
chrome.tabs.create({ active: true, url: chrome.runtime.getURL('settings.html') });
|
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)
|
// REGISTER AN ALARM FOR DAILY UPDATE CHECK
|
||||||
// Calculate the milliseconds until the next 12 PM
|
chrome.alarms.create('PolyPlus-UpdateCheck', {
|
||||||
/*
|
when: Date.now() + (GetNext12PM())
|
||||||
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
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
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
|
// HANDLE ALARMS FIRING
|
||||||
chrome.alarms.onAlarm.addListener(function(alarm){
|
chrome.alarms.onAlarm.addListener(function(alarm){
|
||||||
|
|
@ -40,16 +32,16 @@ chrome.alarms.onAlarm.addListener(function(alarm){
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.version > Manifest.version) {
|
if (data.version > Manifest.version) {
|
||||||
console.log('Update available')
|
|
||||||
chrome.notifications.create("", {
|
chrome.notifications.create("", {
|
||||||
type: "basic",
|
type: "basic",
|
||||||
iconUrl: chrome.runtime.getURL("icon.png"),
|
iconUrl: chrome.runtime.getURL("icon.png"),
|
||||||
title: "New Update Available",
|
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) {
|
}, function(notificationID) {
|
||||||
chrome.notifications.onClicked.addListener(function (id) {
|
chrome.notifications.onClicked.addListener(function (id) {
|
||||||
if (id === notificationID) {
|
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)
|
chrome.notifications.clear(notificationID)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ var BestFriends;
|
||||||
let FavoriteBtn;
|
let FavoriteBtn;
|
||||||
let CalculateButton;
|
let CalculateButton;
|
||||||
|
|
||||||
if (UserID) {
|
if (UserID && !isNaN(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 || {
|
||||||
IRLPriceWithCurrencyOn: false,
|
IRLPriceWithCurrencyOn: false,
|
||||||
|
|
@ -56,89 +56,28 @@ if (UserID) {
|
||||||
alert('Failure to copy 3D avatar URL.')
|
alert('Failure to copy 3D avatar URL.')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else if (UserID && UserID[0] === "@") {
|
||||||
|
const Username = window.location.pathname.split('/')[2].substring(1)
|
||||||
|
|
||||||
/*
|
let Reference = new URLSearchParams(new URL(window.location.href).search).get('ref')
|
||||||
Way overcomplicated code when there is literally an iframe on the page with the exact same result
|
if (Reference === null) {
|
||||||
|
Reference = ""
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
const Avatar = structuredClone(DefaultAvatar)
|
|
||||||
|
|
||||||
const Original = document.querySelector('.container .dropdown-item:nth-child(2)')
|
fetch("https://api.polytoria.com/v1/users/find?username=" + Username)
|
||||||
const Clone = Original.cloneNode(true)
|
.then(response => {
|
||||||
Clone.classList.remove('text-danger')
|
if (!response.ok) {
|
||||||
Clone.classList.add('text-primary')
|
window.location.href = window.location.origin + decodeURIComponent(Reference)
|
||||||
Clone.href = '#'
|
} else {
|
||||||
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')
|
|
||||||
}
|
|
||||||
return response.json()
|
return response.json()
|
||||||
})
|
}
|
||||||
.then(data => {
|
})
|
||||||
data.assets.forEach(item => {
|
.then(data => {
|
||||||
switch(item.type) {
|
window.location.href = "https://polytoria.com/users/" + data.id
|
||||||
case 'hat':
|
})
|
||||||
Avatar.items.push(item.path)
|
.catch(error => {
|
||||||
break
|
console.log("An error occurred:", error);
|
||||||
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)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function HandleIRLPrice() {
|
function HandleIRLPrice() {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
});
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Poly+",
|
"name": "Poly+",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"version_name": "Public Beta",
|
|
||||||
"description": "Power-up your Polytoria experience with Poly+! Created by Index.",
|
"description": "Power-up your Polytoria experience with Poly+! Created by Index.",
|
||||||
"permissions": ["storage", "contextMenus", "tabs", "scripting", "alarms", "notifications"],
|
"permissions": ["storage", "contextMenus", "tabs", "scripting", "alarms", "notifications"],
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
|
||||||
Reference in a new issue