V2EX No Node Specific Styles

Remove node-specific styles on V2EX to keep a unified, clean look.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name                 V2EX No Node Specific Styles
// @name:zh-CN           V2EX 去除节点特性化样式
// @namespace            https://github.com/utags
// @homepageURL          https://github.com/utags/userscripts#readme
// @supportURL           https://github.com/utags/userscripts/issues
// @version              0.1.4
// @description          Remove node-specific styles on V2EX to keep a unified, clean look.
// @description:zh-CN    去除 V2EX 每个节点的特性化样式,保持页面样式统一、简洁。
// @author               Pipecraft
// @license              MIT
// @icon                 https://wsrv.nl/?w=64&h=64&url=https%3A%2F%2Ft3.gstatic.com%2FfaviconV2%3Fclient%3DSOCIAL%26type%3DFAVICON%26fallback_opts%3DTYPE%2CSIZE%2CURL%26url%3Dhttps%3A%2F%2Fwww.v2ex.com%26size%3D64
// @match                https://*.v2ex.com/*
// @match                https://*.v2ex.co/*
// @noframes
// @run-at               document-start
// @grant                none
// ==/UserScript==

;(function () {
  'use strict'

  // Remove all <style> tags under #Rightbar
  function removeRightbarStyles() {
    document.querySelectorAll('#Rightbar style').forEach((el) => el.remove())
  }

  // Try immediately at document-start
  removeRightbarStyles()

  // Observe for #Rightbar creation and future style injections
  const docObserver = new MutationObserver((_, obs) => {
    const rightbar = document.querySelector('#Rightbar')
    if (rightbar) {
      removeRightbarStyles()

      const rbObserver = new MutationObserver((mutations) => {
        for (const m of mutations) {
          m.addedNodes &&
            m.addedNodes.forEach((node) => {
              if (node.nodeType === 1) {
                if (node.matches && node.matches('style')) {
                  node.remove()
                } else if (node.querySelectorAll) {
                  node.querySelectorAll('style').forEach((el) => el.remove())
                }
              }
            })
        }
      })
      rbObserver.observe(rightbar, { childList: true, subtree: true })

      // Stop observing the whole document once #Rightbar is found
      obs.disconnect()
    }
  })
  docObserver.observe(document.documentElement, {
    childList: true,
    subtree: true,
  })

  // Fallback once DOM is ready
  document.addEventListener('DOMContentLoaded', removeRightbarStyles)
})()