HN better domain names

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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;
    }
  }
})();