Skip to content

Instantly share code, notes, and snippets.

@SamHasler
Forked from noibl/hn-betteridge.user.js
Created June 11, 2012 09:03
Show Gist options
  • Select an option

  • Save SamHasler/2909187 to your computer and use it in GitHub Desktop.

Select an option

Save SamHasler/2909187 to your computer and use it in GitHub Desktop.

Revisions

  1. @noibl noibl revised this gist Jun 11, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions hn-betteridge.user.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    // ==UserScript==
    // @name BetteridgeLinks
    // @description Lowlight headlines on Hacker News that conform to Betteridge's Law
    @@ -44,7 +43,7 @@ function run() {
    style = document.createElement('style'),
    rules = document.createTextNode(cssRules);
    style.type = 'text/css';
    if (style.styleSheet) { style.styleSheet.cssText = rules.noeValue; }
    if (style.styleSheet) { style.styleSheet.cssText = rules.nodeValue; }
    else { style.appendChild(rules); }
    head.appendChild(style);
    testLinks();
  2. @invalid-email-address Anonymous revised this gist Jun 11, 2012. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions hn-betteridge.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@

    // ==UserScript==
    // @name BetteridgeLinks
    // @description Lowlight headlines on Hacker News that conform to Betteridge's Law
    // @version 0.2
    // @version 0.3
    // @match http://news.ycombinator.com/*
    // @author noibl <pjpee6w5pc@snkmail.com>
    // ==/UserScript==
    @@ -19,9 +20,10 @@ var cssRules = 'a.hn-betteridge:link { color: #828282; } '
    + 'content: " ' + label + '" '
    + '}';
    var pages = [
    '^http:\\/\\/news\\.ycombinator\\.com\\/$',
    '^http:\\/\\/news\\.ycombinator\\.com\\/newest$',
    '^http:\\/\\/news\\.ycombinator\\.com\\/x\\?fnid='
    '^/$',
    '^/news$',
    '^/newest$',
    '^/x$'
    ];

    init();
    @@ -30,7 +32,7 @@ function init() {
    var re;
    for (var i = 0; i < pages.length; i++) {
    re = new RegExp(pages[i]);
    if (re.test(window.location.href)) {
    if (re.test(window.location.pathname)) {
    run();
    break;
    }
    @@ -60,4 +62,4 @@ function testLinks() {
    function isBetteridge(text) {
    var re = new RegExp('^(' + questions.join('|') + ').*\\?$');
    return re.test(text);
    }
    }
  3. @invalid-email-address Anonymous revised this gist Jun 11, 2012. 1 changed file with 18 additions and 20 deletions.
    38 changes: 18 additions & 20 deletions hn-betteridge.user.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@

    // ==UserScript==
    // @name BetteridgeLinks
    // @description Lowlight headlines on Hacker News that conform to Betteridge's Law
    // @version 0.1
    // @version 0.2
    // @match http://news.ycombinator.com/*
    // @author noibl <pjpee6w5pc@snkmail.com>
    // ==/UserScript==
    @@ -20,24 +19,25 @@ var cssRules = 'a.hn-betteridge:link { color: #828282; } '
    + 'content: " ' + label + '" '
    + '}';
    var pages = [
    'http://news.ycombinator.com/',
    'http://news.ycombinator.com/newest'
    '^http:\\/\\/news\\.ycombinator\\.com\\/$',
    '^http:\\/\\/news\\.ycombinator\\.com\\/newest$',
    '^http:\\/\\/news\\.ycombinator\\.com\\/x\\?fnid='
    ];

    // IE.enhance!
    if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj){
    for(var i=0; i<this.length; i++){
    if(this[i]==obj){
    return i;
    }
    init();

    function init() {
    var re;
    for (var i = 0; i < pages.length; i++) {
    re = new RegExp(pages[i]);
    if (re.test(window.location.href)) {
    run();
    break;
    }
    return -1;
    }
    }

    function init() {
    if (0 > pages.indexOf(window.location.href)) { return false; }
    function run() {
    var head = document.getElementsByTagName('head')[0],
    style = document.createElement('style'),
    rules = document.createTextNode(cssRules);
    @@ -48,11 +48,6 @@ function init() {
    testLinks();
    }

    function isBetteridge(text) {
    var re = new RegExp('^(' + questions.join('|') + ').*\\?$');
    return re.test(text);
    }

    function testLinks() {
    var links = document.querySelectorAll(selector);
    for (var i = 0; i < links.length; i++) {
    @@ -62,4 +57,7 @@ function testLinks() {
    }
    }

    init();
    function isBetteridge(text) {
    var re = new RegExp('^(' + questions.join('|') + ').*\\?$');
    return re.test(text);
    }
  4. @invalid-email-address Anonymous created this gist Jun 11, 2012.
    65 changes: 65 additions & 0 deletions hn-betteridge.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@

    // ==UserScript==
    // @name BetteridgeLinks
    // @description Lowlight headlines on Hacker News that conform to Betteridge's Law
    // @version 0.1
    // @match http://news.ycombinator.com/*
    // @author noibl <pjpee6w5pc@snkmail.com>
    // ==/UserScript==

    var questions = ['Is', 'Are', 'Does', 'Do', 'Has', 'Have', 'Did', 'Will', 'Can', 'Could', 'Should'];
    var selector = '.title a';
    var label = 'Probably not';
    var className = 'hn-betteridge';
    var cssRules = 'a.hn-betteridge:link { color: #828282; } '
    + 'a.hn-betteridge:after {'
    + 'color: #600; font-size: 50%; '
    + 'text-transform: uppercase; '
    + 'letter-spacing: 1px; '
    + 'background-color: #fff; '
    + 'content: " ' + label + '" '
    + '}';
    var pages = [
    'http://news.ycombinator.com/',
    'http://news.ycombinator.com/newest'
    ];

    // IE.enhance!
    if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj){
    for(var i=0; i<this.length; i++){
    if(this[i]==obj){
    return i;
    }
    }
    return -1;
    }
    }

    function init() {
    if (0 > pages.indexOf(window.location.href)) { return false; }
    var head = document.getElementsByTagName('head')[0],
    style = document.createElement('style'),
    rules = document.createTextNode(cssRules);
    style.type = 'text/css';
    if (style.styleSheet) { style.styleSheet.cssText = rules.noeValue; }
    else { style.appendChild(rules); }
    head.appendChild(style);
    testLinks();
    }

    function isBetteridge(text) {
    var re = new RegExp('^(' + questions.join('|') + ').*\\?$');
    return re.test(text);
    }

    function testLinks() {
    var links = document.querySelectorAll(selector);
    for (var i = 0; i < links.length; i++) {
    if (isBetteridge(links[i].innerHTML)) {
    links[i].className += ' ' + className;
    }
    }
    }

    init();