Skip to content

Instantly share code, notes, and snippets.

@sourcevault
Last active February 15, 2024 08:01

Revisions

  1. sourcevault renamed this gist Feb 15, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. sourcevault created this gist Feb 15, 2024.
    52 changes: 52 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    // ==UserScript==
    // @name reddit sidebar_hide 445502
    // @version 1
    // @grant none
    // ==/UserScript==

    // Reddit Sidebar Toggle.
    // Created by Dylan Araps.


    function toggle_post(value) {
    // Remove margin on individual posts.
    // Fixes issues on /r/outoftheloop
    var posts = document.getElementsByClassName("thing");

    for (var i=0; i<posts.length; i++) {
    posts[i].style.marginRight = value;
    }
    }


    function main() {
    var sidebar = document.getElementsByClassName("side")[0];
    var content = document.querySelector("[role=\"main\"]");

    if (sidebar) {
    var display = sidebar.style.display;

    if (display != "none") {
    sidebar.style.display = "none";
    toggle_post("15px");

    // !important needs to be used here since this class
    // can't be overidden otherwise.
    content.style.cssText = `margin-top: 20px !important;
    margin-right: 15px !important;
    padding-top: 0px !important`;
    content.style.border = "none";

    } else {
    // Reset styles.
    sidebar.style.display = null;
    content.style.border = null;
    content.style.margin = null;
    content.style.padding = null;
    toggle_post(null);
    }
    }
    }


    main();