adjust daily summary to use browser extension for history

This commit is contained in:
Noah Masur
2026-01-27 14:13:46 -05:00
parent 430b522c61
commit 49e35403b6
9 changed files with 144 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
function exportHistory() {
const now = new Date();
const startTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0); // Beginning of today
browser.history.search({
text: '',
startTime: startTime,
endTime: now,
maxResults: 10000
}).then(historyItems => {
const historyData = JSON.stringify(historyItems, null, 2);
const blob = new Blob([historyData], {type: 'application/json'});
const url = URL.createObjectURL(blob);
const date = now.toISOString().slice(0, 10); // YYYY-MM-DD
const filename = `firefox-history/history-${date}.json`;
browser.downloads.download({
url: url,
filename: filename,
conflictAction: 'overwrite',
saveAs: false
});
});
}
browser.alarms.create('daily-export', {
periodInMinutes: 60 // every 1 hour
});
browser.alarms.onAlarm.addListener(alarm => {
if (alarm.name === 'daily-export') {
exportHistory();
}
});
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.command === "exportHistory") {
exportHistory();
}
});

View File

@@ -0,0 +1,17 @@
{
"manifest_version": 3,
"name": "History Exporter",
"version": "1.0",
"description": "Automatically exports today's browsing history.",
"permissions": [
"history",
"downloads",
"alarms"
],
"background": {
"scripts": ["background.js"]
},
"action": {
"default_popup": "popup.html"
}
}

View File

@@ -0,0 +1,32 @@
{ pkgs, ... }:
pkgs.stdenv.mkDerivation {
pname = "firefox-history-exporter";
version = "1.0";
src = ./.;
nativeBuildInputs = [ pkgs.zip ];
# We are not building anything, just packaging.
dontBuild = true;
installPhase = ''
# The directory structure expected by Firefox and home-manager.
# The UUID is the official application ID for Firefox.
install_dir=$out/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
mkdir -p $install_dir
# The filename of the .xpi file serves as the extension's ID.
# An email-like format is a common convention.
extension_id="firefox-history-exporter@localhost.xpi"
# Go into the source directory and zip all files into the .xpi archive.
# This ensures the manifest.json is at the root of the archive.
(cd $src; zip $install_dir/$extension_id *)
'';
meta = with pkgs.lib; {
description = "Automatically exports today's browsing history.";
license = licenses.mit;
};
}

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>History Exporter</title>
<style>
body {
width: 200px;
text-align: center;
font-family: sans-serif;
}
button {
margin-top: 10px;
padding: 10px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>History Exporter</h1>
<button id="export-button">Export Now</button>
<p id="status"></p>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,9 @@
document.getElementById('export-button').addEventListener('click', () => {
browser.runtime.sendMessage({command: "exportHistory"});
const statusElement = document.getElementById('status');
statusElement.textContent = 'Exporting...';
setTimeout(() => {
statusElement.textContent = 'Export complete!';
}, 2000);
});