Last active
January 4, 2024 21:11
-
-
Save lospoy/3cd0e5f238ae35ae48580d0925873d33 to your computer and use it in GitHub Desktop.
Redirects GitHub's Milestones to a specific Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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