// ==UserScript== // @name Reddit Multi Column // @namespace https://gist.github.com/c6p/463892bb243f611f2a3cfa4268c6435e // @version 0.1.13 // @description Multi column layout for reddit redesign // @author Can Altıparmak // @homepageURL https://gist.github.com/c6p/463892bb243f611f2a3cfa4268c6435e // @match https://www.reddit.com/* // @grant none // @downloadURL none // ==/UserScript== /* jshint esversion: 6 */ (function() { 'use strict'; const MIN_WIDTH = 400; const COLUMNS = 4; let columns = COLUMNS; let cleanup = false; // https://codepen.io/jpkempf/pen/MbePGB function debounce(fn, wait) { var timeout; return function() { var context = this; var args = arguments; clearTimeout(timeout); timeout = setTimeout(function() { fn.apply(context, args); }, wait); }; } const OUTER = '#SHORTCUT_FOCUSABLE_DIV > div > div > div > div > div:nth-child(2) > div:nth-child(4)' const cardButton = () => document.querySelector('#layoutSwitch--card'); const indexOfSmallest = function (a) { let lowest = 0; for (let i = 1; i makeLayout()); const layoutSwitch = new MutationObserver(setLayout); const watch = function(changes, observer) { const { inner } = select(); if (inner === null) return; layoutSwitch.observe(cardButton(), {attributes: true}); pageChange.observe(inner, {childList: true}); }; const apply = new MutationObserver(watch); const page = document.querySelector('#SHORTCUT_FOCUSABLE_DIV'); apply.observe(page, {childList: true, subtree: true}); watch(); setLayout(); window.requestAnimationFrame(makeLayout); })();