🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/23 11:27:29
🔄 下次更新时间:2026/01/23 12:27:29
手动刷新缓存

WME Utils - Bootstrap

Adds a bootstrap function for easier startup of wmeSdk, WazeWrap, and ScriptUpdateMonitor.

Dette script bør ikke installeres direkte. Det er et bibliotek, som andre scripts kan inkludere med metadirektivet // @require https://update.greasyfork.org/scripts/509664/1461898/WME%20Utils%20-%20Bootstrap.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         WME Utils - Bootstrap
// @namespace    WazeDev
// @version      2024.10.09.000
// @description  Adds a bootstrap function for easier startup of wmeSdk, WazeWrap, and ScriptUpdateMonitor.
// @author       MapOMatic, WazeDev group
// @include      /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
// @license      GNU GPLv3
// ==/UserScript==

/* global WazeWrap */
/* global getWmeSdk */
/* global SDK_INITIALIZED */

// Using var here to allow scripts to override with their own bootstrap, if needed,
// without having to remove the @require line for this code.

// eslint-disable-next-line no-unused-vars, func-names, no-var
var bootstrap = (function() {
    'use strict';

    let wmeSdk;

    function wmeReady(scriptName, scriptId) {
        wmeSdk = getWmeSdk({ scriptName, scriptId });
        return new Promise(resolve => {
            if (wmeSdk.State.isReady()) resolve();
            wmeSdk.Events.once({ eventName: 'wme-ready' }).then(resolve);
        });
    }

    function wazeWrapReady(scriptName) {
        return new Promise(resolve => {
            (function checkWazeWrapReady(tries = 0) {
                if (WazeWrap.Ready) {
                    resolve();
                } else if (tries < 1000) {
                    setTimeout(checkWazeWrapReady, 200, ++tries);
                } else {
                    console.error(`${scriptName}: WazeWrap took too long to load.`);
                }
            })();
        });
    }

    function loadScriptUpdateMonitor(args) {
        let updateMonitor;
        try {
            if (typeof GM_xmlhttpRequest === 'undefined') {
                throw new Error('GM_xmlhttpRequest is required to use WazeWrap.Alerts.ScriptUpdateMonitor');
            }
            updateMonitor = new WazeWrap.Alerts.ScriptUpdateMonitor(
                args.scriptName,
                args.scriptUpdateMonitor.scriptVersion,
                args.scriptUpdateMonitor.downloadUrl,
                GM_xmlhttpRequest,
                args.scriptUpdateMonitor.metaUrl,
                args.scriptUpdateMonitor.metaRegExp
            );
            updateMonitor.start();
        } catch (ex) {
            // Report, but don't stop if ScriptUpdateMonitor fails.
            console.error(`${args.scriptName}:`, ex);
        }
    }

    async function bootstrapFunc(args) {
        args = { ...args };
        args.scriptName ??= GM_info.script.name;
        args.scriptId ??= GM_info.script.name.replaceAll(' ', '');
        await SDK_INITIALIZED;
        await wmeReady(args.scriptName, args.scriptId);
        if (args.useWazeWrap || args.scriptUpdateMonitor) await wazeWrapReady(args);
        if (args.scriptUpdateMonitor) {
            args.scriptUpdateMonitor.scriptVersion ??= GM_info.script.version;
            loadScriptUpdateMonitor(args);
        }
        args.callback?.(wmeSdk);
        return wmeSdk;
    }

    return bootstrapFunc;
})();