Removed the outdated test files.

Formatted all existing files.
Started a scriptapi.

Signed-off-by: retep998 <retep998@verizon.net>
This commit is contained in:
retep998 2013-04-02 11:38:38 -04:00
parent 44761bed69
commit 3ecea83687
7 changed files with 255 additions and 270 deletions

View File

@ -1,29 +1,41 @@
<html> <html>
<head name="headName" id="headId"> <head name="headName" id="headId">
<script type="text/javascript" src="analyze.js"></script> <script type="text/javascript" src="analyze.js"></script>
<script type="text/javascript" src="listener.js"></script> <script type="text/javascript" src="listener.js"></script>
</head> </head>
<body name="bodyName" id="bodyId"> <body name="bodyName" id="bodyId">
<title name="titleName" id="titleId">This is the title of the document</title><br /> <title name="titleName" id="titleId">This is the title of the document</title>
<header name="headerName" id="headerId">This is the header<br /> <br />
<nav name="navName" id="navId">This is the navigational menu</nav><br /> <header name="headerName" id="headerId">
This is the header<br />
<nav name="navName" id="navId">This is the navigational menu</nav>
<br />
</header> </header>
<table name="tableName" id="tableId"><br /> <table name="tableName" id="tableId">
<th name="tableHeadName" id="tableHeadId">table heading</th><br /> <br />
<td>Table Cell</td><br /> <th name="tableHeadName" id="tableHeadId">table heading</th>
<br />
<td>Table Cell</td>
<br />
</table> </table>
<h1 name="headingName" id="headingId">Level 1 Heading</h1><br /> <h1 name="headingName" id="headingId">Level 1 Heading</h1>
<br />
<a href="#" id="anchorId" name="anchorName">Anchor</a><br /> <a href="#" id="anchorId" name="anchorName">Anchor</a><br />
<object name="objectName" id="objectId">This is an object that normally holds a video but I'm too lazy to find one</object><br /> <object name="objectName" id="objectId">This is an object that normally holds a video but I'm too lazy to find one</object><br />
<menu name="menuName" id="menuId">This is a menu</menu><br /> <menu name="menuName" id="menuId">This is a menu</menu>
<br />
<img src="http://www.natural-environment.com/images/banners/banner_7_glasshouse_mountains.jpg" name="imageName" id="imageId"><br /> <img src="http://www.natural-environment.com/images/banners/banner_7_glasshouse_mountains.jpg" name="imageName" id="imageId"><br />
<p name="paraName" id="paraId">This is a paragraph</p><br /> <p name="paraName" id="paraId">This is a paragraph</p>
<br />
<q name="quoteName" id="quoteId">This is a quotation</q><br /> <q name="quoteName" id="quoteId">This is a quotation</q><br />
<summary name="summaryName" id="summaryId">This is a summary</summary><br /> <summary name="summaryName" id="summaryId">This is a summary</summary><br />
<time name="timeName" id="timeId">This is a timestamp</time><br /> <time name="timeName" id="timeId">This is a timestamp</time><br />
<button value="button" type="button" name="buttonName" id="buttonId" onClick="analyze()">Analyze Javascript</button> <br /> <button value="button" type="button" name="buttonName" id="buttonId" onclick="analyze()">Analyze Javascript</button>
<hr name="horizontalRuleName" id="horizontalRuleId"><br /> <br />
<form name="formName" id="formId"><br /> <hr name="horizontalRuleName" id="horizontalRuleId">
<br />
<form name="formName" id="formId">
<br />
<label name="labelName" id="labelId">This is a label</label><br /> <label name="labelName" id="labelId">This is a label</label><br />
<select> <select>
<option value="volvo" name="volvoName" id="volvoId">Volvo</option> <option value="volvo" name="volvoName" id="volvoId">Volvo</option>

View File

@ -5,7 +5,7 @@ function analyze() {
var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"]; var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"];
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;
switch(info[0]) { switch (info[0]) {
case "INPUT": case "INPUT":
info[1] = all[i].getAttribute("type"); info[1] = all[i].getAttribute("type");
break; break;
@ -65,56 +65,56 @@ function analyze() {
} }
function generatescript(info) { function generatescript(info) {
var command; var command;
switch(info[0]) { switch (info[0]) {
case "A": case "A":
command = "window.location.href = '" + info[1] + "';" command = "window.location.href = '" + info[1] + "';"
break; break;
case "BUTTON": case "BUTTON":
command = "button.name = '" + info[1] + "';" command = "button.name = '" + info[1] + "';"
+ "button.type = '" + info[2] + "';" + "button.type = '" + info[2] + "';"
+ "button.value = '" + info[3] + "';" + "button.value = '" + info[3] + "';"
+ "button.form = '" + info[4] + "';"; + "button.form = '" + info[4] + "';";
break; break;
case "FORM": case "FORM":
command = "form.name = '" + info[1] + "';" command = "form.name = '" + info[1] + "';"
+ "form.length = '" + info[2] + "';" + "form.length = '" + info[2] + "';"
+ "form.target = '" + info[3] + "';" + "form.target = '" + info[3] + "';"
+ "form.action = '" + info[4] + "';"; + "form.action = '" + info[4] + "';";
break; break;
case "IMG": case "IMG":
command = "img.name = '" + info[1] + "';" command = "img.name = '" + info[1] + "';"
+ "img.src = '" + info[2] + "';" + "img.src = '" + info[2] + "';"
+ "img.align = '" + info[3] + "';"; + "img.align = '" + info[3] + "';";
break; break;
case "INPUT": case "INPUT":
command = "input.name = '" + info[1] + "';" command = "input.name = '" + info[1] + "';"
+ "input.type = '" + info[2] + "';" + "input.type = '" + info[2] + "';"
+ "input.value = '" + info[3] + "';"; + "input.value = '" + info[3] + "';";
break; break;
case "LINK": case "LINK":
command = "link.href = '" + info[1] + "';" command = "link.href = '" + info[1] + "';"
+ "link.type = '" + info[2] + "';" + "link.type = '" + info[2] + "';"
+ "link.charset = '" + info[3] + "';"; + "link.charset = '" + info[3] + "';";
break; break;
case "OPTION": case "OPTION":
command = "option.text = '" + info[1] + "';" command = "option.text = '" + info[1] + "';"
+ "option.value = '" + info[2] + "';" + "option.value = '" + info[2] + "';"
+ "option.index = '" + info[3] + "';"; + "option.index = '" + info[3] + "';";
break; break;
case "SELECT": case "SELECT":
command = "select.type = '" + info[1] + "';" command = "select.type = '" + info[1] + "';"
+ "select.name = '" + info[2] + "';" + "select.name = '" + info[2] + "';"
+ "select.size = '" + info[3] + "';"; + "select.size = '" + info[3] + "';";
break; break;
case "TABLE": case "TABLE":
command = "table.summary = '" + info[1] + "';" command = "table.summary = '" + info[1] + "';"
+ "table.caption = '" + info[2] + "';"; + "table.caption = '" + info[2] + "';";
break; break;
case "TEXTAREA": case "TEXTAREA":
command = "window.location.name = '" + info[1] + "';" command = "window.location.name = '" + info[1] + "';"
+ "table.type = '" + info[2] + "';" + "table.type = '" + info[2] + "';"
+ "table.value = '" + info[3] + "';"; + "table.value = '" + info[3] + "';";
break; break;
} }
alert(command); alert(command);
} }

View File

@ -2,60 +2,67 @@
<head name="headName" id="headId"> <head name="headName" id="headId">
</head> </head>
<script> <script>
var spans = document.getElementsByTagName("*"); var spans = document.getElementsByTagName("*");
if (window.attachEvent) {window.attachEvent('onload', your_function);} if (window.attachEvent) { window.attachEvent('onload', your_function); }
else if (window.addEventListener) {window.addEventListener('load', your_function, false);} else if (window.addEventListener) { window.addEventListener('load', your_function, false); }
else {document.addEventListener('load', your_function, false);} else { document.addEventListener('load', your_function, false); }
for(i=0;i<spans.length;i++) for (i = 0; i < spans.length; i++)
spans[i].addEventListener("click", this.doSomething); spans[i].addEventListener("click", this.doSomething);
function your_function() function your_function() {
{ alert("Done Loading!");
alert("Done Loading!");
}
function doSomething(e)
{
var targ;
if (!e)
{
var e=window.event;
} }
if (e.target) function doSomething(e) {
{ var targ;
targ=e.target; if (!e) {
var e = window.event;
} }
else if (e.srcElement) if (e.target) {
{ targ = e.target;
targ=e.srcElement;
} }
var tname; else if (e.srcElement) {
var idname; targ = e.srcElement;
}
var tname;
var idname;
idname = targ.id; idname = targ.id;
tname = targ.tagName; tname = targ.tagName;
alert("You clicked on a " + tname + " element. Named "+ idname +"."); alert("You clicked on a " + tname + " element. Named " + idname + ".");
} }
</script> </script>
<body name="bodyName" id="bodyId"> <body name="bodyName" id="bodyId">
<title name="titleName" id="titleId">This is the title of the document</title><br /> <title name="titleName" id="titleId">This is the title of the document</title>
<header name="headerName" id="headerId">This is the header<br /> <br />
<nav name="navName" id="navId">This is the navigational menu</nav><br /> <header name="headerName" id="headerId">
This is the header<br />
<nav name="navName" id="navId">This is the navigational menu</nav>
<br />
</header> </header>
<table name="tableName" id="tableId"><br /> <table name="tableName" id="tableId">
<th name="tableHeadName" id="tableHeadId">table heading</th><br /> <br />
<td>Table Cell</td><br /> <th name="tableHeadName" id="tableHeadId">table heading</th>
<br />
<td>Table Cell</td>
<br />
</table> </table>
<h1 name="headingName" id="headingId">Level 1 Heading</h1><br /> <h1 name="headingName" id="headingId">Level 1 Heading</h1>
<br />
<a href="#" id="anchorId" name="anchorName">Anchor</a><br /> <a href="#" id="anchorId" name="anchorName">Anchor</a><br />
<object name="objectName" id="objectId">This is an object that normally holds a video but I'm too lazy to find one</object><br /> <object name="objectName" id="objectId">This is an object that normally holds a video but I'm too lazy to find one</object><br />
<menu name="menuName" id="menuId">This is a menu</menu><br /> <menu name="menuName" id="menuId">This is a menu</menu>
<br />
<img src="http://www.natural-environment.com/images/banners/banner_7_glasshouse_mountains.jpg" name="imageName" id="imageId"><br /> <img src="http://www.natural-environment.com/images/banners/banner_7_glasshouse_mountains.jpg" name="imageName" id="imageId"><br />
<p name="paraName" id="paraId">This is a paragraph</p><br /> <p name="paraName" id="paraId">This is a paragraph</p>
<br />
<q name="quoteName" id="quoteId">This is a quotation</q><br /> <q name="quoteName" id="quoteId">This is a quotation</q><br />
<summary name="summaryName" id="summaryId">This is a summary</summary><br /> <summary name="summaryName" id="summaryId">This is a summary</summary><br />
<time name="timeName" id="timeId">This is a timestamp</time><br /> <time name="timeName" id="timeId">This is a timestamp</time><br />
<button value="button" type="button" name="buttonName" id="buttonId">Click Me!</button> <br /> <button value="button" type="button" name="buttonName" id="buttonId">Click Me!</button>
<hr name="horizontalRuleName" id="horizontalRuleId"><br /> <br />
<form name="formName" id="formId"><br /> <hr name="horizontalRuleName" id="horizontalRuleId">
<br />
<form name="formName" id="formId">
<br />
<label name="labelName" id="labelId">This is a label</label><br /> <label name="labelName" id="labelId">This is a label</label><br />
<select> <select>
<option value="volvo" name="volvoName" id="volvoId">Volvo</option> <option value="volvo" name="volvoName" id="volvoId">Volvo</option>

View File

@ -1,32 +1,27 @@
var spans = document.getElementsByTagName("*"); var spans = document.getElementsByTagName("*");
if (window.attachEvent) {window.attachEvent('onload', your_function);} if (window.attachEvent) { window.attachEvent('onload', your_function); }
else if (window.addEventListener) {window.addEventListener('load', your_function, false);} else if (window.addEventListener) { window.addEventListener('load', your_function, false); }
else {document.addEventListener('load', your_function, false);} else { document.addEventListener('load', your_function, false); }
for(i=0;i<spans.length;i++) for (i = 0; i < spans.length; i++)
spans[i].addEventListener("click", this.doSomething); spans[i].addEventListener("click", this.doSomething);
function your_function() function your_function() {
{ alert("Done Loading!");
alert("Done Loading!");
} }
function doSomething(e) function doSomething(e) {
{ var targ;
var targ; if (!e) {
if (!e) var e = window.event;
{
var e=window.event;
} }
if (e.target) if (e.target) {
{ targ = e.target;
targ=e.target;
} }
else if (e.srcElement) else if (e.srcElement) {
{ targ = e.srcElement;
targ=e.srcElement;
} }
var tname; var tname;
var idname; var idname;
idname = targ.id; idname = targ.id;
tname = targ.tagName; tname = targ.tagName;
alert("You clicked on a " + tname + " element. Named "+ idname +"."); alert("You clicked on a " + tname + " element. Named " + idname + ".");
} }

3
scriptapi.js Normal file
View File

@ -0,0 +1,3 @@
function script_click_a(url) {
window.location.href = url;
}

View File

@ -1,15 +0,0 @@
<!doctype html>
<html>
<head>
<title>What is this I don't even.</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<h1 id="poke">Sup?</h1>
<a href="javascript:analyze();">Click me to analyze the page.</a>
<form class="blah">
<input id="foo" name="lel" type="text" />
<input id="bar" type="submit" />
</form>
</body>
</html>

View File

@ -1,17 +0,0 @@
function analyze() {
var all = document.getElementsByTagName("*");
for (var i = 0; i < all.length; ++i) {
var info = new Array();
var validtags = ["A", "BUTTON", "FORM", "IMG", "INPUT", "LINK", "OPTION", "SELECT", "TABLE", "TEXTAREA"];
if (validtags.indexOf(all[i].tagName) < 0) continue;
info[0] = all[i].tagName;
info[1] = all[i].getAttribute("id");
info[2] = all[i].getAttribute("name");
info[3] = all[i].getAttribute("class");
info[4] = all[i].getAttribute("type");
dostuff(info);
}
}
function dostuff(info) {
alert(JSON.stringify(info));
}