Commits

Kevin Wetzels  committed 137f906

Add initial version of HN script

  • Participants
  • Parent commits f7f4bc3

Comments (0)

Files changed (1)

+// ==UserScript==
+// @name          HN clean-up
+// @namespace     http://roam.be/greasemonkey
+// @description   Make HN a bit more... better
+// @include       http://news.ycombinator.com/*
+// ==/UserScript==
+/*
+function getNewsItem(contentTable, i) {
+    var o = (i * 3) + 1;
+    return {
+        'title': contentTable.querySelector('tr:nth-child(' + o + ')'),
+        'subtext': contentTable.querySelector('tr:nth-child(' + (o + 1) + ')'),
+        'spacer': contentTable.querySelector('tr:nth-child(' + (o + 2) + ')'),
+    };
+};*/
+
+var body = document.body,
+    css = '',
+    style = document.createElement('style'),
+    layoutTable = body.getElementsByTagName('table')[0],
+    headerCell = layoutTable.querySelector('td'),
+    mainRows = layoutTable.getElementsByTagName('tbody')[0].childNodes,
+    headerRow = mainRows[0],
+    bodyWrapper = mainRows[2].querySelector('td'),
+    contentTable = bodyWrapper.querySelectorAll('table')[0],
+    contentBody = contentTable.childNodes[0];
+headerRow.setAttribute('class', 'hn-header-row');
+bodyWrapper.setAttribute('class', 'hn-body-wrapper');
+contentTable.setAttribute('class', 'hn-content-table');
+
+var rows = contentBody.childNodes,
+    i = 0,
+    len = rows.length;
+for (; i < len - 2; i += 3) {
+    if (i == 2) {alert('hi');};
+    rows[i].setAttribute('class', 'hn-news-item-title');
+    rows[i + 1].setAttribute('class', 'hn-news-item-meta');
+    rows[i + 2].setAttribute('class', 'hn-news-item-spacer');
+}
+
+style.type = 'text/css';
+css += 'body {background:#e0e4e8;padding:20px 0}';
+css += 'td.hn-header {padding: 20px;color:#fff} td.hn-header a, td.hn-header a:link, td.hn-header a:visited, td.hn-header .pagetop {color:#fff}';
+css += "table, td, th, input, .default, .comment, .title, body, .comhead, .subtext, .pagetop, .yclinks {font-family:'Helvetica Neue', Arial, sans-serif}";
+css += ".hn-news-item-title td.title:first-child {width:0px;overflow:hidden;text-indent:-9999px}";
+css += ".hn-news-item-title td:nth-child(2) {vertical-align: middle;padding: 10px 5px 0 20px;}";
+css += ".hn-news-item-title td.title:last-child {padding: 10px 5px 0 0;font-size:14px;color:#404448;line-height:14px}";
+style.innerHTML = css;
+layoutTable.setAttribute('bgcolor', '#fff');
+headerCell.setAttribute('bgcolor', '#303438');
+headerCell.setAttribute('class', 'hn-header');
+document.getElementsByTagName('head')[0].appendChild(style);