Bookmarklet to Save & Retrieve Frequently Used Text Snippets
Do you often type the same text over and over again?
Snippets Bookmarklet saves snippets of the text you need, in your browser storage with names of your choice & retrieves them with a single click.
Just click the bookmarklet anytime you find something you want to save for later. Give your snippet a name, and it will be stored securely in your browser.
To view your saved snippets, click the bookmarklet again and select the name you gave it. The snippet will be inserted in the input element where you need it.
I employed Anthropic's Claude AI assistant to generate bookmarklet code by prompting my requirement:
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
javascript:(function(){ | |
//The getInput function is defined to prompt the user for input. | |
function getInput(text){return prompt(text)} | |
//the localStorage will be used to store & retrieve keys and values. | |
d = localStorage; | |
//The user is prompted to enter either "get" or "set" to choose the action. | |
a = getInput('Enter "get" or "set": '); | |
//If the user chooses "get," they are prompted to enter a key. | |
if (a == "get") { | |
k = d.length ? [...Array(d.length)].map(i => d.key(i)).filter(key => key.startsWith('z_')) : []; // Filter keys with "z_" prefix | |
key = getInput("Keys: " + k + "\nEnter key:"); | |
//If the key exists, the corresponding value is inserted into the textarea with the ID "prompt-textarea". | |
if (d.getItem(key)) document.getElementById("prompt-textarea").value = d.getItem(key); | |
//If not, an alert is displayed indicating that the key does not exist. | |
else alert("Key does not exist!"); | |
} | |
//If the user chooses "set," they are prompted to enter a new key and a value, and this key-value pair is stored in the local storage. | |
else if (a == "set") { | |
key = "z_" + getInput("Enter new key: "); // Add "z_" prefix automatically to identify our custom keys | |
value = getInput("Enter value to store:"); | |
//key-value pair is stored in localStorage. | |
d.setItem(key, value); | |
} else { | |
alert("Invalid action"); | |
} | |
})() |
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
javascript:(function(){function g(t){return prompt(t)}d=localStorage;a=g('Enter "get" or "set": ');if(a=="get"){k=d.length?[...Array(d.length)].map(i=>d.key(i)).filter(k=>k.startsWith('z_')):[];k=g("Keys: "+k+"\nEnter key:");if(d.getItem(k))document.getElementById("prompt-textarea").value=d.getItem(k);else alert("Key does not exist!")}else if(a=="set"){k="z_"+g("Enter new key: ");v=g("Enter value to store:");d.setItem(k,v)}else alert("Invalid action")})() |
Here's how to use it:
- Create a new bookmark in your browser.
- Edit the bookmark and set the name to something like "Snippets".
- Paste the above code into the URL or Location field.
Alternatively drag and drop this link (after checking and adapting the words-per-minute rate) to the Bookmarks bar or Favorites bar in Chrome or Edge to see how it works - Snippets
Comments
Post a Comment