mirror of
https://github.com/nmasur/dotfiles
synced 2026-03-22 20:59:45 +00:00
adjust daily summary to use browser extension for history
This commit is contained in:
41
pkgs/firefox-history-exporter/background.js
Normal file
41
pkgs/firefox-history-exporter/background.js
Normal 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
17
pkgs/firefox-history-exporter/manifest.json
Normal file
17
pkgs/firefox-history-exporter/manifest.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
32
pkgs/firefox-history-exporter/package.nix
Normal file
32
pkgs/firefox-history-exporter/package.nix
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
25
pkgs/firefox-history-exporter/popup.html
Normal file
25
pkgs/firefox-history-exporter/popup.html
Normal 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>
|
||||||
9
pkgs/firefox-history-exporter/popup.js
Normal file
9
pkgs/firefox-history-exporter/popup.js
Normal 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);
|
||||||
|
});
|
||||||
@@ -46,6 +46,7 @@ in
|
|||||||
ublacklist
|
ublacklist
|
||||||
vimium
|
vimium
|
||||||
wappalyzer # TODO: only for work profile
|
wappalyzer # TODO: only for work profile
|
||||||
|
pkgs.nmasur.firefox-history-exporter
|
||||||
# saml-tracer
|
# saml-tracer
|
||||||
# text-fragment
|
# text-fragment
|
||||||
];
|
];
|
||||||
@@ -187,7 +188,7 @@ in
|
|||||||
xsession.windowManager.i3.config.keybindings = lib.mkIf pkgs.stdenv.isLinux {
|
xsession.windowManager.i3.config.keybindings = lib.mkIf pkgs.stdenv.isLinux {
|
||||||
"${config.xsession.windowManager.i3.config.modifier}+Shift+b" = "exec ${
|
"${config.xsession.windowManager.i3.config.modifier}+Shift+b" = "exec ${
|
||||||
# Don't name the script `firefox` or it will affect grep
|
# Don't name the script `firefox` or it will affect grep
|
||||||
builtins.toString (
|
toString (
|
||||||
pkgs.writeShellScript "focus-ff.sh" ''
|
pkgs.writeShellScript "focus-ff.sh" ''
|
||||||
count=$(ps aux | grep -c firefox)
|
count=$(ps aux | grep -c firefox)
|
||||||
if [ "$count" -eq 1 ]; then
|
if [ "$count" -eq 1 ]; then
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ in
|
|||||||
if pkgs.stdenv.isDarwin then
|
if pkgs.stdenv.isDarwin then
|
||||||
[
|
[
|
||||||
"env"
|
"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)
|
(lib.getExe zellij-switch-to-last)
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ let
|
|||||||
inherit (config.nmasur.settings) username;
|
inherit (config.nmasur.settings) username;
|
||||||
cfg = config.nmasur.presets.services.daily-summary;
|
cfg = config.nmasur.presets.services.daily-summary;
|
||||||
|
|
||||||
process_urls = pkgs.writers.writePython3Bin "process-urls" {
|
# Remove process urls in favor of using extention
|
||||||
libraries = [
|
# process_urls = pkgs.writers.writePython3Bin "process-urls" {
|
||||||
pkgs.python3Packages.requests
|
# libraries = [
|
||||||
pkgs.python3Packages.beautifulsoup4
|
# 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.";
|
# } (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
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -25,9 +27,12 @@ in
|
|||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
launchd.user.agents.daily-summary = {
|
launchd.user.agents.daily-summary = {
|
||||||
# This replaces program and args entirely
|
# 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 = ''
|
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/firefox-history/ --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/Sidebery/ --include-directories /Users/${username}/dev/personal/notes/ "${prompt}"
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
path = [
|
path = [
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
# Temporarily disabled in favor of using an extension to save history
|
||||||
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import json
|
import json
|
||||||
|
|||||||
Reference in New Issue
Block a user