~callum/beavers-dam

856864e598b644d9fb3e95dd82b765b836a14679 — Callum Brown 1 year, 2 months ago 0f301f0
use const instead of let where relevant
2 files changed, 9 insertions(+), 10 deletions(-)

M content/content.js
M popup/popup.js
M content/content.js => content/content.js +7 -7
@@ 3,7 3,7 @@ const save = (text) => {
		{ entries: [] }
	).then((items) => {
		// Can't store a Map, use an Object instead
		let entry = {
		const entry = {
			"date": Date(),
			"hostname": location.hostname,
			"text": text,


@@ 20,7 20,7 @@ const undam = (hostname) => {
	chrome.storage.sync.get(
			{ dammed: [] },
	).then((items) => {
		let index = items.dammed.indexOf(hostname);
		const index = items.dammed.indexOf(hostname);
		if (index !== -1) {
			items.dammed.splice(index, 1);
			chrome.storage.sync.set(


@@ 32,16 32,16 @@ const undam = (hostname) => {


const buildDam = () => {
	let dam = document.createElement("div");
	const dam = document.createElement("div");
	dam.id = "beavers-dam";
	document.body.append(dam);

	let textarea = document.createElement("textarea");
	const textarea = document.createElement("textarea");
	dam.append(textarea);

	dam.append(document.createElement("br"));

	let saveAndViewJournal = document.createElement("button");
	const saveAndViewJournal = document.createElement("button");
	saveAndViewJournal.textContent = "Save & View Journal";
	saveAndViewJournal.addEventListener("click", () => {
		if (textarea.value.length > 0) {


@@ 51,13 51,13 @@ const buildDam = () => {
	});
	dam.append(saveAndViewJournal)

	let saveAndContinue = document.createElement("button");
	const saveAndContinue = document.createElement("button");
	saveAndContinue.textContent = `Save & Continue to ${location.hostname}`;
	saveAndContinue.addEventListener("click", () => {
		chrome.storage.sync.get(
			{ minWords: 0 }
		).then((items) => {
			let numWords = textarea.value.trim().split(" ").length;
			const numWords = textarea.value.trim().split(" ").length;
			if (numWords >= items.minWords) {
				save(textarea.value);
				dam.remove();

M popup/popup.js => popup/popup.js +2 -3
@@ 17,9 17,8 @@ document.getElementById("clear").addEventListener(
);

chrome.tabs.query({ active: true}).then(([tab]) => {
	let currentURL = new URL(tab.url);
	let hostname = currentURL.hostname;
	let toggleDammedButton= document.getElementById("toggle-dammed");
	const hostname = new URL(tab.url).hostname;
	const toggleDammedButton= document.getElementById("toggle-dammed");
	chrome.storage.sync.get(
		{ dammed: [] },
	).then((items) => {