Vue Loader

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Vue Loader
// @namespace    https://github.com/SaiCode-DEV
// @version      1.0.0
// @description  Loads Vue.js into the current page if it is not already loaded.
// @author       SaiCode
// @include       /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
// @grant        GM_xmlhttpRequest
// ==/UserScript==

/* global $ */
/* jshint esversion:6 */

(function main() {
  "use strict";

  const VUE_URL = "https://unpkg.com/vue@3/dist/vue.global.js";

  async function init() {
    const sandboxed = typeof unsafeWindow !== "undefined";
    const pageWindow = sandboxed ? unsafeWindow : window;

    // Check if Vue is already loaded
    if (typeof pageWindow.Vue !== "undefined") {
      console.log("Vue.js is already loaded.");
      return;
    }

    console.log("Loading Vue.js...");
    await new Promise((resolve, reject) => {
      $.getScript(VUE_URL)
        .done(() => {
          console.log("Vue.js has been successfully loaded.");
          resolve();
        })
        .fail((jqxhr, settings, exception) => {
          console.error("Failed to load Vue.js:", exception);
          reject(exception);
        });
    });

    if (typeof pageWindow.Vue !== "undefined") {
      console.log("Vue.js has been loaded successfully.");
    } else {
      console.error("Error loading Vue.js.");
    }
  }

  function bootstrap(tries = 1) {
    if (typeof $ !== "undefined") {
      init();
    } else if (tries < 100) {
      setTimeout(() => bootstrap(tries + 1), 100);
    } else {
      console.error("Vue Loader could not be initialized.");
    }
  }

  bootstrap();
})();