From 3e018320050f269b3a33f72e157f6679627e2aff Mon Sep 17 00:00:00 2001 From: Index Date: Tue, 23 Jan 2024 17:27:49 -0600 Subject: [PATCH] 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 --- css/specific.css | 6 +- js/account/create.js | 7 - js/account/inbox.js | 47 ++++ js/background.js | 75 ++++-- js/debug.js | 53 +++++ js/forum/forum-view-old.js | 173 ++++++++++++++ .../{forum-view2.js => forum-view-old2.js} | 0 js/forum/forum-view.js | 220 ++++-------------- js/forum/new-forum-view.js | 22 -- js/membership-themes.js | 4 +- js/places/place-join.js | 6 +- js/places/place-view.js | 40 ++-- js/polyplus-settings.js | 2 - js/profile/simplified-profile.js | 37 +-- js/utils.js | 95 ++++++++ manifest.json | 28 ++- popup.html | 6 +- settings.html | 7 +- 18 files changed, 548 insertions(+), 280 deletions(-) delete mode 100755 js/account/create.js create mode 100644 js/account/inbox.js create mode 100644 js/debug.js create mode 100755 js/forum/forum-view-old.js rename js/forum/{forum-view2.js => forum-view-old2.js} (100%) mode change 100755 => 100644 js/forum/forum-view.js delete mode 100644 js/forum/new-forum-view.js create mode 100644 js/utils.js diff --git a/css/specific.css b/css/specific.css index 963f529..c47950e 100755 --- a/css/specific.css +++ b/css/specific.css @@ -11,7 +11,7 @@ body[data-URL^="https://polytoria.com/create/"] .col.d-flex.align-content-betwee } .text-truncate { - white-space: nowrap !important; /* Prevents text from wrapping to the next line */ - overflow: hidden !important; /* Hides the overflowing text */ - text-overflow: ellipsis !important; /* Adds an ellipsis (...) to indicate truncated text */ + white-space: nowrap !important; + overflow: hidden !important; + text-overflow: ellipsis !important; } \ No newline at end of file diff --git a/js/account/create.js b/js/account/create.js deleted file mode 100755 index bcd28ab..0000000 --- a/js/account/create.js +++ /dev/null @@ -1,7 +0,0 @@ -let NavColumn = document.getElementsByClassName('col-lg-2')[0] -let LaunchCreatorBtn = document.createElement('button') -LaunchCreatorBtn.classList = 'btn btn-success w-100' -LaunchCreatorBtn.innerText = 'Launch Creator' -LaunchCreatorBtn.setAttribute('data-id', '1') -LaunchCreatorBtn.setAttribute('onclick', 'editPlace(this)') -NavColumn.appendChild(LaunchCreatorBtn) \ No newline at end of file diff --git a/js/account/inbox.js b/js/account/inbox.js new file mode 100644 index 0000000..f5324d4 --- /dev/null +++ b/js/account/inbox.js @@ -0,0 +1,47 @@ +HandleExpandMessages() + +function HandleExpandMessages() { + const Messages = document.getElementById('messages') + + for (let message of Messages.children) { + let Expanded = false + let ContentDiv = null + + const ViewButton = message.querySelector('a.btn[href^="/inbox/messages"]') + const MessageID = ViewButton.getAttribute('href').split('/')[3] + + const ExpandButton = document.createElement('button') + ExpandButton.classList = 'btn btn-outline-warning px-4 mt-1' + ExpandButton.innerText = 'Expand' + ViewButton.parentElement.appendChild(ExpandButton) + + ExpandButton.addEventListener('click', function(){ + if (ContentDiv === null) { + fetch('https://polytoria.com/inbox/messages/'+MessageID) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.text() + }) + .then(data => { + const Doc = new DOMParser().parseFromString(data, 'text/html') + const MessageContent = Doc.querySelector('p.mb-0').innerText + + ContentDiv = document.createElement('div') + ContentDiv.classList = 'py-2' + ContentDiv.innerText = MessageContent + message.appendChild(ContentDiv) + }) + .catch(error => { + console.log(error) + }); + } + + Expanded = !Expanded + + ExpandButton.innerText = (Expanded === false) ? 'Expand' : 'Minimize' + ContentDiv.style.display = (Expanded === false) ? 'none' : 'block' + }); + } +} \ No newline at end of file diff --git a/js/background.js b/js/background.js index 3c3b1ba..44cccfc 100755 --- a/js/background.js +++ b/js/background.js @@ -1,3 +1,57 @@ +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', @@ -10,6 +64,7 @@ chrome.contextMenus.create({ ] }); +// COPY AVATAR HASH CONTEXT MENU ITEM REGISTRATION chrome.contextMenus.create({ title: 'Copy Avatar Hash', id: 'PolyPlus-CopyAvatarHash', @@ -21,6 +76,7 @@ chrome.contextMenus.create({ ] }); +// HANDLE CONTEXT MENU ITEMS chrome.contextMenus.onClicked.addListener(function (info, tab){ if (info.menuItemId === 'PolyPlus-CopyID') { let ID = parseInt(info.linkUrl.split('/')[4]) @@ -45,21 +101,6 @@ chrome.contextMenus.onClicked.addListener(function (info, tab){ } }); -/* -chrome.webNavigation.onCompleted.addListener(function (details){ - console.log('TAB CREATED') - - chrome.scripting - .executeScript({ - target: {tabId: details.tabId}, - func: HandleJoinPlace, - args: [details.url] - }) -}, { - url: [{ urlMatches: "https://polytoria.com/join-place/*" }] -}); -*/ - function CopyAssetID(id) { navigator.clipboard .writeText(id) @@ -102,4 +143,8 @@ function HandleJoinPlace(url) { window.location.href = 'polytoria://client/' + data.token }) .catch(error => {console.log(error)}) +} + +export default { + hi: 1 } \ No newline at end of file diff --git a/js/debug.js b/js/debug.js new file mode 100644 index 0000000..d28ace0 --- /dev/null +++ b/js/debug.js @@ -0,0 +1,53 @@ +// DEBUG MENU FOR CLEARING PINNED GAMES AND BEST FRIENDS +document.querySelector('#main-content .container').innerHTML = ` + + +
+ + + +
+ + +
+ + + +
+` + +const ClearPins = document.getElementById('clear-pins') +const ClearBF = document.getElementById('clear-bf') +const EditSettingName = document.getElementById('edit-setting-name') +const EditSettingValue = document.getElementById('edit-setting-value') +const EditSettingBtn = document.getElementById('edit-setting') + +ClearPins.addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() { + alert('Successfully cleared Pinned Games.') + }); +}); + +ClearBF.addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() { + alert('Successfully cleared Best Friends.') + }); +}); + +EditSettingBtn.addEventListener('click', function(){ + chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { + result = result.PolyPlus_Settings + + let NewValue = EditSettingValue.value + if (NewValue === "true") {NewValue = true} + if (NewValue === "false") {NewValue = false} + if (parseInt(NewValue)) {NewValue = parseInt(NewValue)} + result[EditSettingName.value] = NewValue + + chrome.storage.sync.set({ 'PolyPlus_Settings': result }, function() { + alert('Successfully set: "' + EditSettingName.value + '" to ' + NewValue) + }); + + alert('Successfully cleared Best Friends.') + }); +}); \ No newline at end of file diff --git a/js/forum/forum-view-old.js b/js/forum/forum-view-old.js new file mode 100755 index 0000000..f999098 --- /dev/null +++ b/js/forum/forum-view-old.js @@ -0,0 +1,173 @@ +var idCache = [] +let url = "https://polytoria.com/users/:id" + +console.log('loaded!') + +function LowAttentionSpanMode() { + let PostContent = document.querySelector('.mcard p:nth-child(3)').textContent + let Captions = CombineArray(PostContent.split(' ')).map((x, i) => `${x}`).join('') + let NumberOfCaptions = (PostContent.split(' ').length) - 1 + Swal.fire({ + title: "No Attention Span Mode", + html: ` +