-
-
Save ExE-Boss/b80548c8994cfb4faf75cda77dfff437 to your computer and use it in GitHub Desktop.
No step on CSS
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 RedaddCSS | |
// @namespace com.digitalfishfun.nosteponcss | |
// @version 1 | |
// @description Allows subreddits to add CSS through an unofficial method. | |
// @grant none | |
// @include https://reddit.com/r/* | |
// ==/UserScript== | |
const nosteponcss_instructions = ` | |
USAGE: | |
To use this script, the subreddit you are on MUST have a wiki paged named "css" in the root. | |
The page MUST begin with | |
/* @CSS */ | |
and the rest of the page being the CSS you wish to inject.`; | |
console.log('RedaddCSS loading...'); | |
let nosteponcss_css; | |
let nosteponcss_subreddit = window.location.pathname.split('/')[2]; | |
let nosteponcss_main = () => { | |
console.log('Checking https://www.reddit.com/r/' + nosteponcss_subreddit + '/wiki/css.json for custom CSS'); | |
$.get('https://www.reddit.com/r/' + nosteponcss_subreddit + '/wiki/css.json', data => { | |
let nosteponcss_css = data.data.content_md.replace(/\r/g, '').replace(/ /g, ''); | |
if (nosteponcss_css.split('\n') [0] != '/*@CSS*/') return console.log('CSS is not in valid format :/'); | |
console.log('CSS loaded!'); | |
$('head').append('<style id="nosteponcss_style">' + nosteponcss_css + '</style>'); | |
console.log('Done injecting custom CSS!'); | |
console.log('Checking for RES'); | |
if ($("#res-style-checkbox").prop("checked") != undefined) { | |
console.log('RES Detected, loading listener for CSS toggle.'); | |
if (!$("#res-style-checkbox").prop("checked")) { | |
$("#nosteponcss_style").remove(); | |
console.log("CSS is disabled, removing."); | |
} | |
$("#res-style-checkbox").change(() => { | |
if ($("#res-style-checkbox").prop("checked")) { | |
$('head').append('<style id="nosteponcss_style">' + nosteponcss_css + '</style>'); | |
return console.log("Enabled CSS"); | |
} | |
$("#nosteponcss_style").remove(); | |
return console.log("Disabled CSS"); | |
}) | |
} | |
}); | |
} | |
nosteponcss_main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment