Update firerecord.js

added jsdoc tags
This commit is contained in:
David Westgate 2013-04-29 13:33:21 -03:00
parent 2f10bef2f3
commit 47aa3228c1

View File

@ -1,17 +1,20 @@
/*
@author Ian Hickey, Rylan Doherty, David Westgate, Peter Atashian
@fileOverview The event listener, event handler, script writer, and script executer functions of firerecord
*/
var recordingx = false; var recordingx = false;
var path = null; var path = null;
var loadx = null; var loadx = null;
var page = null; var page = null;
window.addEventListener("load", function load(event) { window.addEventListener("load", function load(event) {
window.removeEventListener("load", load, false); // remove listener, no window.removeEventListener("load", load, false); // remove listener, no
// longer needed // longer needed
firerecord.init(); firerecord.init();
}, false); }, false);
var firerecord = function () { var firerecord = function () {
var prefManager = Components.classes["@mozilla.org/preferences-service;1"] var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
.getService(Components.interfaces.nsIPrefBranch);
return { return {
init: function () { init: function () {
getBrowser().addEventListener("load", function () { getBrowser().addEventListener("load", function () {
@ -19,23 +22,19 @@ var firerecord = function() {
}); });
var appcontent = document.getElementById("appcontent"); // browser var appcontent = document.getElementById("appcontent"); // browser
if (appcontent) { if (appcontent) {
appcontent.addEventListener("DOMContentLoaded", firerecord.run, appcontent.addEventListener("DOMContentLoaded", firerecord.run, true);
true);
} }
}, },
/* @author rylan
// Rylan */
running: function () { running: function () {
if (recordingx) { if (recordingx) {
recordingx = false; recordingx = false;
alert("Stop Listen"); alert("Stop Listen");
openUILinkIn(window.content.location.href, "current"); openUILinkIn(window.content.location.href, "current");
// document.location.reload();
// closes all tabs on firefox.
} else { } else {
recordingx = true; recordingx = true;
alert("Start Listen"); alert("Start Listen");
// createFile("Initialize New Test File");
firerecord.run(); firerecord.run();
} }
}, },
@ -46,55 +45,65 @@ var firerecord = function() {
path = io.newPath(); path = io.newPath();
io.createFile(path); io.createFile(path);
}, },
// rylan
/* /*
* file: function(){ const nsIFilePicker = @author rylan
* Components.interfaces.nsIFilePicker;
*
* var fp = Components.classes["@mozilla.org/filepicker;1"]
* .createInstance(nsIFilePicker); fp.init(window, "Dialog Title",
* nsIFilePicker.modeOpen); fp.appendFilters(nsIFilePicker.filterAll |
* nsIFilePicker.filterText);
*
* var rv = fp.show(); if (rv == nsIFilePicker.returnOK || rv ==
* nsIFilePicker.returnReplace) { var file = fp.file; // Get the path as
* string. Note that you usually won't // need to work with the string
* paths. path = fp.file.path; // work with returned nsILocalFile...
* } },
*/ */
// rylan
checkpage: function (readloc) { checkpage: function (readloc) {
page = window.content.location.href; page = window.content.location.href;
if (page != readloc) { if (page != readloc) {
openUILinkIn(readloc, "current"); openUILinkIn(readloc, "current");
} }
}, },
/*
// rylan and David @author rylan, David
*/
playback: function () { playback: function () {
var playThis = io.getLine(path); var wait = true;
var playThis = io.getScript(path);
var line1 = new Array(); var line1 = new Array();
var line2 = new Array(); var line2 = new Array();
for(var i = 0; i < playThis.length; i+=2) for (var i = 0; i < playThis.length; i += 2) {
{
line1 = playThis[i]; line1 = playThis[i];
line2 = playThis[i + 1].split(' :: '); line2 = playThis[i + 1].split(' :: ');
while (true) {
//alert(line1.toString()); if (document.readyState == "complete") {
//alert(line2.toString());
setTimeout(function() {
firerecord.checkpage(line1); firerecord.checkpage(line1);
}, 5000); break;
setTimeout(function() { }
firerecord.fire(line2[0], line2[1], line2[2], line2[3], line2[4]);
}, 8000);
// setTimeout(function(){firerecord.fireExp();},8000);
} }
},
// rylan setTimeout(function () {
this.wait = false
}, 1000);
while (true) {
alert(wait);
if(wait == false)
break;
}
wait = true;
while (true) {
if (document.readyState == "complete") {
firerecord.fire(line2[0], line2[1], line2[2], line2[3], line2[4]);
break;
}
}
setTimeout(function () {
wait = false;
}, 1000);
while (true) {
if(wait == false)
break;
}
wait = true;
}
},
/*
@author rylan
*/
nullCheck: function (elem) { nullCheck: function (elem) {
if (!elem.href) { if (!elem.href) {
elem.href = "null"; elem.href = "null";
@ -141,50 +150,35 @@ var firerecord = function() {
if (!elem.caption) { if (!elem.caption) {
elem.caption = "null"; elem.caption = "null";
} }
return elem; return elem;
}, },
/* /*
* @author rylan
* //rylan fireExp: function(){ var all =
* content.document.getElementsByTagName("A"); for (var i = 0; i <
* all.length; ++i) { var elem = all[i]; if (i==62){ var obj =
* document.createEvent("MouseEvents"); obj.initEvent("click", true,
* true); elem.dispatchEvent(obj); } } },
*/ */
// rylan
fire: function (b, c, d, e, f) { fire: function (b, c, d, e, f) {
var all = content.document.getElementsByTagName(b); var all = content.document.getElementsByTagName(b);
for (var i = 0; i < all.length; ++i) { for (var i = 0; i < all.length; ++i) {
var elem = all[i]; var elem = all[i];
elem = firerecord.nullCheck(elem); elem = firerecord.nullCheck(elem);
switch (elem.tagName) { switch (elem.tagName) {
// All of these cases need null checks for each attribute. // All of these cases need null checks for each attribute.
case "A": case "A":
if (elem.href == c) { if (elem.href == c) {
var obj = document.createEvent("MouseEvents"); var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true); obj.initEvent("click", true, true);
elem.dispatchEvent(obj); elem.dispatchEvent(obj);
} }
break; break;
case "BUTTON": case "BUTTON":
if (elem.name == c && elem.type == d && elem.value == e if (elem.name == c && elem.type == d && elem.value == e && elem.form == f) {
&& elem.form == f) {
var obj = document.createEvent("MouseEvents"); var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true); obj.initEvent("click", true, true);
elem.dispatchEvent(obj); elem.dispatchEvent(obj);
} }
break; break;
case "FORM": case "FORM":
if (elem.name == c && elem.length == d && elem.target == e if (elem.name == c && elem.length == d && elem.target == e && elem.action == f) {
&& elem.action == f) {
var obj = document.createEvent("MouseEvents"); var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true); obj.initEvent("click", true, true);
elem.dispatchEvent(obj); elem.dispatchEvent(obj);
@ -239,23 +233,22 @@ var firerecord = function() {
elem.dispatchEvent(obj); elem.dispatchEvent(obj);
} }
break; break;
} }
} }
}, },
/*
@author David, Peter, rylan, Ian
@description Find all elements attributes and add a listener
*/
run: function () { run: function () {
var head = content.document.getElementsByTagName("head")[0],
var head = content.document.getElementsByTagName("head")[0], style = content.document style = content.document.getElementById("link-target-finder-style"),
.getElementById("link-target-finder-style"), all = content.document all = content.document.getElementsByTagName("*"),
.getElementsByTagName("*"), foundElements = 0; foundElements = 0;
var info = new Array(); // Made this global var info = new Array(); // Made this global
var Recording = true; // Just need this until we finish with the var Recording = true; // Just need this until we finish with the
// the buttons. // the buttons.
if (!style) { if (!style) {
style = content.document.createElement("link"); style = content.document.createElement("link");
style.id = "link-target-finder-style"; style.id = "link-target-finder-style";
@ -265,52 +258,36 @@ var firerecord = function() {
head.appendChild(style); head.appendChild(style);
} }
// Find all elements attributes and add a listener
//David, Peter
for (var i = 0; i < all.length; ++i) { for (var i = 0; i < all.length; ++i) {
// Define the classname variable // Define the classname variable
elm = all[i]; elm = all[i];
// deleted local call to new array info // deleted local call to new array info
var validtags = [ "A", "BUTTON", "FORM", "IMG", "INPUT", var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"];
"LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA" ];
// Add a click event listener to all the valid tags. // Add a click event listener to all the valid tags.
if (validtags.indexOf(all[i].tagName) < 0) if (validtags.indexOf(all[i].tagName) < 0) continue;
continue;
info[0] = all[i].tagName; info[0] = all[i].tagName;
// Feel free to change this to a for each... // Feel free to change this to a for each...
if (recordingx) { if (recordingx) {
switch (info[0]) { switch (info[0]) {
// All of these cases need null checks for each attribute. // All of these cases need null checks for each attribute.
case "INPUT": case "INPUT":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("keyup", handleType, false); elm.addEventListener("keyup", handleType, false);
break; break;
case "A": case "A":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "BUTTON": case "BUTTON":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "FORM": case "FORM":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "IMG": case "IMG":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
/* /*
@ -321,45 +298,35 @@ var firerecord = function() {
* elm.addEventListener("click", handleEvent, false); break; * elm.addEventListener("click", handleEvent, false); break;
*/ */
case "LINK": case "LINK":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "OPTION": case "OPTION":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "SELECT": case "SELECT":
elm.className += ((elm.className.length > 0) ? " " : "") elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "TABLE": case "TABLE":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.className += ((elm.className.length > 0) ? " " : "")
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
case "TEXTAREA": case "TEXTAREA":
elm.className += ((elm.className.length > 0) ? " " : "") elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
+ "link-target-finder-selected";
elm.addEventListener("click", handleEvent, false); elm.addEventListener("click", handleEvent, false);
break; break;
}
} }
} }
} }
// ----------------------------------------------------------------
}
}; };
/*
// rylan @author rylan
@description handles events
*/
function handleEvent(e) { function handleEvent(e) {
var targ; var targ;
if (!e) { if (!e) {
@ -371,7 +338,6 @@ var firerecord = function() {
targ = e.srcElement; targ = e.srcElement;
} }
var taginfo = new Array(); var taginfo = new Array();
taginfo[0] = targ.tagName; taginfo[0] = targ.tagName;
var countr; var countr;
// Feel free to change this to a for each... // Feel free to change this to a for each...
@ -379,26 +345,22 @@ var firerecord = function() {
// All of these cases need null checks for each attribute. // All of these cases need null checks for each attribute.
case "A": case "A":
taginfo[1] = targ.href; taginfo[1] = targ.href;
break; break;
case "BUTTON": case "BUTTON":
taginfo[1] = targ.name; taginfo[1] = targ.name;
taginfo[2] = targ.type; taginfo[2] = targ.type;
taginfo[3] = targ.value; taginfo[3] = targ.value;
taginfo[4] = targ.form; taginfo[4] = targ.form;
break; break;
case "FORM": case "FORM":
taginfo[1] = targ.name; taginfo[1] = targ.name;
taginfo[2] = targ.length; taginfo[2] = targ.length;
taginfo[3] = targ.target; taginfo[3] = targ.target;
taginfo[4] = targ.action; taginfo[4] = targ.action;
break; break;
case "IMG": case "IMG":
taginfo[1] = targ.name; taginfo[1] = targ.name;
taginfo[2] = targ.src; taginfo[2] = targ.src;
break; break;
/* /*
* case "INPUT": taginfo[1] = targ.name; taginfo[2] = targ.type; * case "INPUT": taginfo[1] = targ.name; taginfo[2] = targ.type;
@ -410,30 +372,25 @@ var firerecord = function() {
taginfo[1] = targ.href; taginfo[1] = targ.href;
taginfo[2] = targ.type; taginfo[2] = targ.type;
taginfo[3] = targ.charset; taginfo[3] = targ.charset;
break; break;
case "OPTION": case "OPTION":
taginfo[1] = targ.text; taginfo[1] = targ.text;
taginfo[2] = targ.value; taginfo[2] = targ.value;
taginfo[3] = targ.index; taginfo[3] = targ.index;
break; break;
case "SELECT": case "SELECT":
taginfo[1] = targ.type; taginfo[1] = targ.type;
taginfo[2] = targ.name; taginfo[2] = targ.name;
taginfo[3] = targ.size; taginfo[3] = targ.size;
break; break;
case "TABLE": case "TABLE":
taginfo[1] = targ.summary; taginfo[1] = targ.summary;
taginfo[2] = targ.caption; taginfo[2] = targ.caption;
break; break;
case "TEXTAREA": case "TEXTAREA":
taginfo[1] = targ.name; taginfo[1] = targ.name;
taginfo[2] = targ.type; taginfo[2] = targ.type;
taginfo[3] = targ.value; taginfo[3] = targ.value;
break; break;
} }
if (!taginfo[1]) { if (!taginfo[1]) {
@ -448,21 +405,16 @@ var firerecord = function() {
if (!taginfo[4]) { if (!taginfo[4]) {
taginfo[4] = "null"; taginfo[4] = "null";
} }
/*
* var positionFind = content.document.getElementsByTagName(taginfo[0]);
* for (var i = 0; i < positionFind.length; ++i) { if (targ =
* positionFind[i]){ taginfo[5] = i;
* } } alert(taginfo[5]);
*/
var contents = taginfo.join(' :: ') + "\n"; var contents = taginfo.join(' :: ') + "\n";
io.appendPath(path, window.content.location.href + "\n"); io.appendPath(path, window.content.location.href + "\n");
io.appendPath(path, contents); io.appendPath(path, contents);
e.cancelBubble = true; e.cancelBubble = true;
} };
;
}(); }();
/*
@author Ian
@description handles types
*/
function handleType(e) { function handleType(e) {
var targ; var targ;
if (!e) { if (!e) {