Wednesday, February 20, 2013

Editing / Creating Bookmarklets



Bookmarklets are really cool.

I've updated the Bookmarklet Editor; drag this link to your bookmark toolbar:


So, what does it do?

Well, editing bookmarklets can be difficult, so the editor helps you to make edits and test them.

When you click the Bedit bookmark a new window should popup that looks something like this:


Click "Populate" to generate sample bookmarklet code.  Then, in your browser, create a new bookmark, and paste the code from Bedit into the URL.  The sample bookmarklet simply sends you to a page, depending upon which day of the month it is.

Some bookmarklets are WAY more complicated.  For example, check out www.supergenpass.com.  If you copy the "URL" bookmarklet code and paste it into Bedit, you can parse the code into (slightly) more readable javascript, make some changes, then run it from within Bedit!

Right click the bookmarklet (this one is from www.supergenpass.com):
Copy the entire entry in the URL field:

And paste it into the Bookmarklet Editor window: 

Click "Run" to test it: 

Editing it in its compressed form is difficult, so parse it first:

---

At the risk of confusion and paradox, the URL code for the bookmarklet editor is below; feel free to copy it and paste it into the Bedit window...

javascript:
W8=open('','B','width=400,height=350,resizable');
W8.focus();
with(W8.document){
write('
<html>
<body bgcolor=\'#CCCCCC\'>
<script>function setTemplate () {
var myX=this.document.getElementsByTagName("textarea");
/* var myText=document.body.outerHTML;
myText=myText + "boo";*/
var myText="javascript:(function(){
var today=new Date();
var dd=today.getDate();
window.location.assign(\'https://www.blueletterbible.org/Bible.cfm?b=Pro&c=\'+dd+\'&t=NIV\');

}
())";
myX[0].value=myText
}
function setX(){
var myX=this.document.getElementsByTagName("textarea");
myX[0].value=p4rse(myX[0].value)
}
function resetX(){
var myX=this.document.getElementsByTagName("textarea");
myX[0].value=colap5e(myX[0].value)
}
function colap5e(v){
v=v.split("\\t").join("");
v=v.split("\\n").join("");
v=v.split(" ").join(escape(" "));
v=v.split("\'").join(escape("\'"));
v=v.split(\'"\').join(escape(\'"\'));
v=v.split("\\r").join("");
return(v)
}
function tabMe(s){
var reg = /[\%7D\%7B]/;
var sa = s.split("\\n");
var isfor = /^for/;
for(var i in sa){
if(!reg.test(sa[i])&&i!=0&&!isfor.test(sa[i])){
sa[i]="\\t"+sa[i]  
}

}
sa[0] = sa[0].replace(/(javascript:)([\\S ]+)/,"$1\\n$2");
s=sa.join("\\n");
var r = s.replace(/for[\(]([\\S ]+%3B)[\\s]+([\\S ]+%3B)[\\s]+([\\S\)]+%7B)[\\s]+/g,"for($1$2$3\\n");
return(r)
}
function p4rse(v){
v=v.split("%3B*%2F").join("**%2F");
v=v.split("%3B").join("%3B\\n");
v=v.split("**%2F").join("%3B*%2F");
v=v.split("%7D").join("\\n%7D\\n");
v=v.split("%7B").join("%7B\\n");
/*  Parse Comments */
v=v.split("*%2F").join("*%2F\\n");
/*  Parse Tags */
v=v.split("%3C").join("\\n%3C");
v=tabMe(v);
v=v.split(escape(" ")).join(" ");
v=v.split(escape("\'")).join("\'");
v=v.split(escape(\'"\')).join(\'"\');
/* v=v.split("\\n\\n\\n").join("\\n");*/
return(v)
}

</script>
<center>
<form>
<textarea style=\'width:100%;
height:90%\' name=X rows=30 cols=34 wrap>javascript:
</textarea>
<p>
<input type=button value=Parse onclick=setX()> 
<input type=button value=Compress onclick=resetX()> 
<input type=button value=Run onclick=opener.location=X.value> 
<input type=button id=populate value=Populate onclick=this.disabled=true;
setTemplate()> <a style="font-size:.75em" target=_new href="http://goo.gl/3t2EjH">08.27.2014</a>
</form>
</center>
</body>
</html>');
setTimeout("W8.focus()",0);
void(close())
}