~callum/beavers-dam

bf8a902aa1f123d6d9be1fd92bef72a558d2fb5f — Callum Brown 1 year, 7 months ago eb3e03b v0.3.1
v0.3.1: configurable minimum word count

using options page
6 files changed, 58 insertions(+), 15 deletions(-)

M content/content.js
M manifest.json
A options/options.html
A options/options.js
M popup/popup.html
M popup/popup.js
M content/content.js => content/content.js +18 -14
@@ 1,5 1,3 @@
const MINWORDS = 3;

const save = (text) => {
	chrome.storage.local.get(
		{ entries: [] }


@@ 56,18 54,24 @@ const buildDam = () => {
	let saveAndContinue = document.createElement("button");
	saveAndContinue.textContent = `Save & Continue to ${location.hostname}`;
	saveAndContinue.addEventListener("click", () => {
		if (textarea.value.trim().split(" ").length >= MINWORDS) {
			save(textarea.value);
			dam.remove();
			// Check if this host has been set to be undammed in popup.js
			chrome.storage.local.get(["undam"]).then((items) => {
				if (items.undam === location.hostname) {
					undam(location.hostname);
				}
			}).then(() => chrome.storage.local.set({ undam: null }));
		} else {
			window.alert(`Please write at least ${MINWORDS} words.`);
		}
		chrome.storage.sync.get(
			{ minWords: 0 }
		).then((items) => {
			let numWords = textarea.value.trim().split(" ").length;
			if (numWords >= items.minWords) {
				save(textarea.value);
				dam.remove();
				// Check if this host should be undammed (see popup.js)
				chrome.storage.local.get(["undam"]).then((items) => {
					if (items.undam === location.hostname) {
						undam(location.hostname);
						chrome.storage.local.set({ undam: null });
					}
				});
			} else {
				window.alert(`Please write at least ${items.minWords} words.`);
			}
		});
	});
	dam.append(saveAndContinue)
};

M manifest.json => manifest.json +2 -1
@@ 2,11 2,12 @@
	"manifest_version": 3,
	"name": "Beaver's Dam",
	"description": "Base Level Extension",
	"version": "0.3",
	"version": "0.3.1",
	"permissions": ["storage", "tabs"],
	"action": {
		"default_popup": "popup/popup.html"
	},
	"options_page": "options/options.html",
	"content_scripts": [
		{
			"js": ["content/content.js"],

A options/options.html => options/options.html +15 -0
@@ 0,0 1,15 @@
<!DOCTYPE html>
<html>
	<head>
		<title>Beaver's Dam Options</title>
		<script src="options.js" defer></script>
	</head>
	<body>
		<h1>Beaver's Dam Options</h1>
		<label for="min-words">Minimum word count</label>
		<br>
		<input type="number" id="min-words"></input>
		<br>
		<button id="save">Save</button>
	</body>
</html>

A options/options.js => options/options.js +16 -0
@@ 0,0 1,16 @@
let minWordsInput = document.getElementById("min-words");

// Load saved options
chrome.storage.sync.get(
	{ minWords: 0 }
).then((items) => {
	minWordsInput.value = items.minWords;
});


document.getElementById("save").addEventListener("click", () => {
	// TODO: type check before saving
	chrome.storage.sync.set(
		{ minWords: minWordsInput.value }
	);
});

M popup/popup.html => popup/popup.html +2 -0
@@ 7,6 7,8 @@
		<h1>Beaver's Dam</h1>
		<button id="open-journal">Open Journal</button>
		<br>
		<button id="open-options">Options</button>
		<br>
		<button id="toggle-dammed"></button>
		<br>
		<button id="clear">Clear storage</button>

M popup/popup.js => popup/popup.js +5 -0
@@ 3,6 3,11 @@ document.getElementById("open-journal").addEventListener(
	() => window.open(chrome.runtime.getURL("journal/journal.html")),
);

document.getElementById("open-options").addEventListener(
	"click",
	() => window.open(chrome.runtime.getURL("options/options.html")),
);

document.getElementById("clear").addEventListener(
	"click",
	() => {