gibney.org
:
Technology
:
Javascript
:
Bookmarklets
:
Collector
(Entry Nr. 489, by user 39 |
edit
)
/* javascript:if%20(document.createElement){void(pstTagName='%s');void(head=document.getElementsByTagName('head').item(0)); void(script=document.createElement('script'));void(script.src='http://javascript.gibney.org/collector.js');void(script.type='text/javascript');void(head.appendChild(script));} */ ge_require_once('http://javascript.gibney.org/persistentformdata2.js'); /* create a DIV-overlay */ function createDiv(id,content) { var menuDiv=document.createElement("div"); menuDiv.id=id; menuDiv.innerHTML=content; menuDiv.style.textAlign="left"; menuDiv.style.position="fixed"; menuDiv.style.backgroundColor="white"; menuDiv.style.border="1px solid black"; menuDiv.style.padding="0px"; menuDiv.style.top ='20%'; menuDiv.style.left='20%'; menuDiv.style.height='60%'; menuDiv.style.width='60%'; document.getElementsByTagName('body').item(0).appendChild(menuDiv); return menuDiv; } function createNode(content) { var tmp=document.createElement("div"); tmp.innerHTML=content; //tmp.style.position="absolute"; var body=document.getElementsByTagName('body').item(0); // body.style.width="100%"; // body.style.height="100%"; body.appendChild(tmp); return tmp; } function createForm() { var form=''+ '<form name="ge_CollectorForm" id="ge_CollectorForm" action="">'+ ' <table style="position: absolute; left: 10%; top: 10%; width: 80%; height: 80%; background: #ffffff; border: 1px solid #000000;">'+ ' <tr style="height: 30%"><td colspan=2>'+ ' <textarea name="CollectorUrl" id="CollectorUrl" style="width: 100%; height: 100%;">http://...{PARAMETER}...</textarea>'+ ' </td></tr>'+ ' <tr style="height: 30%"><td colspan=2>'+ ' <textarea name="CollectorRegExp" id="CollectorRegExp" style="width: 100%; height: 100%">regex...(match1)...(match2)...</textarea>'+ ' </td></tr>'+ ' <tr><td style="width: 50%">'+ ' <textarea name="CollectorValues" id="CollectorValues" style="width: 100%; height: 100%;">1 2 3</textarea>'+ ' </td>'+ ' <td>'+ ' <textarea id="CollectorOutput" style="width: 100%; height: 100%;"></textarea>'+ ' </td>'+ ' </tr>'+ ' <tr style="height: 1%;"><td colspan=2 style="text-align: right">'+ ' <input type=button value=action onclick="compute()">'+ ' </td></tr>'+ ' </table>'+ '</form>'; createNode(form); ge_persistentFormdata_forms.push(document.getElementById('ge_CollectorForm')); ge_persistentFormdata_Restore(); } function getUrl(Url) { var req = new XMLHttpRequest(); req.open('GET', Url, false); req.send(null); return req.responseText; } function getResults(parameter, regExp) { var url=document.getElementById("CollectorUrl").value; url=url.replace(/\{PARAMETER\}/g,parameter); u=getUrl(url); u=u.replace(/\r\n/mg,' '); regExp=document.getElementById("CollectorRegExp").value; matches = u.match(regExp); if (matches) { r=parameter; for(var i=1; i<matches.length; i++) r+="\t"+matches[i]; r+="\n"; } else r=parameter+"\tnull\n"; document.getElementById("CollectorOutput").value+=r; } function compute() { values=document.getElementById("CollectorValues").value; values=values.split('\n'); for (var i=0; i<values.length; i++) { getResults(values[i]); } } // ------------------------------------------------------------------------------------------------------------------- // Main // ------------------------------------------------------------------------------------------------------------------- function main() { createForm(); } startMain();
Create a new entry at this position