speedtag/chrome/content/speedtag.js

54 lines
1.5 KiB
JavaScript

// vim: et:ts=2:sw=2:sts=2:ft=js
var startTime = new Date();
$(function() {
var savePath = '';
$('#saveLocationBtn').click(function() {
savePath = mozillaSelectFolder().file.path;
// alert(savePath.file.path);
});
$('#selectAudioFile').click(function() {
if (savePath === '') { alert("Please select a save location first."); return false; }
fil = selectFile();
// alert(savePath);
var destName = getDateString(startTime) + "." + getFileNameExt(fil.file.path);
mozillaCopyFile(fil.file.path, savePath, destName);
});
$('#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);
// alert(s);
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
// alert(destFilePath);
mozillaSaveFile(destFilePath, s);
alert("saved " + destFilePath);
});
$('#loadData').click(function() {
var txtFile = selectFile().file.path;
var txt = mozillaLoadFile(txtFile);
var data = JSON.parse(txt);
loadFormData(data);
});
});
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]);
}
}
}
}