text: window.loremiscous =
    window.loremiscous ||
    (function() {
      const lorem =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Hoc non est positum in nostra actione. Dat enim intervalla et relaxat. Cupit enim dícere nihil posse ad beatam vitam deesse sapienti. Quasi vero, inquit, perpetua oratio rhetorum solum, non etiam philosophorum sit. Pauca mutat vel plura sane Ne tum quidem te respicies et cogitabis sibi quemque natum esse et suis voluptatibus? Duo Reges constructio interrete. Ergo instituto veterum, quo etiam Stoici utuntur, hinc capiamus exordium.";
      // https://loripsum.net/
      const env = window.chrome || browser;
      var imgs = [...document.querySelectorAll("img")];
      var operations = [];
  
      function addOperation(fn) {
        operations.push(fn);
      }
  
      function replaceImgs() {
        imgs.forEach(i => {
          const width = +i.style.width;
          const height = +i.style.height;
          const lastValue = i.src;
          addOperation(() => (i.src = lastValue));
          if (width) {
            i.src = `https://picsum.photos/${width}/${height}?random`;
          } else {
            i.src = `https://picsum.photos/200?random`;
          }
          //    https://loremflickr.com/320/240
        });
      }
  
      function handleIframes() {
        var iframes = [...document.querySelectorAll("iframe")];
        iframes.forEach(iframe => {
          const lastValue = iframe.style.filter;
          addOperation(() => (iframe.style.filter = lastValue));
          iframe.style.filter = "blur(4px)";
        });
      }
  
      function handleFormInputs() {
        var inputs = [...document.querySelectorAll("input, textarea")];
        inputs.forEach(input => {
          const lastValue = input.value;
          addOperation(() => (input.value = lastValue));
          const inputName = input.name || "";
          if (inputName.match(/(first-name|firstname|first_name)/)) {
            input.value = "John";
          } else if (inputName.match(/(last-name|lastname|last_name)/)) {
            input.value = "Doe";
          } else if (inputName.match(/name/)) {
            input.value = "John Doe";
          } else if (input.type === "email" || inputName.match(/mail/)) {
            input.value = "johndoe@gmail.com";
          } else if (input.type === "tel" || inputName.match(/(phone|mobile)/)) {
            input.value = "0113246327846";
          } else {
            input.value = lorem.substr(0, input.value.length || 20);
          }
        });
      }
  
      function replaceBgImgs() {
        var tags = [...document.querySelectorAll("*")];
        var numTags = tags.length;
        let computedStyles;
        for (var i = 0; i < numTags; i++) {
          const tag = tags[i];
          computedStyles = window.getComputedStyle(tag);
          if (computedStyles.backgroundImage !== "none") {
            const lastValue = computedStyles.backgroundImage;
            addOperation(() => (tag.style.backgroundImage = lastValue));
            tag.style.backgroundImage = "url(https://picsum.photos/200?random)";
          }
        }
      }
  
      function getTextNodesIn(elem, filterFn) {
        var textNodes = [];
        if (elem) {
          for (var nodes = elem.childNodes, i = nodes.length; i--; ) {
            var node = nodes[i],
              nodeType = node.nodeType;
            if (nodeType == 3) {
              if (!filterFn || filterFn(node, elem)) {
                textNodes.push(node);
              }
            } else if (
              node.tagName !== "SCRIPT" &&
              node.tagName !== "STYLE" &&
              (nodeType == 1 || nodeType == 9 || nodeType == 11)
            ) {
              textNodes = textNodes.concat(getTextNodesIn(node, filterFn));
            }
          }
        }
        return textNodes;
      }
  
      function replaceText({ textLengthMultiplier }) {
        var nodes = getTextNodesIn(document.body).filter(n =>
          n.nodeValue.match(/\S/)
        );
        // console.log(nodes.length, nodes[3].nodeValue)
        nodes.forEach(n => {
          const lastValue = n.nodeValue;
          addOperation(() => (n.nodeValue = lastValue));
          // replace numbers with numbers and strings with strings
          n.nodeValue = n.nodeValue.replace(/\s+/g, " ");
          n.nodeValue = n.nodeValue
            // Matches digits, non-whitespace special chacters, underscore or spacers
            .split(/(\d+|[^\w\s]|_|\s)/)
            .map(str => {
              const length = str.length * textLengthMultiplier;
              // If this is just numbers
              if (parseInt(str, 10)) {
                return parseInt(
                  Math.random()
                    .toString()
                    .slice(2, Math.min(length + 2, 18)),
                  10
                );
              } else if (
                str.length === 1 &&
                (str.match(/[^\w]/) || str === "_")
              ) {
                // If single special character or _
                return str;
              } else {
                return lorem
                  .split(" ")
                  .sort(() => (Math.random() > 0.5 ? 1 : -1))
                  .join(" ")
                  .substr(0, length);
              }
            })
            .join("");
        });
      }
  
      function replaceTextWithScribble() {
        const style = document.createElement("style");
        style.textContent = `
  				@font-face {
  					font-family: "Redacted Script";
  					src: url("${env.runtime.getURL("fonts/redacted-script-regular.woff")}");
  				}
  				*,*:after,*:before {
  					font-family: 'Redacted Script'!important;
  				}
  			`;
        document.head.appendChild(style);
        addOperation(() => style.remove());
      }
  
      function undo() {
        operations.forEach(op => op());
        operations = [];
      }
  
      function runLoremiscous(options) {
        if (operations.length) {
          undo();
        } else {
          if (options["replaceText"]) {
            requestIdleCallback(() => {
              replaceText({
                textLengthMultiplier: options["textLengthMultiplier"]
              });
            });
          }
          if (options["replaceTextWithScribble"]) {
            requestIdleCallback(replaceTextWithScribble);
          }
          if (options["replaceImage"]) {
            requestIdleCallback(replaceImgs);
          }
          if (options["replaceBgImage"]) {
            requestIdleCallback(replaceBgImgs);
          }
          if (options["replaceIframe"]) {
            requestIdleCallback(handleIframes);
          }
          // TODO: Replacing form control values can trigger unexpected behavior.
          if (options["replaceInput"]) {
            requestIdleCallback(handleFormInputs);
          }
        }
      }
      return runLoremiscous;
    })();
  
  // window.loremiscous();
  