Skip to content

Instantly share code, notes, and snippets.

@fartwhif
Last active July 26, 2018 15:00
Show Gist options
  • Save fartwhif/83b7e353a3bab6a178a9 to your computer and use it in GitHub Desktop.
Save fartwhif/83b7e353a3bab6a178a9 to your computer and use it in GitHub Desktop.
Sanereddit will remove the sidebar/bloatbar on the right, and expand the linklist and comments to the appropriate width, allowing reddit to be used in a sane manner.
// ==UserScript==
// @name sanereddit
// @namespace sanereddit
// @version 1.5
// @grant none
// @license MIT
// @description Sanereddit will remove tons of bloat, allowing reddit to be used in a sane manner.
// ==/UserScript==
(function() {
function getScrollbarWidth() {
var outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
// force scrollbars
outer.style.overflow = "scroll";
// add innerdiv
var inner = document.createElement("div");
inner.style.width = "100%";
outer.appendChild(inner);
var widthWithScroll = inner.offsetWidth;
// remove divs
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
}
$(function() {
var sbWidth = getScrollbarWidth();
var sideBar = document.getElementsByClassName('side') [0];
var linkList = document.getElementsByClassName('linklisting') [0];
var commentarea = document.getElementsByClassName('commentarea')[0];
var comments = document.getElementsByClassName('comment');
var mds = document.getElementsByClassName('md');
var root= document.compatMode=='BackCompat'? document.body : document.documentElement;
function go() {
$("a.title").css('fontSize','small');
$("div.thing").css('marginBottom', '0px');
$("div.footer-parent").hide();
$("div.content").css("marginTop","0px");
sideBar.style.display = 'none';
linkList.style.width = (root.clientWidth - sbWidth) + 'px';
if (commentarea !== undefined){
commentarea.style.width= (root.clientWidth - sbWidth) + 'px';//'100%';
}
var i = 0;
for (i = 0; i < comments.length; i++) {
comments[i].style.width = '100%';
}
for (i = 0; i < mds.length; i++) {
var elem = mds[i];
var marginRight = 0;
var depth = $(elem).parentsUntil("div.commentarea").filter('div.thing').length;
elem.parentElement.style.width = (root.clientWidth - sbWidth - (depth * 31)) + 'px';
elem.style.maxWidth = '100%';
}
}
// Attach it the resize event
window.addEventListener('resize', function (event) {
go();
});
// Run it once initially
go();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment