Skip to content

Instantly share code, notes, and snippets.

@albertopasqualetto
Last active February 24, 2025 23:37
Show Gist options
  • Save albertopasqualetto/4d00d83794d3fff1039cb86680242633 to your computer and use it in GitHub Desktop.
Save albertopasqualetto/4d00d83794d3fff1039cb86680242633 to your computer and use it in GitHub Desktop.
GitHub Release Redirect Userscript
// ==UserScript==
// @name GitHub Release Redirect
// @namespace albertopasqualetto
// @version 1.1
// @description Redirect from specific GitHub release pages to the main releases page, unless coming from there
// @author albertopasqualetto
// @match *://github.com/*
// @icon https://github.githubassets.com/pinned-octocat.svg
// @grant none
// @downloadURL https://gist.github.com/albertopasqualetto/4d00d83794d3fff1039cb86680242633/raw/gh_release_redirect.user.js
// @updateURL https://gist.github.com/albertopasqualetto/4d00d83794d3fff1039cb86680242633/raw/gh_release_redirect.user.js
// ==/UserScript==
(function () {
'use strict';
// Function to handle redirection
const redirectIfNeeded = () => {
// Get the current URL
const currentUrl = window.location.href;
// Check if the current URL is a release tag page
if (/github\.com\/[^/]+\/[^/]+\/releases\/tag\//.test(currentUrl)) {
// Compute the generic releases page URL (removing everything after "/tag/")
const releasesUrl = currentUrl.split('/tag/')[0];
// Check if we're coming from the generic releases page
const isComingFromReleases = document.referrer.startsWith(releasesUrl);
// If not coming from releases page, redirect
if (!isComingFromReleases) {
window.location.replace(releasesUrl);
}
}
};
// Initial check (in case the page was loaded directly)
redirectIfNeeded();
// Use MutationObserver to monitor URL changes in Single-Page Applications
const observer = new MutationObserver(() => {
redirectIfNeeded();
});
// Observe changes to the <body> element (to detect SPA navigation)
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment