Skip to content

Instantly share code, notes, and snippets.

@sutnistj
Last active February 16, 2024 07:17
Show Gist options
  • Save sutnistj/466788c1dce475c71c45a4e279ec63b7 to your computer and use it in GitHub Desktop.
Save sutnistj/466788c1dce475c71c45a4e279ec63b7 to your computer and use it in GitHub Desktop.
Reddit Link Fixer
// ==UserScript==
// @name Old Reddit Link Fixer
// @author Jurid
// @description Fixes incorrect backslash placement in links on Old Reddit
// @match https://*.reddit.com/*
// @version 16-Feb-2024
// ==/UserScript==
onmouseover = (event) => {
const a = event.target.closest('.usertext-body a')
if (a.matches('a[class*="expando-button"]')) return
if (a.matches('a[href*="%5C_"]') && a.innerText === a.href.replaceAll('%5C_', '\\_')) removeBackslashes(a)
if (a.matches('a[href*="reddit.com/media?url="]')) returnNormalMedia(a)
if (a.innerText === a.href) a.innerText = a.href = decodeURI(a.href)
}
function removeBackslashes(a) {
a.href = a.href.replaceAll('%5C_', '_');
a.innerText = a.innerText.replaceAll('\\_', '_')
}
function returnNormalMedia(a) {
a.href = decodeURIComponent(a.href.replace(/^.*?reddit\.com\/media\?url=/, ''))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment