This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/background.js
Index 3e01832005 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
2024-01-23 17:27:49 -06:00

150 lines
No EOL
4.5 KiB
JavaScript
Executable file

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({
title: 'Copy Asset ID',
id: 'PolyPlus-CopyID',
contexts: ['link'],
documentUrlPatterns: ['https://polytoria.com/*'],
targetUrlPatterns: [
"https://polytoria.com/places/**",
"https://polytoria.com/users/**",
"https://polytoria.com/store/**"
]
});
// COPY AVATAR HASH CONTEXT MENU ITEM REGISTRATION
chrome.contextMenus.create({
title: 'Copy Avatar Hash',
id: 'PolyPlus-CopyAvatarHash',
contexts: ['image'],
documentUrlPatterns: ['https://polytoria.com/*'],
targetUrlPatterns: [
"https://c0.ptacdn.com/thumbnails/avatars/**",
"https://c0.ptacdn.com/thumbnails/avatars/**"
]
});
// HANDLE CONTEXT MENU ITEMS
chrome.contextMenus.onClicked.addListener(function (info, tab){
if (info.menuItemId === 'PolyPlus-CopyID') {
let ID = parseInt(info.linkUrl.split('/')[4])
chrome.scripting
.executeScript({
target: {tabId: tab.id},
func: CopyAssetID,
args: [ID]
})
.then(() => console.log("Copied ID!"));
}
if (info.menuItemId === 'PolyPlus-CopyAvatarHash') {
let Hash = new URL(info.srcUrl).pathname.split('/')[3].replace('-icon', '').replace('.png', '')
chrome.scripting
.executeScript({
target: {tabId: tab.id},
func: CopyAvatarHash,
args: [Hash]
})
.then(() => console.log("Copied ID!"));
}
});
function CopyAssetID(id) {
navigator.clipboard
.writeText(id)
.then(() => {
alert('Successfully copied ID!')
})
.catch(() => {
alert('Failure to copy ID.')
});
}
function CopyAvatarHash(hash) {
navigator.clipboard
.writeText(hash)
.then(() => {
alert('Successfully copied avatar hash!')
})
.catch(() => {
alert('Failure to copy avatar hash.')
});
}
function HandleJoinPlace(url) {
console.log('HANDLING JOINING PLACE')
const PlaceID = new URL(url).pathname.split('/')[2]
fetch('https://polytoria.com/api/places/join',{
method: 'POST',
body: {
placeID:PlaceID
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network not ok')
}
return response.json()
})
.then(data => {
if (data.success !== true) {throw new Error(data.message)}
window.location.href = 'polytoria://client/' + data.token
})
.catch(error => {console.log(error)})
}
export default {
hi: 1
}