Wide New Reddit (Dynamic)

Make new reddit layout fill screen width. Obtain class names dynamically to avoid breaks. 28/02/2023, 4:05:40 pm

目前為 2023-02-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Wide New Reddit (Dynamic)
// @namespace   Violentmonkey Scripts
// @match       *://www.reddit.com/*
// @match       *://new.reddit.com/*
// @grant       none
// @version     1.0
// @author      Hou Rui
// @license     GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @icon        https://www.redditstatic.com/desktop2x/img/favicon/favicon-96x96.png
// @description Make new reddit layout fill screen width. Obtain class names dynamically to avoid breaks. 28/02/2023, 4:05:40 pm
// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

// inject styles
function makeElementWide(element) {
  const className = element.className.split(' ')[0];
  console.info("CLASSNAME: " + className);
  addGlobalStyle(`div.${className} { max-width: none !important; width: 100% !important; }`)
  // element.style.maxWidth = 'none';
  // element.style.width = '100%';
}


// for front page
function makeFrontPageWide() {
  const newPostInput = document.querySelector("input[name='createPost']");
  if (newPostInput === null) { return; }
  if (newPostInput.parentElement === null) { return; }
  let leftColumn = newPostInput.parentElement.parentElement;
  if (leftColumn === null) { return; }
  makeElementWide(leftColumn);
}


// for post page
function makePostPageWide() {
  const postContainer = document.querySelector("div[data-testid='post-container']");
  if (postContainer === null) { return; }
  let leftColumn = postContainer.parentElement;
	if (leftColumn === null) { return; }
  makeElementWide(leftColumn);
  makeElementWide(leftColumn.parentElement);
}

makeFrontPageWide();
makePostPageWide();