GitHub squash reminder

Adds an reminder to squash PRs that have > 1 commit

As of 2018-05-29. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        GitHub squash reminder
// @namespace   urn://https://www.georgegillams.co.uk/api/greasemonkey/github_squash_reminder
// @include     *github.com*
// @exclude     none
// @version     2
// @description:en	Adds an reminder to squash PRs that have > 1 commit
// @description   	Adds an reminder to squash PRs that have > 1 commit
// @grant    		none
// ==/UserScript==

let lastModifiedPr = null;

function addReminder() {
  let prId = `${window.location}`.split("pull/")[1];
  if (lastModifiedPr === prId) {
    return;
  } else {
    let commitCount = parseInt(
      document.getElementById("commits_tab_counter").textContent
    );
    console.log(commitCount);
    if (commitCount !== 1) {
      let allElements = document.getElementsByTagName("DIV");
      for (let i = 0; i < allElements.length; i += 1) {
        let element = allElements[i];
        if (element.className === "merge-message") {
          element.innerHTML =
            `<div style="display: block;margin-bottom: -2rem;text-decoration: none;font-weight: bold;font-size: 1.5rem;font-family: Quattrocento Sans,sans-serif;color: #e02626;">REMEMBER TO SQUASH!</div> <br/> <br/>` +
            element.innerHTML;
        }
      }
      allElements = document.getElementsByTagName("BUTTON");
      for (let i = 0; i < allElements.length; i += 1) {
        let element = allElements[i];
        if (
          element.textContent &&
          element.textContent.includes("Merge pull request")
        ) {
          element.disabled = true;
          element.textContent = "MERGE ONLY ONCE SQUASHED!";
          element.style.backgroundImage =
            "linear-gradient(-180deg, #e02626 0%, #9F2D27 90%)";
          element.style.color = "white";
        }
      }
    }
    lastModifiedPr = prId;
  }
}

setInterval(addReminder, 2000);