Timestampeder - Chrome Extension

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Timestampeder - Chrome Extension

Post by maboroshi »

A short while ago I wrote a chrome extension:
Timestampeder is a simple Chrome extension to prefix a timestamp to your file download names.
This Chrome extension was originally made for my personal use to back up files from my web2py web servers.
Filename format is using ISO 8601 format (2013-04-01T13:01:02) yielding 20130401T130102-Filename
https://chrome.google.com/webstore/deta ... fgbncgkfin

Here is the source code
bg.js

Code: Select all

function appendTimestamp() {	
	var now = new Date();
	
	year = now.getFullYear();
	month = now.getMonth() + 1;
	month = (month <10?'0':'') + month;
	day = (now.getDate() <10?'0':'') + now.getDate();
	hour = (now.getHours() <10?'0':'') + now.getHours();
	minutes = (now.getMinutes() <10?'0':'') + now.getMinutes();
	seconds = (now.getSeconds() <10?'0':'') + now.getSeconds();
  
	var myDate = year.toString() + month.toString() + day.toString();
	var myTime = hour.toString() + minutes.toString() + seconds.toString();
  
	var timestamp = myDate + "T" + myTime;
	return timestamp;
}

chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
	var newFilename = appendTimestamp() + "-" + item.filename;
	suggest({filename: newFilename});
});
manifest.json

Code: Select all

{
	"manifest_version": 2,
	"name": "Timestampeder",
	"description": "Prepends a timestamp to your file download names",
	"version": "0.7",
	"icons": { 
		"16": "icon16.png", 
		"48": "icon48.png",
        "128": "icon128.png" 
	},
	"background": {
		"scripts": ["bg.js"]
	},
	"permissions": ["downloads"],
	"content_security_policy": "script-src 'self' chrome-extension-resource: 'unsafe-eval'; default-src 'self'"
}
*cheers mabo

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Timestampeder - Chrome Extension

Post by ayu »

Nice man! : D
I have some stuff that I think I will share soon as well : D
"The best place to hide a tree, is in a forest"

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Re: Timestampeder - Chrome Extension

Post by maboroshi »

Awesome! I look forward to seeing the code you share.

*cheers :-)

Post Reply