diff --git a/chrome/content/fireio.js b/chrome/content/fireio.js index 378e10a..45508a4 100644 --- a/chrome/content/fireio.js +++ b/chrome/content/fireio.js @@ -29,7 +29,7 @@ var io = { @see Mozilla Developer Network Example */ appendPath: function (path, contents) { - alert("appended File"); + var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(path); // alert("append file nullcheck: "+file1.toString()); @@ -67,7 +67,7 @@ var io = { @see Mozilla Developer Network Example */ createFile: function (path) { - alert("created File"); + var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(path); var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); diff --git a/chrome/content/firerecord.js b/chrome/content/firerecord.js index dad9469..24b2dca 100644 --- a/chrome/content/firerecord.js +++ b/chrome/content/firerecord.js @@ -1,430 +1,326 @@ /* -@author Ian Hickey, Rylan Doherty, David Westgate, Peter Atashian +@author Ian Hickey, Rylan Doherty, David Westgate, William Jellesma, Peter Atashian @fileOverview The event listener, event handler, script writer, and script executer functions of firerecord */ -var recordingx = false; +var recording2 = false; var path = null; -var loadx = null; var page = null; +var i = 0; +var line1 = new Array(); +var line2 = new Array(); +var playThis; window.addEventListener("load", function load(event) { - window.removeEventListener("load", load, false); // remove listener, no - // longer needed + window.removeEventListener("load", load, false); firerecord.init(); }, false); + var firerecord = function () { - var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + var prefManager = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); return { - init: function () { - getBrowser().addEventListener("load", function () { - alert("loaded"); - }); - var appcontent = document.getElementById("appcontent"); // browser - if (appcontent) { - appcontent.addEventListener("DOMContentLoaded", firerecord.run, true); - } - }, - /* @author rylan - */ - running: function () { - if (recordingx) { - recordingx = false; - alert("Stop Listen"); - openUILinkIn(window.content.location.href, "current"); - } else { - recordingx = true; - alert("Start Listen"); - firerecord.run(); - } - }, - openfile: function () { - path = io.openPath(); - }, - newfile: function () { - path = io.newPath(); - io.createFile(path); - }, + init : function() { + var appcontent = document.getElementById("appcontent"); // browser + if (appcontent) { + appcontent.addEventListener("DOMContentLoaded", firerecord.run, + true); + } + }, /* - @author rylan + @author Rylan */ - checkpage: function (readloc) { - page = window.content.location.href; - if (page != readloc) { - openUILinkIn(readloc, "current"); - } - }, + running : function() { + if (recording2) { + recording2 = false; + alert("Stop Listen"); + openUILinkIn(window.content.location.href, "current"); + } else { + recording2 = true; + alert("Start Listen"); + firerecord.run(); + } + }, + openfile : function() { + path = io.openPath(); + }, + newfile : function() { + path = io.newPath(); + io.createFile(path); + }, + /* - @author rylan, David + @author Rylan */ - playback: function () { - var wait = true; - var playThis = io.getScript(path); - var line1 = new Array(); - var line2 = new Array(); - for (var i = 0; i < playThis.length; i += 2) { - line1 = playThis[i]; - line2 = playThis[i + 1].split(' :: '); - while (true) { - if (document.readyState == "complete") { - firerecord.checkpage(line1); - break; - } - } - - setTimeout(function () { - this.wait = false - }, 1000); - while (true) { - alert(wait); - if(wait == false) - break; - - } + checkpage : function() { + page = window.content.location.href; + if (page != line1) + openUILinkIn(line1, "current"); - 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) + setTimeout(function(){ + firerecord.fire(); + },5000); + }, + + /* + @author Rylan, David + */ + playback : function() { + i = 0; + playThis = io.getScript(path); + line1 = playThis[0]; + line2 = playThis[0+1].split(' :: '); + firerecord.checkpage(); + }, + + /* + @author Rylan + */ + fire : function() { + if (line2[0]=="key"){ + var obj = document.createEvent("KeyboardEvent"); + obj.initKeyEvent('keydown', true, true, window, false, false, false, false, 8, 0); + document.dispatchEvent(obj); + } + else{ + var all = content.document.getElementsByTagName(line2[1]); + for ( var n = 0; n < all.length; n++) { + var elem = all[n]; + var searchCount = 0; + if(line2[0]=="click") + searchCount = 2; + else if(line2[0]=="type") + searchCount = 3; + var finding = false; + while(searchCount 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("keyup", handleType, false); - break; - case "A": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "BUTTON": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "FORM": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "IMG": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - /* - * case "INPUT": - * - * elm.className += ((elm.className.length > 0) ? " " : "") + - * "link-target-finder-selected"; - * elm.addEventListener("click", handleEvent, false); break; - */ - case "LINK": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "OPTION": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "SELECT": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "TABLE": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - case "TEXTAREA": - elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - break; - } - } - } - - } + run : function() { + + var head = content.document.getElementsByTagName("head")[0], style = content.document + .getElementById("link-target-finder-style"), all = content.document + .getElementsByTagName("*"), foundElements = 0; + var Recording = true; + var info = new Array(); + if (!style) { + style = content.document.createElement("link"); + style.id = "link-target-finder-style"; + style.type = "text/css"; + style.rel = "stylesheet"; + style.href = "chrome://firerecord/skin/skin.css"; + head.appendChild(style); + } + + if (recording2) { + window.content.addEventListener("keyup", handleKey, false); + for ( var i = 0; i < all.length; ++i) { + elm = all[i]; + var validtags = [ "A", "BUTTON", "FORM", "IMG", "INPUT", + "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA" ]; + info[0] = all[i].tagName; + if (validtags.indexOf(info[0]) == -1) + continue; + else{ + if ( (elm.type == "text"||elm.type =="password") && info[0] == "INPUT"){ + elm.className += ((elm.className.length > 0) ? " " : "") + + "link-target-finder-selected"; + elm.addEventListener("change", handleType, false); + } + else{ + elm.className += ((elm.className.length > 0) ? " " : "") + + "link-target-finder-selected"; + elm.addEventListener("click", handleEvent, false); + } + } + } + } + } }; + /* - @author rylan - @description handles events + @author Rylan + @description handles click events */ function handleEvent(e) { - var targ; - if (!e) { - var e = window.event; - } - if (e.target) { - targ = e.target; - } else if (e.srcElement) { - targ = e.srcElement; - } - var taginfo = new Array(); - taginfo[0] = targ.tagName; - var countr; - // Feel free to change this to a for each... - switch (taginfo[0]) { - // All of these cases need null checks for each attribute. - case "A": - taginfo[1] = targ.href; - break; - case "BUTTON": - taginfo[1] = targ.name; - taginfo[2] = targ.type; - taginfo[3] = targ.value; - taginfo[4] = targ.form; - break; - case "FORM": - taginfo[1] = targ.name; - taginfo[2] = targ.length; - taginfo[3] = targ.target; - taginfo[4] = targ.action; - break; - case "IMG": - taginfo[1] = targ.name; - taginfo[2] = targ.src; - break; - /* - * case "INPUT": taginfo[1] = targ.name; taginfo[2] = targ.type; - * taginfo[3] = targ.value; - * - * break; - */ - case "LINK": - taginfo[1] = targ.href; - taginfo[2] = targ.type; - taginfo[3] = targ.charset; - break; - case "OPTION": - taginfo[1] = targ.text; - taginfo[2] = targ.value; - taginfo[3] = targ.index; - break; - case "SELECT": - taginfo[1] = targ.type; - taginfo[2] = targ.name; - taginfo[3] = targ.size; - break; - case "TABLE": - taginfo[1] = targ.summary; - taginfo[2] = targ.caption; - break; - case "TEXTAREA": - taginfo[1] = targ.name; - taginfo[2] = targ.type; - taginfo[3] = targ.value; - break; - } - if (!taginfo[1]) { - taginfo[1] = "null"; - } - if (!taginfo[2]) { - taginfo[2] = "null"; - } - if (!taginfo[3]) { - taginfo[3] = "null"; - } - if (!taginfo[4]) { - taginfo[4] = "null"; - } - var contents = taginfo.join(' :: ') + "\n"; - io.appendPath(path, window.content.location.href + "\n"); - io.appendPath(path, contents); - e.cancelBubble = true; - }; -}(); + var targ; + if (!e) { + var e = window.event; + } + if (e.target) { + targ = e.target; + } else if (e.srcElement) { + targ = e.srcElement; + } + var eleArray= ["href","name","id","type","value","form","length", + "target","action","src","charset","text","index", + "caption","size","summary"]; + var validtags = [ "A", "BUTTON", "FORM", "IMG", "INPUT", + "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA" ]; + var toWrite = new Array(); + toWrite[0] = "click"; + toWrite[1] = targ.tagName; + var countWrite = 2; + var eleCount = 0; + var eleHolder; + if (validtags.indexOf(toWrite[1]) == -1) + { + + } + else{ + while(eleCount