Created
November 6, 2023 03:08
-
-
Save hyrious/9996333a9861b4d324561c1a1ec8c568 to your computer and use it in GitHub Desktop.
Open raw link for PDF files on GitHub.
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 PDF Raw Link | |
// @namespace raw-pdf.github.hyrious.me | |
// @match https://github.com/* | |
// @grant none | |
// @version 1.0 | |
// @author hyrious | |
// @description Replace PDF file's link with its raw link | |
// @require https://cdn.jsdelivr.net/npm/selector-set@1.1.5/selector-set.js | |
// @require https://cdn.jsdelivr.net/npm/selector-observer@2.1.6/dist/index.umd.js | |
// ==/UserScript== | |
void async function() { | |
"use strict" | |
// const RAW = 'https://raw.githubusercontent.com' | |
const RAW = 'https://raw.gitmirror.com' | |
const {observe} = SelectorObserver | |
observe('.react-directory-row a[href$=".pdf"]', { | |
add(a) { | |
const {pathname} = new URL(a.href) | |
const url = RAW + pathname.replace('/blob/', '/') | |
a.href = url | |
} | |
}) | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment