Skip to content

Commit ec83390

Browse files
committed
Initial commit
0 parents  commit ec83390

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

manifest.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Tab Notes",
4+
"browser_specific_settings": {
5+
"gecko": {
6+
"id": "tab-notes@nishit",
7+
"strict_min_version": "42.0"
8+
}
9+
},
10+
"version": "0.1.0",
11+
"author": "Nishit",
12+
"description": "Allow you to write anything in new tab",
13+
"permissions": ["storage"],
14+
"chrome_url_overrides": {
15+
"newtab": "newtab.html"
16+
},
17+
18+
"browser_action": {
19+
"browser_style": true,
20+
"default_title": "Tab notes",
21+
"default_popup": "newtab.html"
22+
},
23+
24+
"commands": {
25+
"_execute_browser_action": {
26+
"suggested_key": {
27+
"default": "Ctrl+Y"
28+
}
29+
}
30+
}
31+
}

newtab.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=<device-width>, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Document</title>
8+
<script type="text/javascript" src="./tabnotes.js"></script>
9+
</head>
10+
<style>
11+
body {
12+
margin: 0px;
13+
}
14+
#notes {
15+
box-sizing: border-box;
16+
border: 0;
17+
font-size: 18px;
18+
line-height: 1.75rem;
19+
margin: 0;
20+
min-height: 100vh;
21+
height: auto;
22+
padding: 2rem 20%;
23+
resize: none;
24+
width: 100%;
25+
}
26+
#notes {
27+
background: #343434;
28+
color: #fff;
29+
}
30+
</style>
31+
<body>
32+
<textarea id="notes" placeholder="Start writing."></textarea>
33+
</body>
34+
</html>

tabnotes.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var timeoutId;
2+
const notes = document.getElementById("notes");
3+
document.addEventListener("keyup", logKey);
4+
browser.tabs.onActivated.addListener(tabOpen);
5+
browser.windows.onFocusChanged.addListener(tabOpen);
6+
7+
function logKey(e) {
8+
console.log("Textarea Change");
9+
clearTimeout(timeoutId);
10+
timeoutId = setTimeout(function() {
11+
// Runs 1 second (1000 ms) after the last change
12+
saveToDB();
13+
}, 1000);
14+
}
15+
16+
function saveToDB() {
17+
browser.storage.sync.set({
18+
tab_note: document.querySelector("#notes").value
19+
});
20+
}
21+
22+
function tabOpen(tab) {
23+
console.log("tab open");
24+
browser.storage.sync.get("tab_note").then(result => {
25+
console.log(result);
26+
document.querySelector("#notes").value = result.tab_note;
27+
});
28+
}
29+
30+
31+
window.addEventListener('load', () => {
32+
tabOpen()
33+
})

0 commit comments

Comments
 (0)