Last active
May 9, 2022 10:25
-
-
Save fedeghe/c164161ae834cbbb043d5ce7b93f4a30 to your computer and use it in GitHub Desktop.
Generate a higher order bookmarklet which allows to generate any bookmarklet really quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("javascript:void "+encodeURIComponent(`function _(){var code=prompt('Paste here Your code'),bm="javascript:void(function(){"+encodeURIComponent(code+'')+"}())";if(code){if(bm.length>2e3){alert('The resulting code looks quite long to be printed in a prompt, the output will be written in the console, please copy it from there');console.log(bm)}else{prompt("Here's the bookmarklet code",bm)}}else{alert('No code given')}}()`)) | |
// which gives | |
/** | |
javascript:void function%20_()%7Bvar%20code%3Dprompt('Paste%20here%20Your%20code')%2Cbm%3D%22javascript%3Avoid(function()%7B%22%2BencodeURIComponent(code%2B'')%2B%22%7D())%22%3Bif%20(code)%7Bif%20(bm.length%20%3E%202e3)%20%7Balert('The%20resulting%20code%20looks%20quite%20long%20to%20be%20printed%20in%20a%20prompt%2C%20the%20output%20will%20be%20written%20in%20the%20console%2C%20please%20copy%20it%20from%20there')%3Bconsole.log(bm)%7Delse%7Bprompt(%22Here's%20the%20bookmarklet%20code%22%2Cbm)%7D%7Delse%7Balert('No%20code%20given')%7D%7D() | |
**/ | |
// save a bookmark named `hyperbookmarklet` (or whatever makes sense for You) and paste | |
// the above `javascript: ....` into the Url field. | |
// | |
// Whenever You want to create a bookmarklet which executes a specific code: | |
// - click the hyperbookmarklet | |
// - when prompted insert the code you want to be executed by the bookmarklet, hit 'OK' | |
// - for small bookmarklets (less than 2000 Bytes) the code will be shown through a prompt u can copy from | |
// - for bigger codes it will be written in the console, and a message will suggest you to copy it from there | |
// - now it's time to use it to create the specific bookmarklet | |
// | |
// ENJOY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment