-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,52 @@ | ||
// 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.runtime.openOptionsPage(); | ||
chrome.contextMenus.create({ | ||
id: "myContextMenuItem", | ||
title: "status.lol Bookmarklet", | ||
contexts: ["page", "selection", "link"] | ||
}); | ||
}); | ||
|
||
// 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.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, | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
// 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('username', (data) => { | ||
const username = data.username || 'default-username'; | ||
chrome.storage.sync.get('address', (data) => { | ||
const address = data.address || 'foobar'; | ||
const title = encodeURIComponent(tab.title); | ||
const url = encodeURIComponent(tab.url); | ||
const link = `https://home.omg.lol/address/${username}/statuslog-bookmarklet?title=${title}&url=${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, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Open the extension's options page when the extension is installed | ||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.runtime.openOptionsPage(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
document.addEventListener("DOMContentLoaded", () => { | ||
// Get the saved username from storage | ||
chrome.storage.sync.get('username', (data) => { | ||
const usernameInput = document.getElementById('username'); | ||
const savedUsername = data.username || 'foobar'; | ||
usernameInput.value = savedUsername; | ||
// Get the saved address from storage | ||
chrome.storage.sync.get('address', (data) => { | ||
// Get the input element for the address | ||
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; | ||
}); | ||
|
||
// Save the username to storage when the Save button is clicked | ||
// Save the address to storage when the Save button is clicked | ||
const saveButton = document.getElementById('saveButton'); | ||
saveButton.addEventListener('click', () => { | ||
const usernameInput = document.getElementById('username'); | ||
const newUsername = usernameInput.value.trim(); | ||
if (newUsername !== '') { | ||
chrome.storage.sync.set({ 'username': newUsername }, () => { | ||
console.log(`Address saved: ${newUsername}`); | ||
alert(`Address saved: ${newUsername}`); | ||
}); | ||
// 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 | ||
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}`); | ||
}); | ||
}); | ||
}); |