speedtag/chrome/content/speedtag.js

54 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

// vim: et:ts=2:sw=2:sts=2:ft=js
2011-05-24 20:04:48 +00:00
var startTime = new Date();
2011-05-23 20:35:35 +00:00
$(function() {
var savePath = '';
$('#saveLocationBtn').click(function() {
2011-05-24 20:04:48 +00:00
savePath = mozillaSelectFolder().file.path;
// alert(savePath.file.path);
2011-05-23 20:35:35 +00:00
});
$('#selectAudioFile').click(function() {
2011-05-24 20:04:48 +00:00
if (savePath === '') { alert("Please select a save location first."); return false; }
2011-05-23 20:35:35 +00:00
fil = selectFile();
2011-05-24 20:04:48 +00:00
// alert(savePath);
var destName = getDateString(startTime) + "." + getFileNameExt(fil.file.path);
2011-05-24 20:04:48 +00:00
mozillaCopyFile(fil.file.path, savePath, destName);
});
2011-05-24 20:04:48 +00:00
$('#saveFormData').click(function() {
if (savePath === '') { alert("Please select a save location first."); return false; }
var arr = $('#metadataForm').serializeObject();
var s = JSON.stringify(arr, null, 2);
2011-05-24 20:04:48 +00:00
// alert(s);
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
// alert(destFilePath);
mozillaSaveFile(destFilePath, s);
alert("saved " + destFilePath);
2011-05-23 20:35:35 +00:00
});
$('#loadData').click(function() {
var txtFile = selectFile().file.path;
var txt = mozillaLoadFile(txtFile);
var data = JSON.parse(txt);
loadFormData(data);
});
2011-05-23 20:35:35 +00:00
});
2011-05-24 20:04:48 +00:00
function getDateString(dateObj) {
return dateObj.toUTCString().replace(",", "").replace(":", ".");
}
function loadFormData(data) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
var value = data[key];
if (value === "on") {
$('#' + key).attr("checked", "checked");
} else {
$('#' + key).val(data[key]);
}
}
}
}