Skip to content

Instantly share code, notes, and snippets.

@dcdunkan
Created June 22, 2023 14:23
Show Gist options
  • Save dcdunkan/6ba8d92d6a6ce6aab0c444106005265c to your computer and use it in GitHub Desktop.
Save dcdunkan/6ba8d92d6a6ce6aab0c444106005265c to your computer and use it in GitHub Desktop.
For some reason its not possible to access GitHub raw links via Jio's connection. So a tiny temporary unreliable fix.
// ==UserScript==
// @name GitHub raw links bypasser for Jio connections
// @namespace http://tampermonkey.net/
// @version 0.1
// @description For some reason its not possible to access GitHub raw links via Jio's connection. So a tiny temp unreliable fix.
// @author Dunkan <https://github.com/dcdunkan>
// @match http*://github.com/*
// @match http*://raw.githubusercontent.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver(function () {
const elements = [
...document.getElementsByTagName("a"),
...document.getElementsByTagName("img"),
];
let changedCount = 0;
for (const element of elements) {
const attributeName = element.tagName === "IMG"
? "src"
: element.tagName === "A"
? "href"
: "";
const link = element[attributeName];
if (
link === "" && !link.includes("://") && !link.startsWith("http:") &&
!link.startsWith("https:") && !link.startsWith("/")
) continue;
const url = new URL(link, "https://github.com");
const params = new URLSearchParams(url.search);
const pathSegments = url.pathname.split("/");
if (url.hostname === "raw.githubusercontent.com") {
url.hostname = "gre.deno.dev";
} else if ( // github.com/user/repo/raw/path || github.com/user/repo/blob/path?raw=true
url.hostname === "github.com" && pathSegments[1] !== "" &&
pathSegments[2] !== "" && pathSegments[4] !== "" && pathSegments[5] !== "" &&
(pathSegments[3] === "raw" || (pathSegments[3] === "blob" && params.get("raw") === "true"))
) {
url.hostname = "gre.deno.dev";
pathSegments.splice(3, 1);
url.pathname = pathSegments.join("/");
console.log("lel", url);
} else {
continue;
}
element[attributeName] = url.toString();
changedCount++;
}
console.info(`${changedCount} changed to GRE link${changedCount > 1 ? "s" : ""}`);
});
observer.observe(document.body, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ["src", "href"]
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment