Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created November 6, 2023 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrious/9996333a9861b4d324561c1a1ec8c568 to your computer and use it in GitHub Desktop.
Save hyrious/9996333a9861b4d324561c1a1ec8c568 to your computer and use it in GitHub Desktop.
Open raw link for PDF files on GitHub.
// ==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