Cross Platform Super Dark IDE Theme, R-Studio Server

A recent post over at r-bar.net demonstrated how to use a Windows system utility to achieve a super Dark Rstudio theme.

Super Dark Theme

Well if you liked that post , but are on Linux or OSX or use RStudio Server, then we have a cross platform solution for you!

Rstudio is a web browser, which means it has an index.html page and we can use javascript to change it. And that's what we'll do. You'll need to locate the index.htm file for Rstudio. I did this on linux with locate rstudio | grep www/index.htm.

You'll also need a copy of jquery.min.js. Use your favorite method of file downloading to first place the contents of that jquery link into a the www/js folder, in a file called jquery.min.js.

Next, copy the following code somewhere between the opening and closing html body tags:

<script src="js/jquery.min.js" type="text/javascript"></script>
  
	<script type="text/javascript" language="javascript">
	var isCtrl = false;
	var isShift = false;
	function invert() {
		var css = 'html {-webkit-filter: invert(100%);' +
				'-moz-filter: invert(100%);' + 
				'-o-filter: invert(100%);' + 
				'-ms-filter: invert(100%);}',
 
		head = document.getElementsByTagName('head')[0],
		style = document.createElement('style');
		
		style.type = 'text/css';
		if (style.styleSheet){
			style.styleSheet.cssText = css;
		} else {
			style.appendChild(document.createTextNode(css));
		}
 
		head.appendChild(style);
	};
 
	$(document).ready(function() {
		// action on key up
		$(document).keyup(function(e) {
			if(e.which == 17) {
				isCtrl = false;
			}
			if(e.which == 16) {
				isShift = false;
			}
		});
		// action on key down
		$(document).keydown(function(e) {
			if(e.which == 17) {
				isCtrl = true; 
			}
			if(e.which == 16) {
				isShift = true; 
			}
			if(e.which == 73 && isCtrl && isShift) { 
				invert();
			} 
		});
	});
	</script>

When you next open RStudio, press Ctrl+Shift+I and Rstudio will invert colors. If you use a light theme, RStudio will switch to the so-called "Super Dark Theme".