HN New Tab

Makes all links to posts and users open in a new tab

< 脚本 HN New Tab 的反馈

评价:好评 - 脚本运行良好

§
发布于:2015-07-31
编辑于:2015-07-31

alternative impl

I tried to use querySelectorAll to achieve the same to target the links to be opened in new tabs.

(function() {
  var filters = [
    'a',
    'not([onclick])',
    'not([target])',
    'not([class*=pocket])',
    'not([href^="#"])',
    'not([href^=mailto])',
    'not([href^=logout])'
  ],
      links = document.querySelectorAll(filters.join(':'));
  for (var i=0; i<links.length; i++) {
    links[i].setAttribute('target', '_blank');
  }
})();

发布留言

登录以发布留言。