Skip to content

Commit

Permalink
Update to v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
edizbaha committed Mar 14, 2023
1 parent 00c1976 commit e80ff08
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 22 deletions.
44 changes: 39 additions & 5 deletions background.js
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();
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "status.lol Bookmarklet",
"version": "1.0",
"version": "1.1",
"description": "A simple bookmarklet extension for status.lol.",
"icons": {
"512": "icon.png"
Expand Down
6 changes: 3 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<div class="box basis" style="--basis: 20em;">
<form>
<p>
<label for="username">omg.lol Address</label>
<input name="username" id="username" type="text" placeholder="foobar" spellcheck="false" autocapitalize="none" autocomplete="off">
<label for="address">omg.lol Address</label>
<input name="address" id="address" type="text" placeholder="foobar" spellcheck="false" autocapitalize="none" autocomplete="off">
</p>
<button class="blue-7-bg white-fg" id="saveButton">
<i class="fa-solid fa-floppy-disk"></i> Save </button>
Expand All @@ -39,4 +39,4 @@
</main>
<script src="options.js"></script>
</body>
</html>
</html>
38 changes: 25 additions & 13 deletions options.js
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}`);
});
});
});

0 comments on commit e80ff08

Please sign in to comment.