NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

removeFromStorage = (storage, key) => {
storage.removeItem(key);
};

deleteSelected = (storage, listId) => {
if (confirm("Are you sure?") === false) {
return;
}
const list = document.getElementById(listId);
const checkboxes = list.querySelectorAll("input[type='checkbox']:checked");
checkboxes.forEach((checkbox) => {
const key = checkbox.value;
removeFromStorage(storage, key);
});
getLocalStorageItems();
updateDeleteButtonState(listId);
};

handleFromStorage = (event) => {
if (event.target.classList.contains("delete")) {
if (confirm("Are you sure?") === false) {
return;
}
const storage = event.target.classList.contains("localList")
? localStorage
: sessionStorage;
const key = event.target.dataset.local;
removeFromStorage(storage, key);
getLocalStorageItems();
updateDeleteButtonState(storage === localStorage ? "localList" : "sessionList");
} else if (event.target.classList.contains("form-check-input")) {
const listId = event.target.closest("ul").id;
updateSelectAllCheckbox(listId);
updateDeleteButtonState(listId);
}
};

setStorage = (storage, list) => {
for (let i = 0; i < storage.length; i++) {
const li = document.createElement("li");
li.classList.add("list-group-item");

const spanKey = document.createElement("b");
spanKey.innerHTML = storage.key(i);

const spanValue = document.createElement("span");
spanValue.innerHTML = storage.getItem(storage.key(i));

const deleteButton = document.createElement("button");
deleteButton.classList.add(
"btn",
"btn-danger",
"btn-sm",
"float-end",
"delete",
`${list.id}`
);
deleteButton.innerHTML = "Delete";
deleteButton.dataset.local = storage.key(i);

const div = document.createElement("div");
div.classList.add("form-check");

const checkInput = document.createElement("input");
checkInput.classList.add("form-check-input");
checkInput.type = "checkbox";
checkInput.value = storage.key(i);
checkInput.id = `${list.id}Check`;

div.appendChild(checkInput);

li.appendChild(div);
li.appendChild(spanKey);
li.appendChild(document.createTextNode(" : "));
li.appendChild(spanValue);
li.appendChild(document.createTextNode(" "));
li.appendChild(deleteButton);

list.appendChild(li);
}
};

getLocalStorageItems = () => {
const list = document.getElementById("localList");
const sessionList = document.getElementById("sessionList");

document.querySelectorAll("ul").forEach((ul) => {
ul.innerHTML = "";
ul.classList.add("list-group", "list-group-flush");
});

setStorage(localStorage, list);
setStorage(sessionStorage, sessionList);
};

updateSelectAllCheckbox = (listId) => {
const list = document.getElementById(listId);
const checkboxes = list.querySelectorAll("input[type='checkbox']");
const allChecked = Array.from(checkboxes).every((checkbox) => checkbox.checked);
const selectAllCheckbox = document.getElementById(`${listId === "localList" ? "localCheckAll" : "sessionCheckAll"}`);
selectAllCheckbox.checked = allChecked;
};

updateDeleteButtonState = (listId) => {
const list = document.getElementById(listId);
const checkboxes = list.querySelectorAll("input[type='checkbox']:checked");
const deleteButton = document.getElementById(listId === "localList" ? "deleteLocalSelected" : "deleteSessionSelected");
deleteButton.style.display = checkboxes.length > 0 ? 'inline-block' : 'none';
};

document.addEventListener("DOMContentLoaded", function () {
getLocalStorageItems();

const keyInput = document.getElementById("key");
const valueInput = document.getElementById("value");
const saveButton = document.getElementById("btn-save");
const list = document.getElementById("localList");
const sessionList = document.getElementById("sessionList");

const localCheckAll = document.getElementById("localCheckAll");
const sessionCheckAll = document.getElementById("sessionCheckAll");

const deleteLocalSelected = document.getElementById("deleteLocalSelected");
const deleteSessionSelected = document.getElementById("deleteSessionSelected");

list.addEventListener("click", handleFromStorage);
sessionList.addEventListener("click", handleFromStorage);

saveButton.addEventListener("click", function () {
const value = valueInput.value;
const key = keyInput.value;

localStorage.setItem(key, value);
sessionStorage.setItem(key, value);

getLocalStorageItems();
document.querySelectorAll("input").forEach((input) => (input.value = ""));
updateDeleteButtonState("localList");
updateDeleteButtonState("sessionList");
});

localCheckAll.addEventListener("change", function () {
const checkboxes = list.querySelectorAll("input[type='checkbox']");
checkboxes.forEach((checkbox) => {
checkbox.checked = localCheckAll.checked;
});
updateDeleteButtonState("localList");
});

sessionCheckAll.addEventListener("change", function () {
const checkboxes = sessionList.querySelectorAll("input[type='checkbox']");
checkboxes.forEach((checkbox) => {
checkbox.checked = sessionCheckAll.checked;
});
updateDeleteButtonState("sessionList");
});

deleteLocalSelected.addEventListener("click", function () {
deleteSelected(localStorage, "localList");
});

deleteSessionSelected.addEventListener("click", function () {
deleteSelected(sessionStorage, "sessionList");
});

updateDeleteButtonState("localList");
updateDeleteButtonState("sessionList");
});
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.