Skip to content

Instantly share code, notes, and snippets.

@pevd950
Created November 9, 2023 17:16
Show Gist options
  • Select an option

  • Save pevd950/af706a82c5844b4a67a9f7abaf3aeba4 to your computer and use it in GitHub Desktop.

Select an option

Save pevd950/af706a82c5844b4a67a9f7abaf3aeba4 to your computer and use it in GitHub Desktop.
Gets PR title and URL and uses url scheme to call iOS Shortcut that parses the text and adds as a reminder
// ==UserScript==
// @name Create PR Reminder
// @description This is your new file, start writing code
// @match https://github.com/*/*/pull/*
// ==/UserScript==
(function () {
"use strict";
function addButton() {
// Check if the button is already added
if (document.querySelector(".add-pr-reminder")) {
return;
}
// Locate the title element
let titleElement = document.querySelector(".gh-header-title");
if (!titleElement) {
// Title element not found, exit the function
return;
}
let title = titleElement.textContent.trim();
let prUrl = window.location.href;
// Create the copy button
let reminderButton = document.createElement("pr-reminder");
reminderButton.classList.add("btn", "btn-sm", "add-pr-reminder");
// copyButton.setAttribute('value', title);
reminderButton.innerHTML = "Add Reminder";
// Style the button to fit GitHub's UI
reminderButton.style.marginLeft = "8px";
// Event listener for the button
reminderButton.addEventListener("click", function () {
let shortcutName = "Remind me to Review PR";
let inputText = `${title}\n${prUrl}`;
let shortcutUrl = `shortcuts://run-shortcut?name=${encodeURIComponent(
shortcutName
)}&input=text&text=${encodeURIComponent(inputText)}`;
// Open the iOS Shortcut URL
window.location.href = shortcutUrl;
});
// Add the copy button next to the pull request title
let titleContainer = document.querySelector(".gh-header-title");
if (titleContainer) {
titleContainer.appendChild(reminderButton);
}
}
// Since GitHub uses pjax for navigation, we need to add our button on history change as well
addButton(); // Add when the script loads
window.addEventListener("pjax:end", addButton); // Add when pjax navigation completes
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment