kylepaulsen / ResourceOverride

An extension to help you gain full control of any website by redirecting traffic, replacing, editing, or inserting new content.
MIT License
467 stars 117 forks source link

Feature request: add script/stylesheet from URL #47

Open moqmar opened 3 years ago

moqmar commented 3 years ago

Currently, I can either replace a resource loaded from an URL, or I can add a script or stylesheet from the editor. I would love to add scripts or stylesheets (<script> or <link> tags) from an URL though (so that e.g. CSS @import etc is also working fine), effectively an "Inject resource from URL" rule (as oposed to "Inject File", which might make more sense to call "Inject custom resource" then).

Maybe URLs starting with file:// could be included as plain text again, but otherwise a <script src="SPECIFIED URL"></script> is totally enough.

An alternative would be to allow "File Type: HTML" for "Inject File", so I can add stuff like <script src="..."></script> to the <head>.

A workaround is to add a Inject File with "File Type: JavaScript", with the following content:

[
  { tag: "script", src: "..." },
  { tag: "link", rel: "stylesheet", href: "..." }
].forEach(def => {
  const el = document.createElement(def.tag);
  for (let attr in def) if (attr != "tag") el.setAttribute(attr, def[attr]);
  document.currentScript.parentElement.appendChild(el);
});