Widget:CCB-auto:修订间差异
更多操作
![]() OctoberSama(留言 | 贡献) 小 |
![]() OctoberSama(留言 | 贡献) 小 |
||
第1行: | 第1行: | ||
<script> | <script> | ||
(function waitForGadgetAndRun() { | |||
// 等待 mw 和 loader 初始化 | |||
if (typeof mw === 'undefined' || !mw.loader?.using || !mw.loader?.getState) { | |||
return setTimeout(waitForGadgetAndRun, 50); | |||
} | |||
const gadgetName = 'ext.gadget.CaoCaoBi'; | |||
// if (state === ' | const state = mw.loader.getState(gadgetName); | ||
// // 已加载完成,可以执行 | |||
if (state === 'registered') { | |||
// 如果还只是 registered,就主动触发加载 | |||
mw.loader.load(gadgetName); | |||
return setTimeout(waitForGadgetAndRun, 50); | |||
} | |||
if (state === 'loading' || state === 'loaded') { | |||
// 还在加载中,再等一等 | |||
return setTimeout(waitForGadgetAndRun, 50); | |||
} | |||
if (state === 'ready') { | |||
// 已加载完成,可以执行 | |||
if (typeof swit_so_CCB === 'function') { | |||
// swit_so_CCB(); | // swit_so_CCB(); | ||
CCB_button(); | |||
} else { | |||
console.warn('swit_so_CCB 仍未定义(函数未注册到 window?)'); | |||
} | |||
return; | |||
// | |||
// 不可识别状态,继续等 | |||
setTime、、ut(waitForGadgetAndRun, 50); | |||
function CCB_button() { | |||
window.swit_so_CCB(); | |||
console.log("按钮触发"); | |||
} | |||
、})(); | |||
</script> | </script> | ||
<span id="CCB_button" class="oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-iconElement oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget" onclick=" | <span id="CCB_button" class="oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-iconElement oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget" onclick="CCB_button()"> | ||
<span class="oo-ui-buttonElement-button" role="button"> | <span class="oo-ui-buttonElement-button" role="button"> | ||
<span class="oo-ui-iconElement-icon oo-ui-icon-search oo-ui-image-progressive"></span> | <span class="oo-ui-iconElement-icon oo-ui-icon-search oo-ui-image-progressive"></span> |
2025年6月11日 (三) 17:39的版本
<script> (function waitForGadgetAndRun() { // 等待 mw 和 loader 初始化 if (typeof mw === 'undefined' || !mw.loader?.using || !mw.loader?.getState) { return setTimeout(waitForGadgetAndRun, 50); }
const gadgetName = 'ext.gadget.CaoCaoBi';
const state = mw.loader.getState(gadgetName);
if (state === 'registered') { // 如果还只是 registered,就主动触发加载 mw.loader.load(gadgetName); return setTimeout(waitForGadgetAndRun, 50); } if (state === 'loading' || state === 'loaded') { // 还在加载中,再等一等 return setTimeout(waitForGadgetAndRun, 50); } if (state === 'ready') { // 已加载完成,可以执行 if (typeof swit_so_CCB === 'function') { // swit_so_CCB(); CCB_button(); } else { console.warn('swit_so_CCB 仍未定义(函数未注册到 window?)'); } return; // // 不可识别状态,继续等 setTime、、ut(waitForGadgetAndRun, 50);
function CCB_button() { window.swit_so_CCB(); console.log("按钮触发"); }
、})();
</script>