Ask HN: What bookmarklets do you use?

9 points by dannyphantom a day ago

Threw together a bookmarklet that sends a page over to a personal, private subreddit the other day that I've been using a ton. Also a HUGE fan of kill-sticky.

Would love to throw some other good ones up there.

https://github.com/t-mart/kill-sticky

  javascript:(function()%7Bdocument.querySelectorAll(%22body%20*%22).forEach(function(node)%7Bif(%5B%22fixed%22%2C%22sticky%22%5D.includes(getComputedStyle(node).position))%7Bnode.parentNode.removeChild(node)%7D%7D)%3Bdocument.querySelectorAll(%22html%20*%22).forEach(function(node)%7Bvar%20s%3DgetComputedStyle(node)%3Bif(%22hidden%22%3D%3D%3Ds%5B%22overflow%22%5D)%7Bnode.style%5B%22overflow%22%5D%3D%22visible%22%7Dif(%22hidden%22%3D%3D%3Ds%5B%22overflow-x%22%5D)%7Bnode.style%5B%22overflow-x%22%5D%3D%22visible%22%7Dif(%22hidden%22%3D%3D%3Ds%5B%22overflow-y%22%5D)%7Bnode.style%5B%22overflow-y%22%5D%3D%22visible%22%7D%7D)%3Bvar%20htmlNode%3Ddocument.querySelector(%22html%22)%3BhtmlNode.style%5B%22overflow%22%5D%3D%22visible%22%3BhtmlNode.style%5B%22overflow-x%22%5D%3D%22visible%22%3BhtmlNode.style%5B%22overflow-y%22%5D%3D%22visible%22%7D)()%3B%0A  
  
- bookmarklet to shoot pages over to Reddit, just swap out r/xyz:

  javascript:(function(){  var url = encodeURIComponent(window.location.href);  window.open('https://old.reddit.com/r/jchromebook/submit?url=' + url);})();
gabrielsroka an hour ago

This seems to work as well:

  javascript:open('https://old.reddit.com/r/xyz/submit?url=' + encodeURIComponent(location.href))
Notes:

1. u don't have to use `window.`, window is the default object (maybe less readable, but folks don't use window.fetch either)

2. using an IIFE is sometimes useful and necessary, but this is a simple bookmarklet

3. as i wrote in the other comment, u don't need to encode it, and if u did, you could use encodeURIComponent to do it for you. ie, show the plain code here and let someone encode it if necessary (but i've never encoded mine)

I've posted several bookmarklets here: https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...

wruza 3 hours ago

Show all images on the page in a grid with size and megapixel tags. Useful for manual scraping.

Dereferer current tab in a new tab. Some sites refuse to be referred from search/etc but copy-pasting an url into a new tab works.

Various “save” bms. Picks up a resource and opens it in new tab for a specific site that disallows right-click or hides an image in css bg, etc.

“Video”. Turns yt short into normal video (short id is regular video id).

It’s a shame that bookmarklets can’t refer to a file and require this %%% inlining. Probably solvable with tampermonkey, but not worth the research.

  • gabrielsroka an hour ago

    > refer to a file

    What do you mean?

    > require %%% inlining

    They don't, and even if they did, you could encode it yourself

ashconnor an hour ago

Add all Amex offers:

    javascript: var index,offerButtons=Array.from(document.getElementsByClassName("offer-cta")).filter(a=>"Add to Card"==a.title);for(index=0;index<offerButtons.length;++index)console.log("Clicking offer button"),offerButtons[index].click(),(async()=>{await new Promise(a=>setTimeout(a,2e3))})();
Force paste (works sometimes)

    javascript:forceBrowserDefault=(e=>{e.stopImmediatePropagation();return true;});['copy','cut','paste'].forEach(e=>document.addEventListener(e,forceBrowserDefault,true));
Facebook Marketplace delete all sold

    javascript:(async()=>{var e,l,a=Array.from(document.getElementsByClassName("x193iq5w")).filter(e=>"Sold"==e.innerHTML);for(let i=0;i<a.length;++i)console.log("Clicking Sold Listing"),a[i].click(),await new Promise(e=>setTimeout(e,3e3)),document.querySelector('[aria-label="Save"]').click(),await new Promise(e=>setTimeout(e,1e3)),document.querySelector('[aria-label="Close"]').click(),await new Promise(e=>setTimeout(e,2e3));location.reload()})();
I should really convert these to Tampermonkey scripts
  • gabrielsroka an hour ago

    i think this works for the Amex one. where do you run/test this?

      javascript:for (let b of document.querySelectorAll('.offer-cta[title="Add to Card"]')) {
        console.log("Clicking offer button");
        b.click();
        (async () => {await new Promise(r => setTimeout(r, 2e3))})();
      }
    
    does the setTimeout work? wouldn't you need something like this (in an async function)

      for (let b of document.querySelectorAll('.offer-cta[title="Add to Card"]')) {
        console.log('Clicking offer button');
        b.click();
        await new Promise(r => setTimeout(r, 2e3));
      }
justtinker a day ago

I have used variations of password revel bookmarklets. I keep searching for new one when I need them again. Most recent find was.

https://gist.github.com/robbiet480/4711696

  • gabrielsroka 20 minutes ago

    this seems to work:

      document.querySelectorAll('input[type=password]').forEach(i => i.type = 'text')
    
    or if there's only 1 password on the page

      document.querySelector('input[type=password]').type='text'