Hide github fork button

Hide github fork button for some reason.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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.3.0
// @author          mozillazg
// @include         https://github.com/test/*
// @run-at          document-end
// @grant           none
// ==/UserScript==

(function () {
  "use strict";

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

  function getSubmitTypeButtons() {
    var navigations = document.querySelectorAll("#js-repo-pjax-container .file-navigation button[type=submit]");
    var headers = document.querySelectorAll("#js-repo-pjax-container .file-header button[type=submit]");
    return [navigations, headers];  // edit, delete buttons
  }

  function getRepoName() {
    var href = document.querySelectorAll('#js-repo-pjax-container h1 strong[itemprop="name"] a')[0].attributes.href;
    var name = href.value;
    return name;  // "/<account>/<repo>"
  }

  function getUploadFilesButtons(repoName) {
    var urlSubContent = repoName + '/upload/';
    var selector = '#js-repo-pjax-container .file-navigation a[href^="' + urlSubContent + '"]';
    console.debug(selector);
    var buttons = document.querySelectorAll(selector);
    return buttons;
  }

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

  function hideSubmitTypeButtons() {
    var submitTypeButtons = getSubmitTypeButtons();
    submitTypeButtons.map(function(buttons) {
      buttons.forEach(function(button) {
        button.remove();
      });
    });
  }

  function hideUploadFileButtons() {
    var repoName = getRepoName();
    var buttons = getUploadFilesButtons(repoName);
    buttons.forEach(function(button) {
      button.remove();
    });
  }

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

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