Last active
February 16, 2024 07:17
-
-
Save sutnistj/466788c1dce475c71c45a4e279ec63b7 to your computer and use it in GitHub Desktop.
Reddit Link Fixer
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 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