Last active
April 27, 2023 08:18
-
-
Save remi6397/d581dc36fbabd47516a4ed8deb6d4e03 to your computer and use it in GitHub Desktop.
Bring Back Reddit Compact!
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 Bring back Reddit Compact | |
// @match https://*.reddit.com/* | |
// @grant none | |
// @version 1.11 | |
// @license Unlicense; https://unlicense.org/ | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const compactTrailMatch = /\/(\.compact)?\/?$/; | |
const compactOrITrailMatch = /(\/(\.compact|\.i)?\/?)+$/; | |
function replaceLinks() { | |
document.querySelectorAll('a[href*="/r/"]').forEach(link => { | |
if (link.href.startsWith('/r/') || link.href.match(/reddit\.com\/r\//)) | |
link.href = link.href.replace(compactOrITrailMatch, '/.i'); | |
}); | |
} | |
window.onload = () => { | |
replaceLinks(); | |
// TODO: hook scroll | |
setInterval(replaceLinks, 0.5); | |
const srcURL = window.location.href; | |
if (!document.querySelector('shreddit-player')) { | |
if (srcURL.match(/:\/\/www\./) && !srcURL.match(/\/gallery/)) { | |
window.location.replace(srcURL.replace(/:\/\/www\./, '://old.').replace(compactTrailMatch, '/.i')); | |
replaceLinks(); | |
} else if (srcURL.match(/:\/\/old\./) && !srcURL.match(/(\/\.i\/?)+$/) && !srcURL.match(/\/over18/)) { | |
window.location.replace(srcURL.replace(compactTrailMatch, '/.i')); | |
replaceLinks(); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment