Skip to content

Instantly share code, notes, and snippets.

@chetansastry
Created April 9, 2011 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetansastry/911459 to your computer and use it in GitHub Desktop.
Save chetansastry/911459 to your computer and use it in GitHub Desktop.
A simple Greasemonkey script for a dual pane Hacker News interface
// ==UserScript==
// @name HN Dual Pane
// @namespace com.chetansastry
// @description An experimental dual pane version of Hacker News
// @include http://news.ycombinator.com/*
// ==/UserScript==
var win = unsafeWindow,
isCommentPage = !!win.location.href.match(/item\?/);
//Add splitpane
document.querySelector('body>center').style.width = '50%';
document.querySelector('body>center>table').width = '90%';
var frame = document.createElement("iframe");
frame.name = 'gm_target';
frame.style.position = 'fixed';
frame.style.width='50%';
frame.style.right=0;
frame.style.top=0;
frame.style.height='100%';
frame.style.borderStyle='none';
document.body.appendChild(frame);
if (!isCommentPage) {
//go through each link to articles and update the href target
var links = document.querySelectorAll('td.title>a');
for (var i=links.length-1; i>=0 ; i--) {
links[i].setAttribute('target', 'gm_target');
}
}
else {
//already on comment page. Load the relevant article in the frame
var articleLink = document.querySelector('td.title>a');
frame.src = articleLink.href;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment