Greasy Fork is available in English.
在window全局变量中添加__wxjs_environment属性,支持自定义值
// ==UserScript==
// @name 注入微信JS环境变量
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 在window全局变量中添加__wxjs_environment属性,支持自定义值
// @author You
// @match https://staging-platform.developer.miui.com/*
// @match *://onebox.developer.mi.com/*
// @grant none
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 配置参数 - 可以在这里修改环境值
const config = {
environmentValue: 'miniprogram', // 可选值: 'miniprogram', 'browser' 等
writable: true, // 是否可写
configurable: true, // 是否可配置
enumerable: true // 是否可枚举
};
// 删除已存在的属性(如果有)
if (window.hasOwnProperty('__wxjs_environment')) {
delete window.__wxjs_environment;
}
// 添加属性
Object.defineProperty(window, '__wxjs_environment', {
value: config.environmentValue,
writable: config.writable,
configurable: config.configurable,
enumerable: config.enumerable
});
console.log('[debug] __wxjs_environment 已注入:', window.__wxjs_environment);
})();