skip to Main Content

I am trying to make a bookmarklet to take notes but I can’t get to work here’s the bookmarklet that it is based off of.

javascript:(function(){
function save() {
localStorage.setItem('SavedState', document.body.innerHTML);
alert('State saved!');
}
function load() {
var savedContent = localStorage.getItem('SavedState');
if (savedContent !== null) {
document.body.innerHTML = savedContent;
alert('State loaded!');
} else {
alert('No saved state found.');
}}
var saveorload = prompt('save or load? It must be exactly save or load.');
if (saveorload == 'save') {
save();
}
if (saveorload == 'load') {
load();
}})()

And here’s the notes bookmarklet.

javascript:(function(){
function take() {
var notetotake = prompt('Note?');
localStorage.setItem('notes', notetotake);
alert('State saved!');
}
function read() {
var notetoread = localStorage.getItem('notes');
if (notetoread !== null) {
prompt('Copy this text', oldnotes);
} else {
alert('No taken notes found.');
}}
var todo = prompt('take or read? It must be exactly take or read.');
if (todo == 'take') {
take();
}
if (todo == 'read') {
read();
}})()

Please help fix this bookmarklet.

I tried it and it just won’t work for me.

2

Answers


  1. Chosen as BEST ANSWER

    Nvm sorry I got it to work.

    javascript:(function(){
    function take() {
    var notetotake = prompt('Note?');
    localStorage.setItem('notes', notetotake);
    alert('Note taken!');
    }
    function read() {
    var notetoread = localStorage.getItem('notes');
    if (notetoread !== null) {
    prompt('Here`s your note!', notetoread);
    } else {
    alert('No taken notes found!');
    }}
    var todo = prompt('take or read? It must be exactly take or read.');
    if (todo == 'take') {
    take();
    }
    if (todo == 'read') {
    read();
    }})()
    

  2. There is a typo in your read function.

    ...
    function read() {
    var notetoread = localStorage.getItem('notes');    <-- here you create variable 'notetoread'
    if (notetoread !== null) {
    prompt('Copy this text', oldnotes);                <-- here you use 'oldnotes' variable
    ...
    

    If you change prompt('Copy this text', oldnotes); to prompt('Copy this text', notetoread); your bookmarklet should work fine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search