~callum/beavers-dam

6ad667e8358a63e86c10c3c654b9fb86b79967ec — Callum Brown 1 year, 2 months ago dff0995 v0.2.1
v0.2.1: Reload page when dam toggled
3 files changed, 7 insertions(+), 10 deletions(-)

M manifest.json
M popup/popup.js
M todo
M manifest.json => manifest.json +1 -1
@@ 2,7 2,7 @@
	"manifest_version": 3,
	"name": "Beaver's Dam",
	"description": "Base Level Extension",
	"version": "0.2",
	"version": "0.2.1",
	"permissions": ["storage", "tabs"],
	"action": {
		"default_popup": "popup/popup.html"

M popup/popup.js => popup/popup.js +6 -7
@@ 6,24 6,20 @@ const openJournal = () => {
};


const toggleDammed = (hostname) => {
const toggleDammed = (hostname, tabId) => {
	chrome.storage.sync.get(
		{ dammed: [] },
	).then((items) => {
		let newText;
		let index = items.dammed.indexOf(hostname);
		if (index === -1) {
			items.dammed.push(hostname);
			newText = `Undam ${hostname}`;
		} else {
			items.dammed.splice(index, 1);
			newText = `Dam ${hostname}`;
		}
		chrome.storage.sync.set(
			{ dammed: items.dammed }
		).then(() => {
			// TODO: reload page instead of changing text
			document.getElementById("toggle-dammed").textContent = newText;
			chrome.tabs.reload(tabId).then(window.close);
		});
	});
};


@@ 43,7 39,10 @@ chrome.tabs.query({ active: true}).then(([tab]) => {
	let currentURL = new URL(tab.url);
	let host = currentURL.hostname;
	let toggleDammedButton= document.getElementById("toggle-dammed");
	toggleDammedButton.addEventListener("click", () => toggleDammed(host));
	toggleDammedButton.addEventListener(
		"click",
		() => toggleDammed(host, tab.id),
	);
	// Set correct initial button text
	chrome.storage.sync.get(
		{ dammed: [] },

M todo => todo +0 -2
@@ 1,5 1,3 @@
reload page instead of changing text when toggling damming in popup.js

programmatically modify matching pages in background.js?

Min word count