Skip to content

Commit

Permalink
Undo del, import/export/setting (#30)
Browse files Browse the repository at this point in the history
thanks to @badduck32
  • Loading branch information
badduck32 authored Sep 7, 2024
1 parent 658b67e commit d5c097b
Show file tree
Hide file tree
Showing 17 changed files with 1,794 additions and 696 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/tab-notes.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# Tab Notes
Open new tab and write anything.

## Features:

* **Easy-to-use**: Just open new tab, and write down thoughts.
* **Auto-save**: No worries about saving things when writing.
* **Theme**: Support light and dark theme.
* **Lightweight and fast**
* **Multi-notes**
* **Browser-action with shortcut**: You could use it without changing your current new tab page
* Open-source

## Shortcuts

- `Ctrl/Cmd + Y`: To open the browser-action tab notes.

## Download

Tab Notes is available to the following browsers:
* [Firefox](https://addons.mozilla.org/firefox/addon/tab-notes/)
* [Chrome](https://chrome.google.com/webstore/detail/tab-notes/obnnegakmgonaiplaobihpmcjhlceeic)

## Screenshot

![screenshot](./screenshot.png)
# Tab Notes
Open a new tab and write anything.

## Features:

* **Easy-to-use**: Just open new tab, and write down thoughts.
* **Auto-save**: No worries about saving things when writing.
* **Cloud sync**: Automatically save your notes across devices using GitHub gists.
* **Theme**: Support light and dark theme.
* **Lightweight and fast**
* **Multiple notes**: Create as many notes as you like.
* **Browser-action with shortcut**: You could use it without changing your current new tab page.
* **Customization**: Edit font, font size and more.
* **Images**: Paste images in your notes.
* **Styled text**: Make your text bold, italic or underlined.
* **Links**: Paste links to websites
* Open-source

## Shortcuts

- `Ctrl/Cmd + Y`: To open the browser-action tab notes.

## Download

*These downloads don't include any changes from this fork*
Tab Notes is available to the following browsers:
* [Firefox](https://addons.mozilla.org/firefox/addon/tab-notes/)
* [Chrome](https://chrome.google.com/webstore/detail/tab-notes/obnnegakmgonaiplaobihpmcjhlceeic)

## Screenshot

![screenshot](./screenshot.png)
Binary file added dnld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 18 additions & 18 deletions export.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Export Page | Tab Notes</title>
<script type="text/javascript" src="./browser-polyfill.min.js"></script>
<script type="text/javascript" src="./migration.js"></script>
<script type="text/javascript" src="./utils.js"></script>
<script type="text/javascript" src="./export.js"></script>
</head>
<body>
<h1>Tab Notes - Export Page</h1>
<textarea id='export-content' style='width: 50vw; height: 75vh;'>
</textarea>

<button id='switch-button' data-current-ask="json">I need json file.</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Export Page | Tab Notes</title>
<script type="text/javascript" src="./browser-polyfill.min.js"></script>
<script type="text/javascript" src="./migration.js"></script>
<script type="text/javascript" src="./utils.js"></script>
<script type="text/javascript" src="./export.js"></script>
</head>
<body>
<h1>Tab Notes - Export Page</h1>
<div>All notes are delimited with "&lt;&lt;&gt;&gt;"</div>
<textarea id='export-content' style='width: 50vw; height: 75vh;' readonly></textarea>
<button id='copy-button' data-current-ask="json">Copy to clipboard</button>
<button id='save-button' data-current-ask="json">Save to file</button>
</body>
</html>
95 changes: 54 additions & 41 deletions export.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
;(() => {
const exportJs = () => {
const init = async () => {
const $textarea = document.querySelector('#export-content')
const $switchBtn = document.querySelector('#switch-button')
const data = await window.utils.loadPreference()

const notes = data.list
.map(note => note.content)
.filter(c => c)
.join('\n\n--------------------\n\n')

$textarea.value = notes

$switchBtn.addEventListener('click', () => {
const { currentAsk } = $switchBtn.dataset

if (currentAsk === 'json') {
$textarea.value = JSON.stringify(data, null, ' ')
$switchBtn.dataset.currentAsk = 'text'
$switchBtn.textContent = 'I need pure text.'
}

if (currentAsk === 'text') {
$textarea.value = notes
$switchBtn.dataset.currentAsk = 'json'
$switchBtn.textContent = 'I need json file.'
}
})
}

return {
init
}
}

window.addEventListener('load', () => {
exportJs().init()
})
})()

;(() => {
const exportJs = () => {
const init = async () => {
const $textarea = document.querySelector('#export-content')
const $copyBtn = document.querySelector('#copy-button')
const $saveBtn = document.querySelector('#save-button')
const data = await window.utils.loadPreference()

const notes = data.list
.map(note => `${note.content}\n\n<<${note.time}>>\n\n`)
.filter(c => c)
.join('')

$textarea.value = notes

$copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText($textarea.value);
console.log('Notes copied to clipboard');
} catch (err) {
alert('Failed to copy: ', err);
}
})

$saveBtn.addEventListener('click', async () => {
var userInput = $textarea.value;

var blob = new Blob([userInput], { type: "text/plain;charset=utf-8" });

let newLink = document.createElement("a");
newLink.download = "export.txt";

if (window.webkitURL != null) {
newLink.href = window.webkitURL.createObjectURL(blob);
} else {
newLink.href = window.URL.createObjectURL(blob);
newLink.style.display = "none";
document.body.appendChild(newLink);
}

newLink.click();
})
}

return {
init
}
}

window.addEventListener('load', () => {
exportJs().init()
})
})()

17 changes: 17 additions & 0 deletions import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Import Page | Tab Notes</title>
<script type="text/javascript" src="./browser-polyfill.min.js"></script>
<script type="text/javascript" src="./migration.js"></script>
<script type="text/javascript" src="./utils.js"></script>
<script type="text/javascript" src="./import.js"></script>
</head>
<body>
<h1>Tab Notes - Import Page</h1>
<div>Paste your exported notes here.</div>
<textarea id='import-content' style='width: 50vw; height: 75vh;'></textarea>
<button id='import-button' data-current-ask="json">Import</button>
</body>
</html>
34 changes: 34 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
;(() => {
const importJs = () => {
const init = async () => {
const $textarea = document.querySelector('#import-content')
const $importBtn = document.querySelector('#import-button')
const data = await window.utils.loadPreference()

$importBtn.addEventListener('click', () => {
if (confirm("Are you sure you want to import these notes? All of your current notes will be replaced. This action cannot be undone.")) {
console.log("replacing")
var tmp = $textarea.value
.split(/\n\n<<([0-9]+)>>\n\n/g)
.slice(0, -1)
var newnotes = []
for (var i = 0; i < tmp.length; i += 2) {
newnotes.push({content: tmp[i], time: parseInt(tmp[i+1])})
}

data.list = newnotes
browser.storage.local.set({ list: data.list })
}
})
}

return {
init
}
}

window.addEventListener('load', () => {
importJs().init()
})
})()

81 changes: 42 additions & 39 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
{
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "54.0a1"
}
},
"icons": {
"48": "icons/48.png",
"96": "icons/96.png",
"128": "icons/128.png",
"256": "icons/256.png"
},
"manifest_version": 2,
"name": "Tab Notes",
"version": "3.2.0",
"description": "Allow you to write anything in new tab",
"permissions": [
"storage", "unlimitedStorage"
],
"chrome_url_overrides": {
"newtab": "newtab.html"
},

"browser_action": {
"browser_style": true,
"default_icon": "icons/48.png",
"default_title": "Tab notes",
"default_popup": "newtab.html"
},

"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Y"
}
}
}
}
{
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "54.0a1"
}
},
"icons": {
"48": "icons/48.png",
"96": "icons/96.png",
"128": "icons/128.png",
"256": "icons/256.png"
},
"manifest_version": 2,
"name": "Tab Notes",
"version": "3.2.0",
"description": "Allow you to write anything in new tab",
"permissions": [
"storage", "unlimitedStorage"
],
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"web_accessible_resources": [
"https://esm.sh/@octokit/request.js/"
],

"browser_action": {
"browser_style": true,
"default_icon": "icons/48.png",
"default_title": "Tab notes",
"default_popup": "newtab.html"
},

"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Y"
}
}
}
}
Loading

0 comments on commit d5c097b

Please sign in to comment.