Skip to content

Instantly share code, notes, and snippets.

@notjuliee
Created May 8, 2017 03:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save notjuliee/c64c95459d376dc216b19fa5d2a9f6ee to your computer and use it in GitHub Desktop.
Save notjuliee/c64c95459d376dc216b19fa5d2a9f6ee to your computer and use it in GitHub Desktop.
No step on CSS
// ==UserScript==
// @name RedaddCSS
// @namespace com.digitalfishfun.nosteponcss
// @version 1
// @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