Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Bookmarklet to switch between HackerNews and HackerWeb

This bookmarklet toggles between HackerNews pages and Cheeuan's HackerWeb interface. If you're not on either then it acts a a bookmark to HackerWeb.

The code

If you edit this, use something like bookmarkleter to convert it into a bookmarklet.

if ( /https?:\/\/news\.ycombinator\.com\/item\?id=(\d+)/.test(location) ) {
   location = 'http://cheeaun.github.io/hackerweb/#/item/' + RegExp.$1;
}
else if ( /http:\/\/cheeaun\.github\.io\/hackerweb\/#\/item\/(\d+)/.test(location) ) {
   location = 'https://news.ycombinator.com/item?id=' + RegExp.$1;
}
else {
   location = 'http://cheeaun.github.io/hackerweb/';
}

The bookmarklet

Create a bookmark to HackerNews then edit it and paste the following into the URL/address field:

javascript:(function(){if(/https%3F:\/\/news\.ycombinator\.com\/item\%3Fid=(\d+)/.test(location)){location='http://cheeaun.github.io/hackerweb/%23/item/'+RegExp.$1;}else%20if(/http:\/\/cheeaun\.github\.io\/hackerweb\/%23\/item\/(\d+)/.test(location)){location='https://news.ycombinator.com/item%3Fid='+RegExp.$1;}else{location='http://cheeaun.github.io/hackerweb/';}})();
@gbrayut

This comment has been minimized.

Copy link

gbrayut commented Mar 28, 2017

Domain has changed from http://cheeaun.github.io/hackerweb/ to https://app.hackerwebapp.com. To avoid the redirect the bookmarklet should be:

javascript:(function(){if(/https%3F:\/\/news\.ycombinator\.com\/item\%3Fid=(\d+)/.test(location)){location='https://app.hackerwebapp.com/%23/item/'+RegExp.$1;}else if(/https:\/\/app\.hackerwebapp\.com\/%23\/item\/(\d+)/.test(location)){location='https://news.ycombinator.com/item%3Fid='+RegExp.$1;}else{location='https://app.hackerwebapp.com';}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.