Skip to content

Instantly share code, notes, and snippets.

@EduApps-CDG
Last active December 15, 2019 13:13
Show Gist options
  • Save EduApps-CDG/1546229bca45528a36b55ecd99f9a2c3 to your computer and use it in GitHub Desktop.
Save EduApps-CDG/1546229bca45528a36b55ecd99f9a2c3 to your computer and use it in GitHub Desktop.
A <script> linker made in JavaScript.
/**
* Copyright 2019 EduApps (Eduardo P. Gomez)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Importer = {
help: function() {
console.log("Importer.js V1.0.0 by EduApps\n<> - needed variable.\n[] - not needed variable.\n\ncommands:\n help - show this help message()\n imports - import a script/module(<url>,[onAppend],[type])");
},
imports: function(url, onAppend, type) {
if (type === null) {
type = "text/javascript";
}
var script = document.createElement("script");
script.src = url;
script.type = type;
document.body.appendChild(script);
if (onAppend !== null) {
onAppend();
}
return script;
}
}
/**
* Copyright 2019 EduApps (Eduardo P. Gomez)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Importer={help:function(){console.log("Importer.js V1.0.0 by EduApps\n<> - needed variable.\n[] - not needed variable.\n\ncommands:\n help - show this help message()\n imports - import a script/module(<url>,[onAppend],[type])")},imports:function(e,n,t){null===t&&(t="text/javascript");var p=document.createElement("script");return p.src=e,p.type=t,document.body.appendChild(p),null!==n&&n(),p}};
@EduApps-CDG
Copy link
Author

EduApps-CDG commented Dec 15, 2019

How to use:

Simple:

Importer.imports("my/url.js");

More complex:

var mycode = Importer.imports("my/url.js", function() {
    alert("path: " mycode.src + "\nmime: " + mycode.type);
}, "text/javascript+module");

still need help? try execute Importer.help() on the JavaScript Console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment