Load external script

Tool to let you load external scripts

Ce script ne devrait pas être installé directement. C'est une librairie créée pour d'autres scripts. Elle doit être inclus avec la commande // @require https://update.greatest.deepsurf.us/scripts/33853/222461/Load%20external%20script.js

  1. // ==UserScript==
  2. // @name Load external script
  3. // @description Tool to let you load external scripts
  4. // @version 1
  5. // @author A Meaty Alt
  6. // @grant none
  7. // ==/UserScript==
  8.  
  9. function loadScript(scriptURL) {
  10. 'use strict';
  11. function httpGetAsync(theUrl, callback) {
  12. var xmlHttp = new XMLHttpRequest();
  13. xmlHttp.onreadystatechange = function() {
  14. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  15. callback(xmlHttp.responseText);
  16. }
  17. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  18. xmlHttp.send(null);
  19. }
  20. return new Promise(function(resolve){
  21. httpGetAsync(scriptURL, function(response){
  22. var s = document.createElement("script");
  23. s.text = response;
  24. document.getElementsByTagName("head")[0].appendChild(s);
  25. resolve();
  26. });
  27. });
  28.  
  29. }