Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  // ==UserScript==
  // @name				 news.yc open in new tab
  // @namespace		 http://joshwand.com/
  // @description	 opens links on news.yc's list pages in new tabs/windows
  // @include			 http://news.ycombinator.com/
  // @include			 http://news.ycombinator.com/news
  // @include			 http://news.ycombinator.com/newest
  // @include			 http://news.ycombinator.com/x?*

  // ==/UserScript==

  var a, links, thisdomain;
  thisdomain = window.location.host;

  links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++) {
      a = links[i];
      if (a.host && (a.host != thisdomain || String(a).match(/item\?id=/))) {
          a.target = "_blank";
      }
  }


I would prefer the loop this way:

  for each(a in links) 
   if (a.host && (a.host!=thisdomain || String(a).match(/item\?id=/)))
    a.target = "_blank";


What can I say, I don't actually know JS. I just cargo-culted this from another similar script.




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

Search: