Event Fire

Functions to check page, handle events of all click types. Still need to
work on text input. Also trying to work capturing the location of the
target, incase there is no information included once its captured. This
will serve as a method of last resort.
This commit is contained in:
Rylan doherty 2013-04-27 18:32:39 -04:00
parent 5bb072a645
commit ab4876445f
2 changed files with 458 additions and 103 deletions

View File

@ -2,24 +2,19 @@
<?xml-stylesheet href="chrome://linktargetfinder/skin/skin.css" type="text/css"?> <?xml-stylesheet href="chrome://linktargetfinder/skin/skin.css" type="text/css"?>
<!DOCTYPE firerecord SYSTEM "chrome://firerecord/locale/translations.dtd"> <!DOCTYPE firerecord SYSTEM "chrome://firerecord/locale/translations.dtd">
<overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type='text/javascript' >
var path = "C:\\defaultRecord.txt";
var contents ="";
</script>
<script src="firerecord.js" /> <script src="firerecord.js" />
<script src="io.js" />
<menupopup id="menu_ToolsPopup"> <menupopup id="menu_ToolsPopup">
<menuitem label="&runlinktargetfinder;" key="link-target-finder-run-key" oncommand="firerecord.running()"/> <menuitem label="&runlinktargetfinder;" key="link-target-finder-run-key" oncommand="firerecord.running()"/>
</menupopup> </menupopup>
<toolbox> <toolbox>
<menubar id="xulschoolhello-menubar"> <menubar id="xulschoolhello-menubar">
<menu id="xulschoolhello-greeting-menu" label="File Options"> <menu id="xulschoolhello-greeting-menu" label="testing">
<menupopup> <menupopup>
<menuitem label="Load Script" <menuitem label="Choose Text File"
oncommand ="firerecord.file()"/> oncommand ="firerecord.file()"/>
<menuitem label="Create Script" <menuitem label="Run File"
oncommand ="firerecord.initfire()"/> oncommand ="firerecord.readr()"/>
</menupopup> </menupopup>
@ -32,17 +27,17 @@
</keyset> </keyset>
<toolbar id="status-bar"> <toolbar id="status-bar">
<statusbarpanel id="link-target-finder-status-bar-icon" label="Record" class="statusbarpanel-iconic" <statusbarpanel id="link-target-finder-status-bar-icon" label="Record" class="statusbarpanel-iconic" src="chrome://firerecord/skin/toolbar-large.png" tooltiptext="&runlinktargetfinder;" onclick="firerecord.running()" />
src="chrome://firerecord/skin/toolbar-large.png" tooltiptext="Click to start recording to currently loaded script"
onclick="firerecord.running()" />
</toolbar> </toolbar>
<toolbar id="status-bar"> <toolbar id="status-bar">
<statusbarpanel id="Play" type="menu" role="button" label="Play" class="statusbarpanel-iconic" <statusbarpanel id="Recording" type="menu" role="button" label="Record" class="statusbarpanel-iconic" src="chrome://firerecord/skin/toolbar-large.png" tooltiptext="Page to Page Recording" onclick="firerecord.running()" />
src="chrome://firerecord/skin/play.png" tooltiptext="Click to playback currently loaded script" onclick="firerecord.playback()" />
</toolbar> </toolbar>
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="link-target-finder-toolbar-button" label="firerecord:" class="statusbarpanel-iconic" src="chrome://firerecord/skin/toolbar-large.png" tooltiptext="&runlinktargetfinder;" oncommand="firerecord.running()"/>
</toolbarpalette>

View File

@ -1,16 +1,19 @@
var recordingx = false; var recordingx = false;
var path = null; var path = null;
var loadx = null;
var page = null;
window.addEventListener("load", function load(event) { window.addEventListener("load", function load(event) {
window.removeEventListener("load", load, false); //remove listener, no longer needed window.removeEventListener("load", load, false); //remove listener, no longer needed
firerecord.init(); firerecord.init();
}, false); }, false);
var firerecord = function () { 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 { return {
init: function () { init: function () {
getBrowser().addEventListener("load", function (){alert("loaded");});
var appcontent = document.getElementById("appcontent"); // browser var appcontent = document.getElementById("appcontent"); // browser
if (appcontent) { if (appcontent) {
appcontent.addEventListener("DOMContentLoaded", firerecord.run, true); appcontent.addEventListener("DOMContentLoaded", firerecord.run, true);
@ -20,7 +23,7 @@ var firerecord = function () {
if(recordingx){ if(recordingx){
recordingx = false; recordingx = false;
alert("Stop Listen"); alert("Stop Listen");
openUILinkIn(window.content.location.href,"current");
//document.location.reload(); //document.location.reload();
//closes all tabs on firefox. //closes all tabs on firefox.
} }
@ -50,7 +53,188 @@ var firerecord = function () {
} }
}, },
checkpage: function(readloc){
page = window.content.location.href;
if (page != readloc){
openUILinkIn(readloc,"current");
}
},
readr: function(){
var a= "http://rt.com/news/";
var b= "A";
var c= "http://rt.com/news/ukraine-tymoshenko-pardon-request-508/";
var d = "null";
var e = "null";
var f = "null";
setTimeout(function(){firerecord.checkpage(a);},5000);
setTimeout(function(){firerecord.fire(b,c,d,e,f);},8000);
//setTimeout(function(){firerecord.fireExp();},8000);
},
nullCheck: function(elem){
if(!elem.href){
elem.href = "null";
}
if(!elem.name){
elem.name = "null";
}
if(!elem.type){
elem.type= "null";
}
if(!elem.value){
elem.value= "null";
}
if(!elem.form){
elem.form= "null";
}
if(!elem.length){
elem.length= "null";
}
if(!elem.target){
elem.target = "null";
}
if(!elem.action){
elem.action= "null";
}
if(!elem.src){
elem.src= "null";
}
if(!elem.charset){
elem.charset= "null";
}
if(!elem.text){
elem.text= "null";
}
if(!elem.index){
elem.index= "null";
}
if(!elem.size){
elem.size= "null";
}
if(!elem.summary){
elem.summary= "null";
}
if(!elem.caption){
elem.caption= "null";
}
return elem;
},/*
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);
}
}
},*/
fire: function(b,c,d,e,f){
var all = content.document.getElementsByTagName(b);
for (var i = 0; i < all.length; ++i) {
var elem = all[i];
elem = firerecord.nullCheck(elem);
switch (elem.tagName) {
//All of these cases need null checks for each attribute.
case "A":
if (elem.href == c){
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "BUTTON":
if (elem.name == c && elem.type == d && elem.value == e && elem.form == f)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "FORM":
if (elem.name == c && elem.length == d && elem.target == e && elem.action == f)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "IMG":
if (elem.name == c && elem.src == d)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "INPUT":
if (elem.name == c && elem.type == d && elem.value == e)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "LINK":
if (elem.href == c && elem.type == d && elem.charset == e)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "OPTION":
if (elem.text == c && elem.value == d && elem.index == e)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "SELECT":
if (elem.type == c && elem.name == d && elem.size == e)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "TABLE":
if (elem.summary == c && elem.caption == d)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
case "TEXTAREA":
if (elem.name == c && elem.type == d && elem.value == e)
{
var obj = document.createEvent("MouseEvents");
obj.initEvent("click", true, true);
elem.dispatchEvent(obj);
}
break;
}
}
},
run : function () { run : function () {
var head = content.document.getElementsByTagName("head")[0], var head = content.document.getElementsByTagName("head")[0],
style = content.document.getElementById("link-target-finder-style"), style = content.document.getElementById("link-target-finder-style"),
all = content.document.getElementsByTagName("*"), all = content.document.getElementsByTagName("*"),
@ -71,16 +255,85 @@ var firerecord = function () {
// Find all elements attributes and add a listener // Find all elements attributes and add a listener
//----------------------------------------------------------- //-----------------------------------------------------------
// Add author(s) to this section. Who did this? David and Peter? // Add author(s) to this section. Who did this? David and Peter?
// Vastly simplified by Peter
if(recordingx){
for (var i = 0; i < all.length; ++i) { for (var i = 0; i < all.length; ++i) {
var elm = all[i]; //Define the classname variable
elm.addEventListener("click", handleEvent, false); elm = all[i];
//deleted local call to new array info
var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"];
//Add a click event listener to all the valid tags.
if (validtags.indexOf(all[i].tagName) < 0) continue;
info[0] = all[i].tagName;
//Feel free to change this to a for each...
if(recordingx){
switch (info[0]) {
//All of these cases need null checks for each attribute.
case "INPUT":
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected"; elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.addEventListener("click", 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":
info[1] = all[i].getAttribute("summmary");
info[2] = all[i].getAttribute("caption");
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;
} }
} }
}
//---------------------------------------------------------------- //----------------------------------------------------------------
} }
@ -99,9 +352,116 @@ var firerecord = function () {
else if (e.srcElement) { else if (e.srcElement) {
targ = e.srcElement; targ = e.srcElement;
} }
var contents = "script_click(script_find(" + targ.tagName + ", " + targ.getAttribute("id") + ", " + targ.getAttribute("name") + "));\n";
alert(contents); //---------------------------------------------------------------------
//_____________________________________________________________________
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 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";
appendFile(window.content.location.href+"\n");
appendFile(contents); appendFile(contents);
e.cancelBubble = true; e.cancelBubble = true;
}; };