From 338bc3ed2901e066ea92a4edc1d75bb9f4cfff5a Mon Sep 17 00:00:00 2001 From: Rylan doherty Date: Tue, 7 May 2013 11:18:55 -0400 Subject: [PATCH] Update Several Files --- chrome/content/firerecord.js | 580 +++++++++++++++++++---------------- 1 file changed, 310 insertions(+), 270 deletions(-) diff --git a/chrome/content/firerecord.js b/chrome/content/firerecord.js index 24b2dca..f2f5c94 100644 --- a/chrome/content/firerecord.js +++ b/chrome/content/firerecord.js @@ -2,7 +2,6 @@ @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 recording2 = false; var path = null; @@ -11,316 +10,357 @@ var i = 0; var line1 = new Array(); var line2 = new Array(); var playThis; +var debugging = 0; //Turn on debugging by setting this to 1. +var lastPage = ""; +/* + * debug handles displaying popups for additional info + * needed for debugging purposes. + * @arg debug string to display to in debug mode. + */ +var debug = function (debugString) { + if (this.debugging == 1) { alert(debugString) } + else { return 1; } +}; +/* + * Handles calling the init function on each page load. + */ window.addEventListener("load", function load(event) { window.removeEventListener("load", load, false); firerecord.init(); }, false); +/* + * Init checks that the dom is loaded an ready before calling run() + */ var firerecord = function () { var prefManager = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); return { - init : function() { - var appcontent = document.getElementById("appcontent"); // browser - if (appcontent) { - appcontent.addEventListener("DOMContentLoaded", firerecord.run, + init: function () { + var appcontent = document.getElementById("appcontent"); // browser + if (appcontent) { + appcontent.addEventListener("DOMContentLoaded", firerecord.run, true); - } - }, + } + }, /* @author Rylan */ - 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); - }, - + running: function () { + if (recording2) { + recording2 = false; + alert("Recording Completed."); + openUILinkIn(window.content.location.href, "current"); + } else { + recording2 = true; + alert("Recording On."); + firerecord.run(); + } + }, + openfile: function () { + path = io.openPath(); + }, + newfile: function () { + path = io.newPath(); + io.createFile(path); + }, + /* @author Rylan */ - checkpage : function() { - page = window.content.location.href; - if (page != line1) - openUILinkIn(line1, "current"); - - setTimeout(function(){ - firerecord.fire(); - },5000); - }, - + checkpage: function () { + page = window.content.location.href; + if (page == lastPage) { + //do nothing + } + else if (page != line1) { + openUILinkIn(line1, "current"); + } + setTimeout(function () { + firerecord.fire(); + }, 3000);//Change timeout to 3 seconds. + }, + /* @author Rylan, David */ - playback : function() { - i = 0; - playThis = io.getScript(path); - line1 = playThis[0]; - line2 = playThis[0+1].split(' :: '); - firerecord.checkpage(); - }, - + playback: function () { + i = 0; + playThis = io.getScript(path); + line1 = playThis[0]; + debug("Line 1 == " + line1); + line2 = playThis[0 + 1].split(' :: '); + debug("Line 2 == " + line2); + //Keep a copy of the last address so we don't refresh the page in the middle of trying to login to a site etc. + lastPage = line1; + 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("change", handleType, false); - } - else{ - elm.className += ((elm.className.length > 0) ? " " : "") - + "link-target-finder-selected"; - elm.addEventListener("click", handleEvent, false); - } - } - } - } - } + 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", "SPAN", "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.type == "submit" || elm.type == "email") { + 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 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 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