Forked from lospoy/github-milestones-redirect.js
Last active
January 4, 2024 18:22
-
-
Save reggi/38a66fe6b6ba3538f897d9ef4397467b 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