开发者

How to "Decompile" a Bookmarklet?

开发者 https://www.devze.com 2023-02-05 21:08 出处:网络
We all know that bookmarklets are nothing but some executable javascript code that do some things for us

We all know that bookmarklets are nothing but some executable javascript code that do some things for us when we click on them depending on the function that they are intended to do... My Question is:

For example, I have a Bookmarklet, don't know, something like this one:

javascript:void(window.open('http://www.pdfdownload.org/web2pdf/Default.aspx?left=0&right=0&top=0&bottom=0&page=0&cURL='+document.location.href));

As far as I understand, the bookmarklet code (with the "&cURL=" thing) takes the URL that is in the adress bar of the browser and then do something with it in order to get a result. Something similar can be done with a selection, by changing some parameters in the bookmarklet (Like with the "Search selection in Google Maps" one) and some others.

How can I "decompile" a bookmarklet in order 开发者_运维知识库to make it take the desired data (in this case an URL) from a form?

For example, let's say I want to use the above bookmarklet in a webpage to provide a form that let's the user input a URL and then click a button to get the result.

I've seen other bookmarklets that get the URL from a "?input=" and others from a "?url="

How can I pass bookmarklet's functions to a form?


In a bookmarklet it's actually easiest to use prompt('Please enter a URL', 'default value') instead of the variable. Displaying a form in the current webpage is rather cumbersome.

If you just need one user-entered value, prompt() is an easy to use alternative to ask a user for more info. (Of course you can use multiple prompt() calls, too, but this will probably lead to a confused user)


Try something like this:

<form method="get" action="http://www.pdfdownload.org/web2pdf/Default.aspx">
<input type="hidden" name="left" value="0">
<input type="hidden" name="right" value="0">
<input type="hidden" name="top" value="0">
<input type="hidden" name="bottom" value="0">
<input type="hidden" name="page" value="0">
<input type="text" name="cURL">
<input type="submit">
</form>


Maybe you can call a javascript file in your bookmarklet :

javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('src','http://www.example.com/js.js');document.body.appendChild(e)})())

And you create an iframe on js.js

var site = location.href;
document.body.innerHTML += "<div style='background-color:white;z-index:1000;position:fixed;right:0;top:0' width='300' height='250'><iframe src='http://www.example.com/bookmarklet.php?q=" + site + "' /></div>";
0

精彩评论

暂无评论...
验证码 换一张
取 消