I end up using bookmarklets a ton, as they just work most of the time without having to boot up any additional stuff or having to run web requests through a proxy.
My most used one is probably this, allowing me to download all files in a page. There’s also the “Submit to Lobsters” bookmarklet, which is awesome.
Any useful ones you’d like to share? Input is super appreciated.
I have a couple site-specific versions of a bookmarklet for toggling between a page on prod and dev:
javascript:(function(){var u=window.location.href;var n=u.startsWith('https://lobste.rs/')?'http://localhost:3000/':'https://lobste.rs/';window.location.href=n+u.split('/').slice(3).join('/')})();I’m stealing this. I’ve been lazily using https://github.com/guillaumebriday/switch-to-localhost for years, but it doesn’t switch back to prod.
I have meant to write this for years and just never gotten around to it. I just swap the URLs, think “I should make a bookmarklet” and then do whatever it is I was doing originally.
Bookmarklets I use:
Here’s the view source one: https://apple.stackexchange.com/a/417701
Ooh the Mastodon one is really nice, links to other instances has always added so much friction to using Mastodon for me
The one I use the most is probably opendir_image.js. It collects all links to image, audio and video files on the current page and displays the files in a nice grid view.
I use bookmarklets a ton every day. I also use a lot of browser extensions but for simpler things for myself, bookmarklets are an easier and faster way to achieve similar goals.
The ones I use the most are Copy as Markdown and Copy as HTML: both of them copy the current page’s title and URL in either markdown links or html anchor tags. I use them to grab interesting stuff into my notes or to my website and save a lot of formatting time when they come in a right format. If some text is selected on a page, the markdown version will add that as a blockquote on top of the link. I have shared them in my blog.
Then I have a few that modify websites by adding functionality, like one for the local hockey league that I also shared in aforementioned blog post.
I also like to automate things like filling forms while developing since that gets boring quite fast.
Both of those are super useful! Added to my list.
yawaramin shared some bookmarklets a few months ago. I have to use the anchors toggle way too often :-)
The one that I use the most is one that inserts a signed email address into the currently focused field. It can can use what is in the field already as the “name” or defaults to the domain.
I have it linked to the
ekeyword so I just do<C-l>e<Enter>to insert the email address.The other main one that I occasionally use injects the Google Translate script into the current page.
I use a similar email approach. Might have to adapt yours here!
The Google Translate script one sounds super useful! Do you have any links to that?
javascript:void(document.location='https://wave.webaim.org/report#/'+escape(document.location))javascript:void(document.location='https://validator.nu/?doc='+escape(document.location)+'&showoutline=yes')javascript:void(document.location='https://www.websitecarbon.com/website/'+escape(document.location.host))At work I use one for adding better video controls to HTML5 video (e.g. skip 10 msec backwards/forwards). It’s based on https://stackoverflow.com/a/66464235 .
Also occasionally using a self-built bookmarklet for adding a histogram and color controls to the images on a website. The controls are nice to quickly make an image brighter, to see if the dark pixels contain more details than visible to a human eye. This bookmarklet has become quite extensive though: I now have to start a local webserver from which most of the JS code is loaded. This approach also makes it easier to edit the code.
At least the second bookmarklet is quite intrusive though; so it does not work well on all pages.
My most used one is jump to Wikipedia. The next most used is a work specific one for going to the right page in the admin.
Could you elaborate on the jump to Wikipedia one?
You highlight some text and hit the bookmarklet and then it loads that page in Wikipedia.
Strip playlist params from YouTube so it doesn’t autoplay more:
javascript:( function(){ location.href='https://www.youtube.com/watch?%27+(new%20RegExp(%22v=[^&]*%22).exec(location.href))%20}%20)();New reddit to old reddit:
javascript:( function(){ location.href='https://old.'+(new RegExp("reddit.com/.*").exec(location.href)) } )();Open page in Internet Archive:
javascript:window.location = "https://web.archive.org/web/*/" + window.location;Save page in Internet Archive:
javascript:window.location = "https://web.archive.org/save/" + window.location;Decode base64 in place:
javascript:function c(){}c.prototype.get=function(){var a="";window.getSelection?a=window.getSelection().toString():document.selection&&%22Control%22!=document.selection.type&&(a=document.selection.createRange().text);return%20a};c.prototype.set=function(a){if(window.getSelection){var%20b=window.getSelection();b.rangeCount&&(b=b.getRangeAt(0),b.deleteContents(),b.insertNode(document.createTextNode(a)))}else%20document.selection&&document.selection.createRange&&(b=document.selection.createRange(),b.text=a)};try{var%20d=new%20c,e=atob(d.get());d.set(e)}catch(a){alert(a.message)};I have five that I currently use a lot:
remove position:fixed elements, for getting rid of in-your-face modals:
javascript:(function()%7B(function%20()%20%7Bvar%20i%2C%20elements%20%3D%20document.querySelectorAll('body%20*')%3Bfor%20(i%20%3D%200%3B%20i%20<%20elements.length%3B%20i%2B%2B)%20%7Bif%20(getComputedStyle(elements%5Bi%5D).position%20%3D%3D%3D%20'fixed')%20%7Belements%5Bi%5D.parentNode.removeChild(elements%5Bi%5D)%3B%7D%7D%7D)()%7D)()poor man’s dark mode:
javascript:(function(){function RGBtoHSL(RGBColor){with(Math){var R,G,B;var cMax,cMin;var sum,diff;var Rdelta,Gdelta,Bdelta;var H,L,S;R=RGBColor[0];G=RGBColor[1];B=RGBColor[2];cMax=max(max(R,G),B);cMin=min(min(R,G),B);sum=cMax+cMin;diff=cMax-cMin;L=sum/2;if(cMax==cMin){S=0;H=0;}else{if(L<=(1/2))S=diff/sum;else S=diff/(2-sum);Rdelta=R/6/diff;Gdelta=G/6/diff;Bdelta=B/6/diff;if(R==cMax)H=Gdelta-Bdelta;else if(G==cMax)H=(1/3)+Bdelta-Rdelta;else H=(2/3)+Rdelta-Gdelta;if(H<0)H+=1;if(H>1)H-=1;}return[H,S,L];}}function getRGBColor(node,prop){var rgb=getComputedStyle(node,null).getPropertyValue(prop);var r,g,b;if(/rgb\((\d+),\s(\d+),\s(\d+)\)/.exec(rgb)){r=parseInt(RegExp.$1,10);g=parseInt(RegExp.$2,10);b=parseInt(RegExp.$3,10);return[r/255,g/255,b/255];}return rgb;}function hslToCSS(hsl){return "hsl("+Math.round(hsl[0]*360)+", "+Math.round(hsl[1]*100)+"%, "+Math.round(hsl[2]*100)+"%)";}var props=["color","background-color","border-left-color","border-right-color","border-top-color","border-bottom-color"];var props2=["color","backgroundColor","borderLeftColor","borderRightColor","borderTopColor","borderBottomColor"];if(typeof getRGBColor(document.documentElement,"background-color")=="string")document.documentElement.style.backgroundColor="white";revl(document.documentElement);function revl(n){var i,x,color,hsl;if(n.nodeType==Node.ELEMENT_NODE){for(i=0;x=n.childNodes[i];++i)revl(x);for(i=0;x=props[i];++i){color=getRGBColor(n,x);if(typeof(color)!="string"){hsl=RGBtoHSL(color);hsl[2]=1-hsl[2];n.style[props2[i]]=hslToCSS(hsl);}}}}})()view toot from mastodon.social
javascript: (function () {window.location.href =https://mastodon.social/authorize_interaction?uri=${encodeURIComponent(window.location.href)}`;})();`[Comment removed by author]
Here’s one for opening the archive.is version of a page:
javascript:void(window.location = `https://archive.is/${window.location.href.split('?')[0]}`)To force PiP mode for videos on macOS in Safari, where the native video controls aren’t available:
javascript:document.querySelector(%22video%22).webkitSetPresentationMode(%22picture-in-picture%22);I have found that I can right-click in the address bar on the sound control to force PiP mode on recent versions of Safari.
https://i.imgur.com/QzRurGk.png
In case a page is lacking anchors for a section I want to link to or I want to highlight something specifically, many browser support “text fragments” these days as a way to encode a snippet of text in the URL, search for it in the page, and highlight it. The following bookmarklet automates the process for the currently selected text:
(I don’t recall where I got it from)
Example URL: https://lobste.rs/s/vjdc18/bookmarklets_do_you_use_them_if_so_wanna#:~:text=which%20is%20awesome
I have these but haven’t made a good habit to use them
ob)at least on firefox, setting keyword enables launch the ’let from the address bar. So
Ctrl-L obtakes me from firefox into emacs with my capture template (were I ever to remember I can do that)password generator in case the browser built-in doesn’t work or I need the password outside of the browser
I have a couple but they are tied to my own computer and server. Just ways of quickly automating things I do often. My own blog has a quirky micropub API homebrew implementation, so lots of “reblog”, “quote text from this page”, and other actions are just bookmarklets that either call my own server or some locally running app on my computer.
What’s the point of the
if (val < 0x7F) { return val; }? I’m pretty sure the code will work exactly the same if you remove this.Right. That’s a bug. The logical-and would just be a no-op, but same effect. I think an earlier version discarded bytes above 0x7F, which is why the code looks like that. It’s not perfect either way. @hanno set out to write the perfect JavaScript password generator once and made a good presentation & blog post about it.
45–75 for responsive typography testing and stats.js for performance monitoring.
One disadvantage of the decentralised fediverse is that I can’t be logged in to every different server, so I use a bookmarklet to open the current post or profile on my home, mtl.rocks.
I have one that converts header elements (e.g. h1, h2, etc) to anchor links (if they don’t already support it). Useful for linking to specific sections of a page (usually blog posts in my case), which subsequently helps with preserving reading progress and finding them later via browser history.
Needs a lot of reworking though now that I write this out. Can do a better job of handling some edge cases and being more generally useful!
I have 5:
Most of these form fillers work like this:
javascript:(function(){var today=new Date();var year=today.getFullYear();var month=today.getMonth()+1;var day=today.getDate();var element1=document.getElementsByClassName("marginbottom05")[0].innerText;var element2=document.getElementsByClassName("marginbottom0")[0].innerText;var url=window.location.href;var formUrl='https://docs.google.com/forms/d/e/THIS IS THE ID FOR YOUR FORM/viewform?entry.1394767016=%27+encodeURIComponent(element1)+%27&entry_1823497776=%27+encodeURIComponent(element2)+%27&entry_1559489288=%27+encodeURIComponent(url)+%27&entry.1300142439_year=%27+encodeURIComponent(year)+%27&entry.1300142439_month=%27+encodeURIComponent(month)+%27&entry.1300142439_day=%27+encodeURIComponent(day);window.location.href=formUrl;})();