From 02c0dc1630a7124543bd65a9a63479082c307d12 Mon Sep 17 00:00:00 2001 From: Ediz Baha Date: Sun, 18 Aug 2024 19:25:47 +0300 Subject: [PATCH] v2.1 Update --- README.md | 2 +- background.js | 77 +++++++++++++++++++++++---------- emoji.js | 23 ++++++++++ firefox-manifest.json | 32 +++++++------- manifest.json | 60 +++++++++++++------------- options.html | 85 ++++++++++++++++++++----------------- options.js | 36 +++++++--------- update.html | 99 +++++++++++++++++++++++++++++++++++++++++++ update.js | 24 +++++++++++ 9 files changed, 311 insertions(+), 127 deletions(-) create mode 100644 emoji.js create mode 100644 update.html create mode 100644 update.js diff --git a/README.md b/README.md index 001bcf6..5f50f38 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # status.lol bookmarklet -> ***Version: 1.3*** +> ***Version: 2.1*** *A simple bookmarklet extension for [status.lol](https://status.lol).* diff --git a/background.js b/background.js index 31d6c99..76fb18f 100644 --- a/background.js +++ b/background.js @@ -1,15 +1,46 @@ -// Fixed the issue of opening options.html in Chrome update +function checkForUpdates() { + fetch('https://ediz.paste.lol/status-bookmarklet/raw') + .then(response => response.json()) + .then(data => { + const currentVersion = chrome.runtime.getManifest().version; + const newVersion = data.version; + + if (compareVersions(currentVersion, newVersion) < 0) { + const changelogLines = data.changelog.split('\n').filter(line => line.trim() !== ''); + + chrome.storage.local.set({ + version: newVersion, + changelog: changelogLines, + url: data.url + }, () => { + chrome.tabs.create({ url: chrome.runtime.getURL('update.html') }); + }); + } + }) + .catch(error => console.error('Update check failed:', error)); +} + +function compareVersions(v1, v2) { + const v1Parts = v1.split('.').map(Number); + const v2Parts = v2.split('.').map(Number); + + while (v1Parts.length < v2Parts.length) v1Parts.push(0); + while (v2Parts.length < v1Parts.length) v2Parts.push(0); + + for (let i = 0; i < v1Parts.length; i++) { + if (v1Parts[i] > v2Parts[i]) return 1; + if (v1Parts[i] < v2Parts[i]) return -1; + } + return 0; +} + + + chrome.runtime.onInstalled.addListener((details) => { - // Check if the reason for onInstalled event is "install" or "update" if (details.reason === "install" || details.reason === "update") { - // Open the options page of the extension - chrome.runtime.openOptionsPage(); + checkForUpdates(); } -}); -// Create a context menu item with id "myContextMenuItem" and title "status.lol Bookmarklet" -// This context menu item will be shown when user right-clicks on a page, selection, or link -chrome.runtime.onInstalled.addListener(() => { chrome.contextMenus.create({ id: "myContextMenuItem", title: "status.lol Bookmarklet", @@ -17,29 +48,31 @@ chrome.runtime.onInstalled.addListener(() => { }); }); -// Add a listener for clicks on the "myContextMenuItem" context menu item -// When the context menu item is clicked, it opens a new popup window with a link to status.lol +chrome.runtime.onStartup.addListener(() => { + checkForUpdates(); +}); + chrome.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "myContextMenuItem") { chrome.storage.sync.get('address', (data) => { const address = data.address || 'foobar'; chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - const title = encodeURIComponent(tabs[0].title); - const url = encodeURIComponent(tabs[0].url); - const link = `https://home.omg.lol/address/${address}/statuslog-bookmarklet?title=${title}&url=${url}`; - chrome.windows.create({ - url: link, - type: "popup", - width: 700, - height: 670, - }); + if (tabs.length > 0) { + const title = encodeURIComponent(tabs[0].title); + const url = encodeURIComponent(tabs[0].url); + const link = `https://home.omg.lol/address/${address}/statuslog-bookmarklet?title=${title}&url=${url}`; + chrome.windows.create({ + url: link, + type: "popup", + width: 700, + height: 670, + }); + } }); }); } }); -// Add a listener for clicks on the extension's action button -// When the button is clicked, it opens a new popup window with a link to status.lol chrome.action.onClicked.addListener((tab) => { chrome.storage.sync.get('address', (data) => { const address = data.address || 'foobar'; @@ -53,4 +86,4 @@ chrome.action.onClicked.addListener((tab) => { height: 670, }); }); -}); \ No newline at end of file +}); diff --git a/emoji.js b/emoji.js new file mode 100644 index 0000000..0f429d4 --- /dev/null +++ b/emoji.js @@ -0,0 +1,23 @@ +(function() { + 'use strict'; + + function updateEmoji() { + chrome.storage.sync.get('emoji', (data) => { + const emoji = data.emoji || '👀'; + + fetch('https://api.omg.lol/statuslog/emoji/' + encodeURIComponent(emoji)) + .then((response) => response.json()) + .then((data) => { + let emojiImg = document.getElementById('emoji_img'); + let glyph = document.getElementById('glyph'); + if (emojiImg && glyph) { + emojiImg.setAttribute('src', data.response.img); + glyph.value = data.response.emoji; + } + }) + .catch((error) => console.error('API request error:', error)); + }); + } + + window.addEventListener('load', updateEmoji); +})(); diff --git a/firefox-manifest.json b/firefox-manifest.json index d05d9ef..5a48306 100644 --- a/firefox-manifest.json +++ b/firefox-manifest.json @@ -1,10 +1,9 @@ { "manifest_version": 3, "name": "status.lol Bookmarklet", - "version": "1.3", + "version": "2.1", "description": "A simple bookmarklet extension for status.lol.", - "icons": - { + "icons": { "512": "icon.png" }, "host_permissions": [ @@ -15,25 +14,26 @@ "storage", "contextMenus" ], - "background": - { - "scripts": ["background.js"] + "background": { + "service_worker": "background.js" }, - "action": - { + "action": { "default_icon": "icon.png", "default_title": "status.lol Bookmarklet" }, - "options_ui": - { + "options_ui": { "page": "options.html", "open_in_tab": true }, - "browser_specific_settings": - { - "gecko": - { + "browser_specific_settings": { + "gecko": { "id": "statuslol@omg.lol" } - } -} \ No newline at end of file + }, + "content_scripts": [ + { + "matches": ["https://home.omg.lol/address/*/statuslog-bookmarklet*"], + "js": ["emoji.js"] + } + ] +} diff --git a/manifest.json b/manifest.json index 862ba01..b64cecf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,32 +1,34 @@ { - "manifest_version": 3, - "name": "status.lol Bookmarklet", - "version": "1.3", - "description": "A simple bookmarklet extension for status.lol.", - "icons": + "manifest_version": 3, + "name": "status.lol Bookmarklet", + "version": "2.1", + "description": "A simple bookmarklet extension for status.lol.", + "icons": { + "512": "icon.png" + }, + "host_permissions": [ + "https://home.omg.lol/*" + ], + "permissions": [ + "activeTab", + "storage", + "contextMenus" + ], + "background": { + "service_worker": "background.js" + }, + "action": { + "default_icon": "icon.png", + "default_title": "status.lol Bookmarklet" + }, + "options_ui": { + "page": "options.html", + "open_in_tab": true + }, + "content_scripts": [ { - "512": "icon.png" - }, - "host_permissions": [ - "https://home.omg.lol/*" - ], - "permissions": [ - "activeTab", - "storage", - "contextMenus" - ], - "background": - { - "service_worker": "background.js" - }, - "action": - { - "default_icon": "icon.png", - "default_title": "status.lol Bookmarklet" - }, - "options_ui": - { - "page": "options.html", - "open_in_tab": true + "matches": ["https://home.omg.lol/address/*/statuslog-bookmarklet*"], + "js": ["emoji.js"] } -} \ No newline at end of file + ] +} diff --git a/options.html b/options.html index 641788f..fc887f4 100644 --- a/options.html +++ b/options.html @@ -1,42 +1,51 @@ - - status.lol Bookmarklet - Options - - - -
-
- status.lol Bookmarklet - Prami + + status.lol Bookmarklet - Options + + + +
+
+ status.lol Bookmarklet + Prami +
+
+
+
+

+ + +

+

+ + +

+ +
-
-
-
-

- - -

- -
-
-
-
- - +
+
+ + \ No newline at end of file diff --git a/options.js b/options.js index 12f4d48..44eec09 100644 --- a/options.js +++ b/options.js @@ -1,33 +1,27 @@ document.addEventListener("DOMContentLoaded", () => { - // Get the saved address from storage - chrome.storage.sync.get('address', (data) => { - // Get the input element for the address + chrome.storage.sync.get(['address', 'emoji'], (data) => { const addressInput = document.getElementById('address'); - // Get the saved address from storage, or set it to an empty string if it doesn't exist - const savedaddress = data.address || ''; - // Set the value of the address input element to the saved address - addressInput.value = savedaddress; + const emojiInput = document.getElementById('emoji'); + const savedAddress = data.address || ''; + const savedEmoji = data.emoji || ''; + addressInput.value = savedAddress; + emojiInput.value = savedEmoji; }); - // Save the address to storage when the Save button is clicked const saveButton = document.getElementById('saveButton'); saveButton.addEventListener('click', () => { - // Get the input element for the address const addressInput = document.getElementById('address'); - // Get the new address entered by the user, and remove any leading/trailing white space - const newaddress = addressInput.value.trim(); - // Check if the new address is empty - if (newaddress === '') { - // If it is, display an alert message and exit the function + const emojiInput = document.getElementById('emoji'); + const newAddress = addressInput.value.trim(); + const newEmoji = emojiInput.value.trim(); + if (newAddress === '') { alert('Please enter a valid address'); return; } - // Save the new address to storage - chrome.storage.sync.set({ 'address': newaddress }, () => { - // Log a message to the console indicating that the address has been saved - console.log(`Address saved: ${newaddress}`); - // Display an alert message to the user indicating that the address has been saved - alert(`Address saved: ${newaddress}`); + chrome.storage.sync.set({ 'address': newAddress, 'emoji': newEmoji }, () => { + console.log(`Address saved: ${newAddress}`); + console.log(`Emoji saved: ${newEmoji}`); + alert(`Address and emoji saved: ${newAddress} - ${newEmoji}`); }); }); -}); +}); \ No newline at end of file diff --git a/update.html b/update.html new file mode 100644 index 0000000..9a99885 --- /dev/null +++ b/update.html @@ -0,0 +1,99 @@ + + + + + Update Available! + + + + + +
+
+ status.lol Bookmarklet + Prami +
+
+

v of the status.lol bookmarklet extension is available. Please update to the latest version.

+
+

What's New:

+

+
+ +
+ + + + \ No newline at end of file diff --git a/update.js b/update.js new file mode 100644 index 0000000..b858918 --- /dev/null +++ b/update.js @@ -0,0 +1,24 @@ +document.addEventListener("DOMContentLoaded", () => { + chrome.storage.local.get(['version', 'changelog', 'url'], (data) => { + const versionContent = document.getElementById('version-content'); + const changelogContent = document.getElementById('changelog-content'); + const updateButton = document.getElementById('update-button'); + + versionContent.textContent = data.version || 'Unknown Version'; + + if (data.changelog) { + const changelogLines = data.changelog; + changelogContent.innerHTML = changelogLines.map(line => `

${line}

`).join(''); + } else { + changelogContent.innerHTML = '

No changelog available.

'; + } + + updateButton.addEventListener('click', () => { + if (data.url) { + chrome.tabs.create({ url: data.url }); + } else { + alert('No update URL available.'); + } + }); + }); +}); \ No newline at end of file