Hide github fork button

Hide github fork button for some reason.

Verze ze dne 12. 04. 2016. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name            Hide github fork button
// @namespace       https://github.com/mozillazg/hide-github-fork-button.user.js
// @description     Hide github fork button for some reason.
// @version         0.1.0
// @author          mozillazg
// @include         https://github.com/test/*
// @run-at          document-end
// ==/UserScript==

(function () {
  "use strict";

  function isContainFork() {
    return (document.querySelectorAll("#fork-destination-box").length !== 0);
  }

  function hideFork() {
    var buttons = document.querySelectorAll(".experiment-repo-nav .pagehead-actions li");
    if (buttons.length > 2) {
      var forkButton = buttons[2];
      forkButton.remove();
    }
  }

  // run
  function run() {
    if (isContainFork()) {
      hideFork();
    }
  }

  // DOM targets - to detect GitHub dynamic ajax page loading
  var targets = document.querySelectorAll([
    "#js-repo-pjax-container",
    "#js-pjax-container"
  ].join(","));

  Array.prototype.forEach.call(targets, function(target) {
    // detect DOM change
    new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        run();
      });
    }).observe(target, {
      childList: true,
      subtree: true
    });
  });

  run();
})();