chriszarate / bookmarkleter Goto Github PK
View Code? Open in Web Editor NEWYou have JavaScript. You need a bookmarklet. This does that.
Home Page: https://chriszarate.github.io/bookmarkleter/
You have JavaScript. You need a bookmarklet. This does that.
Home Page: https://chriszarate.github.io/bookmarkleter/
Add a command-line interface.
In IE11, CJK ideographs are not escaped to Unicode codepoints, which cause problems when clicking on bookmarklet.
I entered the following JavaScript snippet:
var sel = document.getSelection();
if (sel === null || sel === undefined)
sel = prompt('Suchbegriff:', '');
if (sel !== null && sel !== undefined && sel !== '')
location.href = 'https://de.wikipedia.org/w/index.php?search=' + encodeURIComponent(sel);
The "Minify code" option was unchecked. The generated bookmarklet was:
javascript:void%20function(){var%20a=document.getSelection();(null===a||a===void%200)%26%26(a=prompt(%22Suchbegriff:%22,%22%22)),null!==a%26%26a!==void%200%26%26%22%22!==a%26%26(location.href=%22https://de.wikipedia.org/w/index.php%3Fsearch=%22+encodeURIComponent(a))}();
This pretty much looks like the result of a minifier. The result does not change when I check and uncheck the Babel checkbox.
Looks like the function wrapper code simply needs a carriage return before appending this string: "}();"
For example if my code is this:
var x;
var foo = bar?.baz ?? x;
//
I get this red box error:
unknown: Unexpected token (3:6) 1 | void function () {var x; 2 | var foo = bar?.baz ?? x; > 3 | //}(); | ^
Up until now, personally as a workaround I would just always add "[new line]/**/" to the end of my input
[\n]/**/
But obviously this shouldn't be needed; seems a simple-to-fix issue,
as it appears to be happening due to how the "void function () {" ...
wrapper string closes.
I suspect all that is needed to fix is just appending "\n}();"
instead of "}();"
-- I will see if I can find the exact line myself and create a PR if possible.
index.html line 177
<label id="InputLabel" for="Input">JavaScript</label>
The label's for attribute doesn't match any element id.
With both of these checkboxes selected...
[x] Wrap in an IIFE (anonymizing function).
[x] Mangle variables to reduce code size. (formerly called "Minify code using Babel Minify."
...there seems to be a regressive bug introduced by today's update.
Test case:
var key = "href";
var foo = location[key];
var bar = foo + "#";
foo += "?";
console.log(bar);;;
Result from newly-updated version @ https://chriszarate.github.io/bookmarkleter/
javascript:void function () {var key="href",foo=location.href,bar=foo+"#";foo+="?",console.log(bar);}();
Compare to result from previous version e.g. https://alanhogan.github.io/bookmarkleter/
javascript:void function(){var a=location.href,b=a+"#";a+="?",console.log(b)}();
when using jQuery, the append into the header happens out of block scope, needs to be moved up one line:
!function($) {
var loadBookmarklet = function($) {
/* user script here */
};
if ($ && $.fn && parseFloat($.fn.jquery) >= 1.7)
loadBookmarklet($);
else {
var s = document.createElement("script");
s.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.js",
s.onload = s.onreadystatechange = function() {
var state = this.readyState;
state && "loaded" !== state && "complete" !== state || loadBookmarklet(jQuery.noConflict())
}
}
document.getElementsByTagName("head")[0].appendChild(s) /* needs to be moved up one line */
}(window.jQuery);
No issue here - just wanted to say thanks for building this!
I've recently found myself wanting to create more bookmarklets for various tasks, and this makes it a breeze.
To diagnose an issue with SGP, I used UglifyJS2 via UglifyJS-online (site here) to recompress a prettified version of SGP.
SuperGenPass's bookmarklet size on supergenpass.com: 4633 bytes.
bookmarkleter with UglifyJS: 3432 bytes.
UglifyJS2 compression: 2985 bytes.
https://github.com/JavaScript-Packer/24KB-Uglify.js is a link to my highly modded/fixed, minified and compressed version of Uglify that is only 24KB, maybe you can help me spread it's use... This could help you remake your marklet app in less than 30KB versus 475KB it is now.
It is the heart of www.scriptcompress.com and so far gets better results than most other minifiers. Use Google Closure compiler first and this fuglify will still make it smaller!
It's easy to use, max settings are set already and just one function to call:
var code = 'alert("Your Code");';
var minified = fugly(code);
Since uglify
depends on ES5 code, the web utility makes it impossible for me to create a bookmarklet from ES6 code.
@chriszarate I'm curious about how this would go about being patched. I have a couple ideas:
I'd be willing to implement this, but I wanted to get your feedback before I do any serious work.
Thanks so much for the updates! I confirmed things like foo?.bar or foo??bar now work.
Except it seems tonnow be broken; the DEFAULT minifying no longer happens (AKA if you uncheck all boxes, where you want to minify but not run Babel transform to convert to older code)
Originally posted by @DarrenSem in #27 (comment)
how do i make it a bookmarklet
If you run npm view bookmarkleter versions
the latest version available on npm
is still 1.1.0
Please publish 1.2.0
The anonymizing function doesn't play nice with internal Javascript functions like "prompt". After the code completes, the window is then evaluated/replaced to just show the string "true". Minimal test case:
val = prompt("What's your name?"); if (val) alert("Hello, "+val);
Which is being converted to the following code:
javascript:!function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)}();
In my browser (Firefox 53.0.3 64-Bit), the window's contents change to "true" after the code completes.
The code with the following anonymizing function works as intended:
javascript:(function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)})();
From my understanding, the highlighted issue is, that the output of the anonymizing function is being inverted and can evaluate to "true". Maybe an even better way would be to generally cast it to void:
javascript:void(function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)})();
To quote someone else's comment elsewhere in this repo, "It is Really The Best Bookmarklet Maker I found!"
So, pretty please -- similar to what you did in Issue #19 -- can this EXCELLENT tool be updated to allow for the latest additions to ES6? Things like...
etc.
Thanks in advance @chriszarate ! I am willing to "buy you a coffee" or equivalent, that's how much many of us appreciate this perfect-UI tool.
PS: Also perhaps let the repo have all of the source files used to build the end result too (if not typically included there already -- I'm relatively new to the whole Node package.json etc. rabbit hole so... ๐คทโโ๏ธ)
I assume that this is a Firefox-only problem, but I didn't actually test this in other browsers.
Currently the generated bookmarklet looks like this:
javascript:!function(){...}()
The result of this expression will be either false
or true
, depending on the return value of the function. Since the result isn't undefined
Firefox will replace the contents of the current page with the text false
or true
which isn't usually desired. A simple change to the generated bookmarklet fixes this:
javascript:void function(){...}()
There is the same issue if "Wrap in an IIFE" isn't checked - normally adding void 0
to the end of the bookmarklet would work but UglifyJS removes it.
With your https://chriszarate.github.io/bookmarkleter/, I always have to put Off all my ?.
in original codes before I find where to put them back in the result. Else, I'm getting anunknown: Support for the experimental syntax 'optionalChaining' isn't currently enabled
and No result because of this error.
I use your Bookmarkleter - a bit customized through Tampermonkey - to help me build our HTML page of Chrome bookmarklets. It is Really The Best Bookmarklet Maker I found!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.