A personal dictionary
Whenever I encountered a new word on the internet I used to:
- open a new tab
- search the word definition
- copy and paste it into a local file
These steps were inefficient and interrupted my reading. So I made a small browser extension using ajax:
function insertToDictionaryDB(term, url=document.URL) {
var obj = {term: term, url: url}
var response = $.ajax({
type: 'POST',
url: "http://localhost:3131",
data: obj,
dataType: 'text',
success: function(d) { console.log("OK")},
error: function() { console.log("Something went wrong") }
});
}
document.addEventListener('keydown', function(e) {
switch(true) {
case e.ctrlKey && e.key === 'd': term = prompt('Term:'); url = prompt('URL:', document.URL); insertToDictionaryDB(term, url); break;
}
}
This function (which is mapped to Ctrl+D
) sends a json string with a term
and url
to a listening local server http://localhost:3131
.
The server searches the word definition, stores it in a database, and opens a dialog with the word definition.
All triggered with a single keystroke, and without leaving the browser 👌.