// ==UserScript== // @name Reddit Multi Column // @namespace https://gist.github.com/c6p/463892bb243f611f2a3cfa4268c6435e // @version 0.2.3 // @description Multi column layout for reddit redesign // @author Can Altıparmak // @homepageURL https://gist.github.com/c6p/463892bb243f611f2a3cfa4268c6435e // @match https://www.reddit.com/* // @match https://new.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 = null; let parent = null; const cardIcon = () => document?.querySelector('shreddit-sort-dropdown[header-text="View"]')?.shadowRoot?.querySelector('svg'); const shouldClean =(icon) => icon === undefined ? false : icon.getAttribute('icon-name') !== "view-card-outline"; cleanup = shouldClean() let postMap = new Map() const indexOfSmallest = function (a) { let lowest = 0; for (let i = 1; i height + c.clientHeight, 0) + "px" } } }; const setLayout = function(changes, observer) { const c = shouldClean(cardIcon()); if (c !== cleanup) { cleanup = c; window.requestAnimationFrame(makeLayout) } }; const requestLayout = () => window.requestAnimationFrame(makeLayout) const pageChange = new MutationObserver(requestLayout); window.addEventListener('resize', requestLayout); window.addEventListener('scrollend', requestLayout); const layoutSwitch = new MutationObserver(setLayout); const watch = function(changes, observer) { postMap = new Map() parent = document.querySelector("article + hr + faceplate-partial").parentNode if (parent === null) return; pageChange.observe(parent, {childList: true}); const timeout = setTimeout(() => { const icon = cardIcon(); if (icon !== undefined) { clearTimeout(timeout); layoutSwitch.observe(icon, {attributes: true}); } }) window.requestAnimationFrame(makeLayout); }; const apply = new MutationObserver(watch); const app = document.querySelector("shreddit-app") apply.observe(app, {attributes: true}); watch(); })();