Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add script/stylesheet from URL #47

Open
moqmar opened this issue Mar 21, 2021 · 0 comments
Open

Feature request: add script/stylesheet from URL #47

moqmar opened this issue Mar 21, 2021 · 0 comments

Comments

@moqmar
Copy link

moqmar commented Mar 21, 2021

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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant