Vue Loader

Loads Vue.js into the current page if it is not already loaded.

  1. // ==UserScript==
  2. // @name Vue Loader
  3. // @namespace https://github.com/SaiCode-DEV
  4. // @version 1.0.0
  5. // @description Loads Vue.js into the current page if it is not already loaded.
  6. // @author SaiCode
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. /* global $ */
  12. /* jshint esversion:6 */
  13.  
  14. (function main() {
  15. "use strict";
  16.  
  17. const VUE_URL = "https://unpkg.com/vue@3/dist/vue.global.js";
  18.  
  19. async function init() {
  20. const sandboxed = typeof unsafeWindow !== "undefined";
  21. const pageWindow = sandboxed ? unsafeWindow : window;
  22.  
  23. // Check if Vue is already loaded
  24. if (typeof pageWindow.Vue !== "undefined") {
  25. console.log("Vue.js is already loaded.");
  26. return;
  27. }
  28.  
  29. console.log("Loading Vue.js...");
  30. await new Promise((resolve, reject) => {
  31. $.getScript(VUE_URL)
  32. .done(() => {
  33. console.log("Vue.js has been successfully loaded.");
  34. resolve();
  35. })
  36. .fail((jqxhr, settings, exception) => {
  37. console.error("Failed to load Vue.js:", exception);
  38. reject(exception);
  39. });
  40. });
  41.  
  42. if (typeof pageWindow.Vue !== "undefined") {
  43. console.log("Vue.js has been loaded successfully.");
  44. } else {
  45. console.error("Error loading Vue.js.");
  46. }
  47. }
  48.  
  49. function bootstrap(tries = 1) {
  50. if (typeof $ !== "undefined") {
  51. init();
  52. } else if (tries < 100) {
  53. setTimeout(() => bootstrap(tries + 1), 100);
  54. } else {
  55. console.error("Vue Loader could not be initialized.");
  56. }
  57. }
  58.  
  59. bootstrap();
  60. })();