MediaWiki:EmbedExternalPage.js
MediaWiki界面页面
更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/**
* 嵌入Easecation服务页面 - 修复版
* 解决DOM加载时机、协议拦截、容错问题
*/
( function () {
'use strict';
// 修复:用 mw.hook 监听 MediaWiki 页面内容加载完成(比 DOMContentLoaded 更适配 Wiki)
mw.hook('wikipage.content').add(function($content) {
// 从页面内容中查找容器(兼容动态加载)
const container = $content.find('#easecation-service-container')[0] || document.getElementById('easecation-service-container');
if (!container) {
console.log('未找到嵌入容器 #easecation-service-container');
return;
}
// 修复:优先用 HTTPS(如果目标网站支持),避免混合内容拦截
const iframeSrc = 'https://service.wiki.easecation.net/' || 'http://service.wiki.easecation.net/';
// 创建iframe
const iframe = document.createElement('iframe');
iframe.id = 'easecation-service-iframe';
iframe.src = iframeSrc;
iframe.width = '100%';
iframe.height = '800px';
iframe.frameBorder = '0';
iframe.scrolling = 'auto';
iframe.sandbox = 'allow-scripts allow-same-origin allow-forms';
iframe.referrerPolicy = 'no-referrer-when-downgrade';
// 修复:允许混合内容(仅当 Wiki 是 HTTPS 但目标是 HTTP 时临时用)
iframe.allow = 'mixed-content';
// 清空容器避免重复
container.innerHTML = '';
container.appendChild(iframe);
// 加载状态处理
iframe.onload = function () {
console.log('Easecation服务页面加载完成');
};
iframe.onerror = function () {
container.innerHTML = `
`;
console.error('iframe加载失败:', iframeSrc);
};
});
}() );