HN better domain names

Displays the full domain name of each item on Hacker News.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        HN better domain names
// @description Displays the full domain name of each item on Hacker News.
// @version     2
// @namespace   https://tomkwok.com/hacker-news-greasemonkey-scripts/
// @include     http://news.ycombinator.com/*
// @include     https://news.ycombinator.com/*
// @grant       GM_addStyle
// ==/UserScript==

GM_addStyle(".orig-domain { color: #222 !important; }");

(function() {
  var HTTP_SCHEME = /^https?:\/\//;
  var spans = document.getElementsByClassName('comhead');

  for (var i = 0; i < spans.length; i++) {
    var span = spans[i];
    var a = span.previousSibling;
    var sitestr = span.getElementsByClassName('sitestr')[0];

    if (a.href && a.href.match(HTTP_SCHEME)) {
      orig_domain = new RegExp(sitestr.innerHTML.replace(/\s/, "")
                                                .replace(/\./, "\."));
      console.log(orig_domain);
      var h = a.href.replace(HTTP_SCHEME, "")
                    .replace(/\/.*/, "")
                    .replace(/^www\d*\./, "")
                    .replace(orig_domain, function (orig_domain){ return '<span class="orig-domain">' + orig_domain + '</span>'; });
      //span.innerHTML = " (" + h + ")";
      sitestr.innerHTML = h;
    }
  }
})();