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

Add new rule: Add JS/CSS file From URL #62

Open Ronald-Diemicke opened 1 year ago

Ronald-Diemicke commented 1 year ago

So - I recently realized I could use a feature where I could actually give RO a URL and have it add it to the page as a new script file or CSS file - so I could test a script I've got hosted elsewhere on a page BEFORE I commit to adding it...

KevynTD commented 7 months ago

I was thinking the same thing. You can do it the following way, but it's not that practical, having an UI would make it a lot easier to edit.

// Bite code from https://stackoverflow.com/a/950146/6227108
function dynamicallyLoadScript(url) {
    var script = document.createElement("script");  // create a script DOM node
    script.src = url;  // set its src to the provided URL

    document.head.appendChild(script);  // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}

// example
dynamicallyLoadScript('https://cdn.jsdelivr.net/momentjs/2.17.1/moment.min.js')

It would be nice to select if it is type="module" in the options too