Easier browsing of Hacker News...for me
http://nirmalpatel.com/#hnsplitview
HN SplitView is a bookmarklet that adds a link labelled "SPLIT VIEW" to each post on the Hacker News website. This link allows the user to open the post and the discussion page side by side in frames. Simply drag the link for HN SplitView to your toolbar or add it as a favorite.
I've been using this and it makes it easier for me to browse. I hope that other members of the HN community find it useful. I've tested it under Safari and FF. Let me know if you guys have any problems.
EDIT: It doesn't add the link for posts like this one or those of the "Ask HN:" variety.
40 comments
[ 2.5 ms ] story [ 84.4 ms ] threadthanks again!
http://userscripts.org/scripts/show/28371
If the author doesn't like it, PM me, and I'll delete this post and the Userscripts.org post.
I just modified it so that it would prompt for install when you clicked Install Script. GreaseKit for Safari doesn't have an Install User Script option...work in progress.
Thanks for turning me back on to userscripts!
My first bookmarklet too, really.
Btw, There s one minor bug. If I click the bookmarklet more than once, it adds "|SPLIT VIEW |" more than once.
| SPLIT VIEW | SPLIT VIEW | SPLIT VIEW | SPLIT VIEW | SPLIT VIEW
Can someone please look at the code below (and read my comments in it) and tell me why the three addEventListeners that I have commented out won't work? I'd really really like to know why I am being retarded and how to fix it, as the solution I ended up with seems unnecessarily ugly.
View code here: http://userscripts.org/scripts/review/25039
Or if you don't care about it being ugly and just want to use it: http://userscripts.org/scripts/show/25039
But I'd really appreciate help with figuring out the issue with the addEventListeners.
Went ahead and set it to what it should be... body.
Firebug doesn't seem to be showing me any errors either.
BTW: I like the title of your blog, "Artfully Underemployed" :)
Since this is becoming more than just the simple blacklist script it originally was, I suppose I should rename it or something to make that more clear. ;)
Oh and I almost forgot, thanks for the brilliant idea!
Because it overrides the page itself you can't click "Back" or Alt+Left or whatever to go back to the list of stories. I did go back and add the check for if I'm already inside the frameset to my code though. Gotta prevent those recursive split views :). Now if you surf back to the main page in the right frame and click on a SplitView link it will reload both frames.
I will look at it in Safari some and see if I can figure out what the deal is there. Safari's Activity window doesn't show any errors.
I'll also see what I can think of for the Back button issue when doing it your way. That may not be a big deal to anyone else though.
Maybe it'll all be clear when I wake up.
That said, after doing some testing I think your issue is that the page isn't completely loaded before the addEventListener is called. Changing the addEventListener line to a simple element.onclick = function(alert) triggers an error in the browser; so does trying to ask about the element's onclick function. Putting in an alert box in place of the addEventListener line pretty clearly demonstrates that the page is still loading when the code is being called on the links. Firefox is a little touchy about that.
I'm still working on it, lemme see what happens if I wrap up your script's initialization section into a document.onload, or something similar.
Edit: Also, elements are being returned as XPCNativeWrapper objects [http://developer.mozilla.org/en/docs/XPCNativeWrapper]. I'm totally unfamiliar with those; maybe that's interfering with the event attachment somehow?
Edit: Yeah, looks like it. I wasn't sure, so I had to test, but references to elements from directly inside the code body get the XPCNativeWrapper objects, which provide protection for some properties. But, code called from a setTimeout doesn't get those objects, and gets direct access to the elements. Not sure how to fix that right since I've never encountered that before.
You can supposedly get access to the underlying JS object from the XPCNativeWrapper object with the wrappedJSObject property and then act on it, but it's a big security no-no. I tried it anyway to no avail.
Your thought on the page not being loaded is kind of where I ended up too. However, my understanding was that GM ran user scripts after the window.onload finished, but I could be completely wrong here. If I assign all the links id attributes in the GM script and then manually add event listeners in my Firebug console, they work fine. Also, you'll notice that later in my script I add click listeners on other items (buttons and links) that work swimmingly, so it's either entirely arbitrary or I'm missing something very obvious.
Thanks for looking at this, I'll look forward to any other thoughts you have.
EDIT: Looks like I was very wrong about the GM script executing after the window load event. I have been playing with wrapping code in a load event listener and have indeed got it working that way. Thanks for the suggestion! I'll hopefully have something polished and posted soon.
| You can supposedly get access to the underlying JS object from the XPCNativeWrapper object with the wrappedJSObject property and then act on it, but it's a big security no-no. I tried it anyway to no avail.
The other wrong way that I found out about was the unsafeWindow object; same kind of deal, gives you direct access to the page.
New version is on the userscripts page for anyone that wants it: http://userscripts.org/scripts/show/25039
UPDATES: I can't edit the main post anymore so I thought I would try and summarize the updates here.
Oompa posted a Greasemonkey script here: http://userscripts.org/scripts/show/28371
I modified to work on multiple pages under hacker news, you can find it here: http://userscripts.org/scripts/show/28372
The bookmarklet still works and is located at the URL in the post.
The bookmarklet will not continue adding SPLIT VIEW links after it has been used once.
xcroll