Disable Squash and Merge on Mondays

Disable buttons with text "Squash and merge" on Mondays

当前为 2024-12-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Disable Squash and Merge on Mondays
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Disable buttons with text "Squash and merge" on Mondays
// @author       Your Name
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Check if today is Monday
    const today = new Date();
    const isMonday = today.getDay() === 4;
    let disabledButtons = [];

      let autoMergeIntervalId;
      let disableButtonsIntervalId;

    if (isMonday) {
        // Function to disable buttons
        const disableButtons = () => {
            const buttons = document.querySelectorAll('button');
            buttons.forEach(button => {
                if (button.textContent.trim() === 'Squash and merge' || button.textContent.trim() === 'Enable auto-merge (squash)') {
                    button.disabled = true;
                    disabledButtons.push(button);
                }
            });
        };

        const checkForButtonAndShowDialog = () => {
            const button = Array.from(document.querySelectorAll('button')).find(btn => btn.textContent.trim() === 'Disable auto-merge');

            if (button) {
                const userConfirmed = confirm('It is Monday and likely you should not be merging, do you want to disable auto-merge?');
                if (userConfirmed) {
                    button.click();
                } else {
                    clearInterval(autoMergeIntervalId);
                }
            }
        };

        const enableButtons = () => {
            disabledButtons.forEach(button => {
                button.disabled = false;
            });
            disabledButtons = [];
        };

        const banner = document.createElement('div');
        banner.style.position = 'fixed';
        banner.style.top = '0';
        banner.style.left = '0';
        banner.style.width = '100%';
        banner.style.backgroundColor = 'green';
        banner.style.color = 'white';
        banner.style.textAlign = 'center';
        banner.style.padding = '10px';
        banner.style.zIndex = '1000';
        banner.textContent = 'It is Monday and you might not want to be merging since it will interfere with release!';

        const button = document.createElement('button');
        button.textContent = 'Re-enable Merging (Release is over)';
        button.style.marginLeft = '20px';
        button.onclick = () => {
            clearInterval(autoMergeIntervalId);
            clearInterval(disableButtonsIntervalId);
            enableButtons();
            banner.remove();
        };

        banner.appendChild(button);
        document.body.appendChild(banner);


        autoMergeIntervalId = setInterval(checkForButtonAndShowDialog, 2000);
        disableButtonsIntervalId = setInterval(disableButtons, 2000);
    }
})();