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);
});

View File

@@ -46,6 +46,7 @@ in
ublacklist
vimium
wappalyzer # TODO: only for work profile
pkgs.nmasur.firefox-history-exporter
# saml-tracer
# text-fragment
];
@@ -187,7 +188,7 @@ in
xsession.windowManager.i3.config.keybindings = lib.mkIf pkgs.stdenv.isLinux {
"${config.xsession.windowManager.i3.config.modifier}+Shift+b" = "exec ${
# Don't name the script `firefox` or it will affect grep
builtins.toString (
toString (
pkgs.writeShellScript "focus-ff.sh" ''
count=$(ps aux | grep -c firefox)
if [ "$count" -eq 1 ]; then

View File

@@ -128,7 +128,7 @@ in
if pkgs.stdenv.isDarwin then
[
"env"
"PATH=${config.home.homeDirectory}/.nix-profile/bin:/usr/bin:/bin"
"PATH=/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/usr/bin:/bin"
(lib.getExe zellij-switch-to-last)
]
else

View File

@@ -9,13 +9,15 @@ let
inherit (config.nmasur.settings) username;
cfg = config.nmasur.presets.services.daily-summary;
process_urls = pkgs.writers.writePython3Bin "process-urls" {
libraries = [
pkgs.python3Packages.requests
pkgs.python3Packages.beautifulsoup4
];
} (builtins.readFile ./process-urls.py);
prompt = "Based on my browser usage for today from the markdown file located in /Users/${username}/Downloads/Sidebery/todays_urls.md, create or update a daily summary markdown file in the generated notes directory located in /Users/${username}/dev/personal/notes/generated/ with the filename format 'YYYY-MM-DD Daily Summary.md'. The resulting markdown file should use /Users/${username}/dev/personal/notes/templates/generated-summary.md as a format template, and it should summarize where I have spent my time today and highlight any notable links that I have visited. Please create markdown links to other relevant notes in /Users/${username}/dev/personal/notes/. If there is an existing markdown file for today, update it to include the newest information.";
# Remove process urls in favor of using extention
# process_urls = pkgs.writers.writePython3Bin "process-urls" {
# libraries = [
# pkgs.python3Packages.requests
# pkgs.python3Packages.beautifulsoup4
# ];
# } (builtins.readFile ./process-urls.py);
# prompt = "Based on my browser usage for today from the markdown file located in /Users/${username}/Downloads/Sidebery/todays_urls.md, create or update a daily summary markdown file in the generated notes directory located in /Users/${username}/dev/personal/notes/generated/ with the filename format 'YYYY-MM-DD Daily Summary.md'. The resulting markdown file should use /Users/${username}/dev/personal/notes/templates/generated-summary.md as a format template, and it should summarize where I have spent my time today and highlight any notable links that I have visited. Please create markdown links to other relevant notes in /Users/${username}/dev/personal/notes/. If there is an existing markdown file for today, update it to include the newest information.";
prompt = "Based on my browser usage for today from the JSON file located in /Users/${username}/Downloads/firefox-history/history-YYYY-MM-DD.json, create or update a daily summary markdown file in the generated notes directory located in /Users/${username}/dev/personal/notes/generated/ with the filename format 'YYYY-MM-DD Daily Summary.md'. The resulting markdown file should use /Users/${username}/dev/personal/notes/templates/generated-summary.md as a format template, and it should summarize where I have spent my time today and highlight any notable pages that I have visited, using the titles of each URL in the JSON file for markdown links. Please create markdown links to other relevant notes in /Users/${username}/dev/personal/notes/ and explain why they are being referenced. If there is an existing markdown file for today, update it to include the newest information.";
in
{
@@ -25,9 +27,12 @@ in
config = lib.mkIf cfg.enable {
launchd.user.agents.daily-summary = {
# This replaces program and args entirely
# script = ''
# ${process_urls}/bin/process-urls /Users/${username}/Downloads/Sidebery/
# GEMINI_API_KEY=$(cat /Users/${username}/.config/gemini/.gemini_api_key) ${pkgs.gemini-cli}/bin/gemini --allowed-tools all --yolo --include-directories /Users/${username}/Downloads/Sidebery/ --include-directories /Users/${username}/dev/personal/notes/ "${prompt}"
# '';
script = ''
${process_urls}/bin/process-urls /Users/${username}/Downloads/Sidebery/
GEMINI_API_KEY=$(cat /Users/${username}/.config/gemini/.gemini_api_key) ${pkgs.gemini-cli}/bin/gemini --allowed-tools all --yolo --include-directories /Users/${username}/Downloads/Sidebery/ --include-directories /Users/${username}/dev/personal/notes/ "${prompt}"
GEMINI_API_KEY=$(cat /Users/${username}/.config/gemini/.gemini_api_key) ${pkgs.gemini-cli}/bin/gemini --allowed-tools all --yolo --include-directories /Users/${username}/Downloads/firefox-history/ --include-directories /Users/${username}/dev/personal/notes/ "${prompt}"
'';
path = [

View File

@@ -1,3 +1,6 @@
# Temporarily disabled in favor of using an extension to save history
import requests
from bs4 import BeautifulSoup
import json