forked from karlerikjonatan/chrome-empty-new-tab
-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
25 lines (22 loc) · 770 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const body = document.body;
body.innerHTML = localStorage.getItem('notes') || '';
body.onkeyup = () => localStorage.setItem('notes', body.innerHTML);
// Inter Tab Synchronization
window.onstorage = (event) => { body.innerHTML = event.newValue; };
// Key Events
document.onkeydown = (event) => {
// Change Tab to Spaces
if (event.code === 'Tab') {
event.preventDefault();
const spaces = ' ';
document.execCommand('insertText', false, spaces);
}
// Save per ⌘ + S
if (event.metaKey && event.key === 's') {
event.preventDefault();
const link = document.createElement('a');
link.download = 'notes.html';
link.href = `data:text/html,<!DOCTYPE html>\n${body.parentElement.outerHTML}`;
link.click();
}
};