|
// ==UserScript== |
|
// @name Disable Update Branch Button |
|
// @namespace https://gist.github.com/henrymai/ea9652ae9c7eb95ae929c928c44006e1 |
|
// @version 1.2 |
|
// @description Replace update branch button with a custom message in a code block |
|
// @author ChatGPT4o |
|
// @match https://github.com/*/pull/* |
|
// @icon https://www.google.com/s2/favicons?domain=github.com |
|
// @grant none |
|
// @updateURL https://gist.github.com/henrymai/ea9652ae9c7eb95ae929c928c44006e1/raw/disable_github_update_branch_button.user.js |
|
// @downloadURL https://gist.github.com/henrymai/ea9652ae9c7eb95ae929c928c44006e1/raw/disable_github_update_branch_button.user.js |
|
// ==/UserScript== |
|
|
|
|
|
// This script was generated courtesy of ChatGPT4o |
|
(function() { |
|
'use strict'; |
|
|
|
// Function to get branch names from the page |
|
function getBranchNames() { |
|
const baseRefElement = document.querySelector('.base-ref .css-truncate-target'); |
|
const headRefElement = document.querySelector('.head-ref .css-truncate-target'); |
|
|
|
const baseBranch = baseRefElement ? baseRefElement.textContent.trim() : 'unknown-base'; |
|
const headBranch = headRefElement ? headRefElement.textContent.trim() : 'unknown-head'; |
|
|
|
return { baseBranch, headBranch }; |
|
} |
|
|
|
|
|
// Function to disable the update branch buttons and replace them with a message |
|
function replaceUpdateBranchButton() { |
|
|
|
// Get branch names |
|
const { baseBranch, headBranch } = getBranchNames(); |
|
|
|
// Select all forms containing the buttons |
|
const forms = document.querySelectorAll('.js-update-branch-form'); |
|
|
|
forms.forEach(form => { |
|
if (form) { |
|
// Create a new pre element to hold the message |
|
const messagePre = document.createElement('pre'); |
|
messagePre.style.fontSize = '16px'; |
|
messagePre.style.fontWeight = 'bold'; |
|
messagePre.style.marginTop = '10px'; |
|
messagePre.textContent = |
|
`PLEASE do this locally:\n\n` + |
|
`git switch <your local pr branch>\n` + |
|
`git pull --rebase origin ${baseBranch}\n` + |
|
`# !!! Make sure to fix any conflicts from the pull rebase before pushing. !!!\n` + |
|
`git push origin -f HEAD:${headBranch}\n\n`; |
|
|
|
// Replace the form with the message pre |
|
form.parentNode.replaceChild(messagePre, form); |
|
} |
|
}); |
|
} |
|
|
|
// Run the function to replace the button with a message |
|
replaceUpdateBranchButton(); |
|
|
|
// In case the content is dynamically loaded, observe for changes and run the function again if needed |
|
const observer = new MutationObserver((mutations) => { |
|
mutations.forEach(() => { |
|
replaceUpdateBranchButton(); |
|
}); |
|
}); |
|
|
|
observer.observe(document.body, { childList: true, subtree: true }); |
|
})(); |