Hide github fork button

Hide github fork button for some reason.

目前為 2017-06-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Hide github fork button
  3. // @namespace https://github.com/mozillazg/hide-github-fork-button.user.js
  4. // @description Hide github fork button for some reason.
  5. // @version 0.2.0
  6. // @author mozillazg
  7. // @include https://github.com/test/*
  8. // @run-at document-end
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14.  
  15. function isContainFork() {
  16. return (document.querySelectorAll("#fork-destination-box").length !== 0);
  17. }
  18. function getSubmitTypeButtons() {
  19. var navigations = document.querySelectorAll("#js-repo-pjax-container .file-navigation button[type=submit]");
  20. var headers = document.querySelectorAll("#js-repo-pjax-container .file-header button[type=submit]");
  21. return [navigations, headers] // edit, delete buttons
  22. }
  23. function getRepoName() {
  24. var href = document.querySelectorAll('#js-repo-pjax-container h1 strong[itemprop="name"] a')[0].attributes['href'];
  25. var name = href.value;
  26. return name // "/<account>/<repo>"
  27. }
  28. function getUploadFilesButtons(repoName) {
  29. var urlSubContent = repoName + '/upload/';
  30. var selector = '#js-repo-pjax-container .file-navigation a[href^="' + urlSubContent + '"]'
  31. console.debug(selector);
  32. var buttons = document.querySelectorAll(selector);
  33. return buttons
  34. }
  35.  
  36. function hideFork() {
  37. var buttons = document.querySelectorAll(".experiment-repo-nav .pagehead-actions li");
  38. if (buttons.length > 2) {
  39. var forkButton = buttons[2];
  40. forkButton.remove();
  41. }
  42. }
  43. function hideSubmitTypeButtons() {
  44. var submitTypeButtons = getSubmitTypeButtons();
  45. submitTypeButtons.map(function(buttons) {
  46. buttons.forEach(function(button) {
  47. button.remove();
  48. });
  49. });
  50. }
  51. function hideUploadFileButtons() {
  52. var repoName = getRepoName();
  53. var buttons = getUploadFilesButtons(repoName);
  54. buttons.forEach(function(button) {
  55. button.remove();
  56. });
  57. }
  58.  
  59. // run
  60. function run() {
  61. if (isContainFork()) {
  62. hideFork();
  63. hideSubmitTypeButtons();
  64. hideUploadFileButtons();
  65. }
  66. }
  67.  
  68. // DOM targets - to detect GitHub dynamic ajax page loading
  69. var targets = document.querySelectorAll([
  70. "#js-repo-pjax-container",
  71. "#js-pjax-container"
  72. ].join(","));
  73.  
  74. Array.prototype.forEach.call(targets, function(target) {
  75. // detect DOM change
  76. new MutationObserver(function(mutations) {
  77. mutations.forEach(function(mutation) {
  78. run();
  79. });
  80. }).observe(target, {
  81. childList: true,
  82. subtree: true
  83. });
  84. });
  85.  
  86. run();
  87. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址