Open Source Shadow DOM

Ensure all Shadow DOM nodes are open. Includes workarounds for broken functionality due to Shadow DOM restriction. Intented for research use.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Open Source Shadow DOM
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.1.4
// @license      AGPLv3
// @author       jcunews
// @description  Ensure all Shadow DOM nodes are open. Includes workarounds for broken functionality due to Shadow DOM restriction. Intented for research use.
// @match        *://*/*
// @exclude      https://challenges.cloudflare.com/*
// @grant        none
// @inject-into  page
// @run-at       document-start
// ==/UserScript==

(d => {
  //fix document.activeElement not able to get element in Shadow DOM
  var dac = (d = Object.getOwnPropertyDescriptor(Document.prototype, "activeElement")).get;
  d.get = function() {
    var p = dac.call(this), n;
    while (n = p.shadowRoot?.activeElement) p = n;
    return p
  };
  Object.defineProperty(Document.prototype, "activeElement", d);

  //make sure Shadow DOMs are open
  var as = Element.prototype.attachShadow;
  Element.prototype.attachShadow = function(opts) {
    if (!window._cf_chl_opt && !document.querySelector('script[src^="https://challenges.cloudflare.com/"]')) {
      var o = {}, m = opts?.mode, r;
      Array.from(Object.entries(opts)).forEach(a => o[a[0]] = a[1]);
      o.mode = "open";
      opts = o;
      r = as.apply(this, arguments);
      if (m === "closed") {
        Object.defineProperty(r, "realMode", {value: "open"});
        Object.defineProperty(r, "mode", {
          get: () => "closed",
          set: v => v
        })
      }
    } else r = as.apply(this, arguments);
    return r
  };

  //fix event not dispatching if it came from element in Shadow DOM
  var dael = Document.addEventListener;
  Document.addEventListener = function(typ, fn) {
    function f(e) {
      if (e.shadowRoot) {
        e.shadowRoot.addEventListener.apply(e.shadowRoot, arguments);
        e.shadowRoot.querySelectorAll('*').forEach(f)
      }
    }
    document.querySelectorAll('body,body *').forEach(f);
    return dael.apply(this, arguments)
  };
})()