Skip to content

Instantly share code, notes, and snippets.

@lospoy
Last active January 4, 2024 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lospoy/3cd0e5f238ae35ae48580d0925873d33 to your computer and use it in GitHub Desktop.
Save lospoy/3cd0e5f238ae35ae48580d0925873d33 to your computer and use it in GitHub Desktop.
Redirects GitHub's Milestones to a specific Sort
// ==UserScript==
// @name GitHub Milestones Redirect
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Redirects to GitHub milestones with specific parameters on link click
// @author You
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function isGitHubMilestoneURL(url) {
const urlPattern = /^https:\/\/github\.com\/[^\/]+\/[^\/]+\/milestones$/;
return urlPattern.test(url);
}
// Function to handle the link click event
function handleLinkClick() {
const u = new URL(window.location.href).pathname.split('/').filter(v => v);
const user = u[0]
const repo = u[1]
if (isGitHubMilestoneURL(window.location.href)) {
// Redirect to the specified URL
window.location.href = `https://github.com/${user}/${repo}/milestones?direction=asc&sort=due_date&state=open`
}
}
handleLinkClick()
var oldHref = document.location.href;
window.onload = function() {
var bodyList = document.querySelector("body")
var observer = new MutationObserver(function(mutations) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
/* Changed ! your code here */
handleLinkClick()
}
});
var config = {
childList: true,
subtree: true
};
observer.observe(bodyList, config);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment