Open Source Shadow DOM

Ensure all Shadow DOM nodes are open. Intented for research use.

// ==UserScript==
// @name         Open Source Shadow DOM
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.0.1
// @license      AGPLv3
// @author       jcunews
// @description  Ensure all Shadow DOM nodes are open. Intented for research use.
// @match        *://*/*
// @grant        none
// @inject-into  page
// @run-at       document-start
// ==/UserScript==

(() => {
  var as = Element.prototype.attachShadow;
  Element.prototype.attachShadow = function(opts) {
    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
      })
    }
    return r
  };
})()