mirror of
https://github.com/nmasur/dotfiles
synced 2026-02-08 23:09:46 +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);
|
||||
});
|
||||
Reference in New Issue
Block a user