Hacker News new | past | comments | ask | show | jobs | submit login
Easier browsing of Hacker News...for me
57 points by nirmal on June 13, 2008 | hide | past | favorite | 36 comments
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.




So I went to add this splitview thing to my Greasemonkey script for Hacker News, only I did the same thing without hitting your site for the frameset (completely clientside js). It works quite nicely, but for some reason I had to resort to something I consider quite ugly.

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.


Disclaimer: I've never used Greasemonkey (now an Opera user) and have only spent a few minutes trying to figure out how it interfaces with the browser. I know my way around JS though.

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.


Yeah I learned about the XPCNativeWrapper objects last night too. Basically GM has access to every object (from window/document on down) as one of these for security purposes (so the target page can't redefine standard methods). Due to the vagaries of the way they are implemented, you can't call the onclick/onkeypress/etc methods directly. It actually states in the documentation that addEventListener is the preferred (and only working) method.

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.


Yay! Glad you got it sorted out. I was stumped, and finally ran out of time to keep tinkering with it. Even with the code firing after the page was done loading, I still couldn't get it working right.

| 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.


I've installed the script under Safari and FF2 and I don't notice anything happening. Is it overwriting the existing links? I didn't do that because sometimes I may only want to quickly see the comments or main article.

Firebug doesn't seem to be showing me any errors either.

BTW: I like the title of your blog, "Artfully Underemployed" :)


If you installed it for the first time, make sure you turn the feature on. Look for the link called "blacklist" in the top bar of HN, which will pull up the options for the script. Check the box next to split view.

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!


Cool, I got it to work in FF. It doesn't work under Safari (no blacklist in the toolbar). I noticed extra scroll bars in FF but my guess is that's because there is some css padding/margin stuff applied to the body.

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.


I'll keep the back button thing in mind when I look at it again... and I noticed the weird scrollbar stuff too. I'll have to fix that at some point. I've been up since 4pm yesterday, and seeing as how it is noon, think I'm going to head towards bed for a bit.

Maybe it'll all be clear when I wake up.


I didnt look to closely, but it looks like you are creating a closure around the comments var for your event listener function. The problem is that you are doing this within a loop, meaning the comments var changes after each iteraion, probably ending up in something you hadnt intended


But even if I create an anonymous function that just calls alert(), the click event never fires. i.e. ->

  byId(thisnode.id).addEventListener('click', function(ev) { alert('test'); }, false);
Won't fire either.


For one thing, the function returned by createFramesetReal() seems to be using the undefined variable 'b'.


Op, I had that in a previous version, musta accidently cut that out when cleaning it up. It didn't have an effect though.

Went ahead and set it to what it should be... body.


Just an update to this. I have the problem fixed now, so thanks all that looked at it. (And thaumaturgy, I owe you a beer.)

New version is on the userscripts page for anyone that wants it: http://userscripts.org/scripts/show/25039


UPDATES: For greasemonkey/kit users. Clicking Split View links in the right frame will now not cause internal splitting.

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.


This script assumes that I visit news.ycombinator.com to read news. I'd prefer a Firefox extension that compares the addresses of web pages I visit with links in the news.ycombinator.com RSS feed. That way I'd be notified that there's a discussion thread about the page I'm currently viewing.


very nice, and very useful...can you make it a one click thing? right now I have to click on the bookmarklet and then click on split view. If it was just one link that would be awesome. I wonder if this can be tweaked to work from within Google Reader, hmmm..I'll tinker with that a bit.

thanks again!


I turned this into a Greasemonkey script for any Firefox users.

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.


Quite the contrary, thanks for doing it! I used to be worried by the constant security issues when Greasemonkey came out (back in the day). I never got into it and now I use Safari. Do you know if this works under Creammonkey for Safari? I may go install it if it does.


I have no idea. All I did really was copy all the Firefox relevant lines out of the functions and if statements, so they'd get executed right as the page loads. I'm now going to try to get it to work without your web link, so if your website goes down, the script will still work. If you want any credit, just tell me, and I'll add what I can :)


http://userscripts.org/scripts/show/28372

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.


I don't understand what you changed? Can you please elaborate?


I just wrapped your code in a closure so it would run immediately. This makes GreaseKit or Greasemonkey prompt you to install. This way you don't have to go and install it manually.

Thanks for turning me back on to userscripts!


Doesn't work for me on Firefox 2


I was able to install it just fine. I'm on OS X with FF2.


I think that would require the script running at the loading of the page. This could probably be done with a Greasemonkey script (Creammonkey for Safari).


Wah NirmalBhai, wah.

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


Fixed.


i was thinking about proposing this as a feature. because when dealing with submissions, the constant is that i look at both the article and the comments


On Opera, it says "Unsupported browser". Why not?


I had modified the bookmarklet to allow opera but it doesn't like the code on my splitting page. I'm not sure why though. It's pretty tame JS. Opera also doesn't show me any errors in the Error Console.


This is brilliant.


i'm too retarded to install this but not too proud to admit it.. it sounds like it scrolls 2+ windows with one control:

xcroll


Simple, but effective. Awesome.


I love you, nirmal.


wow this is so useful. kudos =]

My first bookmarklet too, really.


10 /10




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: