4 ms·
I made a bookmarklet for Firefox that opens the HN discussion in a new tab (if there is one) and offers to submit if there isn't. It's very quick and dirty but
by llimos 6y ago
I made a bookmarklet for Firefox that opens the HN discussion in a new tab (if there is one) and offers to submit if there isn't. It's very quick and dirty but it does the trick.
It opens the first result from the search API, can be modified to open all of them if you want.
javascript:(()=>{const w=window.open();fetch(`https://hn.algolia.com/api/v1/search?tags=story&query=${encodeURIComponent(window.location.href)}`).then(a => a.json()).then(a=>{const c=a.hits.filter(b=>b.url===window.location.href)[0];if(c){w.location.replace(`https://news.ycombinator.com/item?id=${c.objectID}`)}else{w.confirm('Not on HN. Submit?') ? w.location.replace(`https://news.ycombinator.com/submitlink?u=${encodeURIComponent(document.location)}&t=${encodeURIComponent(document.title)}`):w.close();}})})()
Interestingly I had to open the tab before getting the search results, it seems there is an exemption to the popup blocker for bookmarklets but only synchronously.
Edit: It seems the backticks mess something up in HN formatting. Code here: https://gist.github.com/llimos/ee818bcb3060adc8469f4978c654a184 https://gist.github.com/llimos/ee818bcb3060adc8469f4978c654a...