|
|
第1行: |
第1行: |
| <includeonly><span id="CCB_button" class="mw-ui-button mw-ui-progressive"> | | <includeonly><span id="CCB_button" class="mw-ui-button mw-ui-progressive"> |
| <span id="ccb-click-target"> | | <span onclick="swit_so_CCB();"> |
| <img src="/images/5/5b/%E5%A4%A7%E7%99%BD%E8%B1%A1.webp" style="width:1em"> | | <img src="/images/5/5b/%E5%A4%A7%E7%99%BD%E8%B1%A1.webp" style="width:1em"> |
| <span>点我CCB!!</span> | | <span>点我CCB!!</span> |
| </span> | | </span> |
| </span> | | </span></includeonly><noinclude>{{doc|content=注意:widget不应该在条目中直接使用!请使用{{tl|CCB-button}}。}}</noinclude> |
| | |
| <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') {
| |
| (function loadCCBModule() {
| |
| if (!window.mw?.loader) return setTimeout(loadCCBModule, 50);
| |
| | |
| mw.loader.using('ext.gadget.CaoCaoBi').then((ccb) => {
| |
| const el = document.getElementById("ccb-click-target");
| |
| if (el && typeof ccb.swit_so_CCB === "function") {
| |
| el.addEventListener("click", (e) => {
| |
| e.preventDefault();
| |
| ccb.swit_so_CCB();
| |
| });
| |
| }
| |
| });
| |
| })();
| |
| } else {
| |
| console.warn('swit_so_CCB 仍未定义(函数未注册到 window?)');
| |
| }
| |
| return;
| |
|
| |
| </script></includeonly><noinclude>{{doc|content=注意:widget不应该在条目中直接使用!请使用{{tl|CCB-button}}。}}</noinclude>
| |