Created
September 14, 2015 17:06
-
-
Save RPiAwesomeness/552145790e722b6719a4 to your computer and use it in GitHub Desktop.
Firefox history addon - stores date, page title, & page URL as you visit the page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Libraries and objects | |
// Run the logURL function when tab is "ready" | |
require("sdk/tabs").on("ready", logURL); | |
// Not exactly sure what this is/does, but it's there. | |
var {Cu} = require("chrome"); | |
// To read & write content to file | |
var {TextDecoder, TextEncoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {}); | |
// Get the full path of the user's home directory + the filename firefoxHistory | |
var path = OS.Path.join(OS.Constants.Path.homeDir, 'firefoxHistory'); | |
function logURL(tab) | |
{ | |
// Used for making date human-readable vs Epoch/Unix type | |
// Currently disabled because we're using Epoch/Unix type date | |
// const dateObj = new Date(); | |
// var curDate = dateObj.getMonth() + "/" + dateObj.getDay() + "/" + | |
// dateObj.getFullYear() + "_" + dateObj.getHours() + ":" + | |
// dateObj.getMinutes() + ":" + dateObj.getSeconds() + ":" + | |
// dateObj.getMilliseconds(); | |
// Lets us get the current UTC epoch/Unix-type date | |
var epochDate = new Date(); | |
// TextEncoder/TextDecoder objects | |
var encoder = new TextEncoder(); | |
// Get the current UTC date & convert it to seconds instead of milliseconds | |
epochDate = (epochDate.getTime() / 1000).toString(); | |
// Dividing by 1000 to convert seconds to milliseconds leaves a remainder, let's remove that | |
epochDate = epochDate.slice(0, epochDate.indexOf('.')); | |
// Prepare the text to be written | |
var toWrite = epochDate + "-\"" + tab.title + "\"-" + tab.url + "\n"; | |
var textEncoded = TextEncoder().encode(toWrite); | |
// This code takes care of appending the new data to the file instead of overwriting it | |
OS.File.open(path, {write: true, append: true}).then(valOpen => { | |
var textEncoded = TextEncoder().encode(toWrite); | |
valOpen.write(textEncoded).then(valWrite => { | |
valOpen.close() | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment