github merge blocker

Disable merge buttons for the base branches you wish to restrict.

  1. // ==UserScript==
  2. // @name github merge blocker
  3. // @namespace maoanran@gmail.com
  4. // @version 2024-05-10
  5. // @description Disable merge buttons for the base branches you wish to restrict.
  6. // @author maoanran
  7. // @match https://github.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let RESTRICTED_BASE_BRANCHES = ['main', 'master'] // Change the array to add more branches to prevent merging
  16.  
  17. function runWhenReady(readySelector, callback) {
  18. var numAttempts = 0;
  19. var tryNow = function() {
  20. var elem = document.querySelector(readySelector);
  21. if (elem) {
  22. callback(elem);
  23. } else {
  24. numAttempts++;
  25. if (numAttempts >= 10) {
  26. console.warn('Giving up after 10 attempts. Could not find: ' + readySelector);
  27. } else {
  28. setTimeout(tryNow, 250 * Math.pow(1.1, numAttempts));
  29. }
  30. }
  31. };
  32. tryNow();
  33. }
  34.  
  35. let baseBranch = document.querySelectorAll('.commit-ref.base-ref span');
  36.  
  37. if (baseBranch.length == 1 && RESTRICTED_BASE_BRANCHES.includes(baseBranch[0].innerText)) {
  38. runWhenReady('.BtnGroup button', function() {
  39. document.querySelectorAll('.BtnGroup button').forEach(button => button.setAttribute("disabled","disabled"));
  40. })
  41. }
  42.  
  43. })();

QingJ © 2025

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