This commit is contained in:
Rylan Doherty 2013-04-23 12:49:42 -04:00
parent 0427e0bf8f
commit 729b7b552b
3 changed files with 226 additions and 171 deletions

View File

@ -1,43 +1,43 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<?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 src="firerecord.js" /> <script src="firerecord.js" />
<menupopup id="menu_ToolsPopup"> <menupopup id="menu_ToolsPopup">
<menuitem label="&runlinktargetfinder;" key="link-target-finder-run-key" oncommand="firerecord.run()"/> <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="testing"> <menu id="xulschoolhello-greeting-menu" label="testing">
<menupopup> <menupopup>
<menuitem label="Nothing Yet" <menuitem label="Choose Text File"
oncommand ="firerecord.file()"/> oncommand ="firerecord.file()"/>
</menupopup> </menupopup>
</menu>
</menubar>
</toolbox>
<keyset>
<key id="link-target-finder-run-key" modifiers="accel alt shift" key="L" oncommand="firerecord.run()"/>
</keyset>
<toolbar id="status-bar">
<statusbarpanel id="link-target-finder-status-bar-icon" label="Record" class="statusbarpanel-iconic" src="chrome://firerecord/skin/toolbar-large.png" tooltiptext="&runlinktargetfinder;" onclick="firerecord.run()" />
</toolbar>
<toolbar id="status-bar">
<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()" />
</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.run()"/>
</toolbarpalette>
<input type="file" id="upload" name="upload"/>
</menu>
</menubar>
</toolbox>
<keyset>
<key id="link-target-finder-run-key" modifiers="accel alt shift" key="L" oncommand="firerecord.running()"/>
</keyset>
<toolbar id="status-bar">
<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()" />
</toolbar>
<toolbar id="status-bar">
<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()" />
</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>
</overlay> </overlay>

View File

@ -1,10 +1,12 @@
var recordingx = false; var recordingx = false;
var path = 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 {
@ -14,25 +16,41 @@ var firerecord = function () {
appcontent.addEventListener("DOMContentLoaded", firerecord.run, true); appcontent.addEventListener("DOMContentLoaded", firerecord.run, true);
} }
}, },
running: function () { running: function (){
if (recordingx) { if(recordingx){
recordingx = false; recordingx = false;
alert("Stop Listen"); alert("Stop Listen");
//document.location.reload();
//closes all tabs on firefox. //document.location.reload();
} //closes all tabs on firefox.
else { }
recordingx = true; else{
alert("Start Listen"); recordingx = true;
firerecord.run(); alert("Start Listen");
} //createFile("Initialize New Test File");
firerecord.run();
}
},
file: function(){
const nsIFilePicker = Components.interfaces.nsIFilePicker;
}, var fp = Components.classes["@mozilla.org/filepicker;1"]
file: function () { .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) {
run: function () { 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...
}
},
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("*"),
@ -60,83 +78,83 @@ var firerecord = function () {
var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"]; var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "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) continue; if (validtags.indexOf(all[i].tagName) < 0) 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.addEventListener("click", handleType, false);
break;
case "A":
elm.addEventListener("click", handleEvent);
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;
elm.className += ((elm.className.length > 0) ? " " : "") + "link-target-finder-selected";
elm.addEventListener("click", handleType, false);
break;
case "A":
elm.addEventListener("click", handleEvent);
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;
}
} }
}
}
}
//---------------------------------------------------------------- //----------------------------------------------------------------
} }
}; };
//Need to add author to this part... //Need to add author to this part...
//Need to add author to this part... //Need to add author to this part...
function handleEvent(e) { function handleEvent(e) {
var targ; var targ;
if (!e) { if (!e) {
@ -150,98 +168,135 @@ var firerecord = function () {
} }
//--------------------------------------------------------------------- //---------------------------------------------------------------------
//_____________________________________________________________________ //_____________________________________________________________________
var tname; var tname;
var taginfo = new Array(); var taginfo = new Array();
tname = targ.tagName; tname = targ.tagName;
taginfo[0] = tname; taginfo[0] = tname;
//Feel free to change this to a for each... //Feel free to change this to a for each...
switch (tname) { switch (tname) {
//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": case "INPUT":
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;
case "LINK": case "LINK":
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.summmary; taginfo[1] = targ.summmary;
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;
} }
alert(window.content.location.href); alert(window.content.location.href);
if (!taginfo[1]) { if(!taginfo[1]){
taginfo[1] = "null"; //taginfo[1]= "null";
} }
if (!taginfo[2]) { if(!taginfo[2]){
taginfo[2] = "null"; //taginfo[2]= "null";
} }
if (!taginfo[3]) { if(!taginfo[3]){
taginfo[3] = "null"; //taginfo[3]= "null";
} }
if (!taginfo[4]) { if(!taginfo[4]){
taginfo[4] = "null"; //taginfo[4]= "null";
} }
alert("You clicked on a " + tname + " with info \n " + taginfo[1] + "\n" + taginfo[2] + "\n" + taginfo[3] + "\n" + " saving... " + taginfo.join('::')); var contents = "You clicked on a " + tname + " with info \n "+ taginfo.join(' :: ')+"\n";
appendFile(contents);
e.cancelBubble = true; e.cancelBubble = true;
}; };
}(); }();
function createFile(contents) {
alert("created File");
var file1 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file1.initWithPath("C:\\test\\" + "test.txt");
//alert("create file nullcheck" +file1.toString());
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
// use 0x02 | 0x10 to open file for appending.
foStream.init(file1, 0x02 | 0x08 | 0x20, 438, 0);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(contents.toString());
converter.close(); // this closes foStream
}
function appendFile(contents) {
alert("appended File");
var file1 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file1.initWithPath(path);
//alert("append file nullcheck: "+file1.toString());
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
// use 0x02 | 0x10 to open file for appending.
foStream.init(file1, 0x02 | 0x10, 438, 0);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(contents);
converter.close();
}
function handleType(e) { function handleType(e) {
var targ; var targ;
if (!e) { if (!e) {

View File

@ -1,31 +1,31 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<prefwindow <prefwindow
title="FireRecord Preferences" title="FireRecord Preferences"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane label="FireRecord Preferences"> <prefpane label="FireRecord Preferences">
<preferences> <preferences>
<preference id="link-target-finder-autorun" name="extensions.firerecord.autorun" type="bool"/> <preference id="link-target-finder-autorun" name="extensions.firerecord.autorun" type="bool"/>
</preferences> </preferences>
<groupbox> <groupbox>
<caption label="Settings"/> <caption label="Settings"/>
<grid> <grid>
<columns> <columns>
<column flex="4"/> <column flex="4"/>
<column flex="1"/> <column flex="1"/>
</columns> </columns>
<rows> <rows>
<row> <row>
<label control="autorun" value="Autorun"/> <label control="autorun" value="Autorun"/>
<checkbox id="autorun" preference="link-target-finder-autorun"/> <checkbox id="autorun" preference="link-target-finder-autorun"/>
</row> </row>
</rows> </rows>
</grid> </grid>
</groupbox> </groupbox>
</prefpane> </prefpane>
</prefwindow> </prefwindow>