Widget:模板调用
<script type="text/javascript"> (window.RLQ = window.RLQ || []).push(['jquery', () => { $(function(){ console.log('模板调用ing......'); // 点击触发右侧页面调用 var liArr = $(".left-container .selection-li"); bindClickTrigger(); getPageContent(liArr[0]);
function bindClickTrigger(){
$.each(liArr, function (index,item) {
item.addEventListener("click", function(event){ getPageContent(event.target) });
})
}
function getPageContent(event){
let pageName = "" + "/短信/"+ event.getAttribute('data-param');
$.get(`https://wiki.biligame.com/lysk/api.php`,
{
action:"parse",
format:"json",
page:pageName,
prop:"text|headitems",
},
function (res) {
let data = res.parse.text['*'];
//console.log(data);
$('.messages-list>.right-container')[0].innerHTML = data;
// 处理链接跳转问题
let tempA = $(".right-container .MessageName a")[0];
if(tempA){
tempA.removeAttribute('class');
tempA.setAttribute('href', "/lysk/" + pageName);
}
// 处理选项切换问题
handleSwitch();
dTab();
}
)
}
//loadAndShowWikiContent();
// 加载模板
function loadAndShowWikiContent(roleName) {
var wikiContent = document.getElementById("content-area");
wikiContent.innerHTML = "";
// 调用MediaWiki的API获取wiki内容
var api = new mw.Api();
// 调用api.get方法,传入action, text参数,请求解析文本
api.get({
action: "parse",
text: `
}`,
}).then(function (ret) {
if (ret && ret.parse && ret.parse.text) {
wikiContent.innerHTML = ret.parse.text['*'];
// 加载短信内容功能所需js
if (!window.jsLoad) {
mw.loader.load("https://wiki.biligame.com/lysk/index.php?title=MediaWiki:朋友圈选项.js&action=raw&ctype=text/javascript", "text/javascript");
handleSwitch();
setTimeout(jsLoad,1000);
}
}
else wikiContent.innerHTML += "
加载内容失败:" + ret + "
";
});
}
function handleSwitch(){ // 获取所有的SwitchContainer const switchContainers = document.querySelectorAll('.SwitchContainer'); // 为所有SwitchContainer添加点击事件监听 switchContainers.forEach(container => {
// 监听点击事件
container.addEventListener('click', function (e) {
// 检查点击的是否为按钮
if (e.target.classList.contains('btn')) {
// 阻止事件冒泡
e.stopPropagation();
// 获取当前SwitchContainer内的按钮和内容
const buttons = container.querySelector('.BtnContainer').children;
const contents = container.querySelector('.BtnContent').children;
// 获取点击的按钮的索引
const index = Array.from(buttons).indexOf(e.target);
// 切换激活状态
toggleActiveState(buttons, contents, index);
}
});
}); } function dTab() {
document.querySelectorAll(".d-tab-titles .d-tab-title").forEach((tab, i) => {
tab.addEventListener("click", () => {
// 找到当前 tab 所在的标题列表
const titleListContainer = tab.closest(".d-tab-titles");
//console.log(titleListContainer)
if (!titleListContainer) return;
const titleList = Array.from(titleListContainer.querySelectorAll(".d-tab-title"));
// 找到对应的 .d-tab 容器和内容列表
const tabsContainer = titleListContainer.closest(".d-tab");
const tabContents = Array.from(
tabsContainer.querySelectorAll(":scope > .d-tab-contents > .tab-content")
);
// 如果只有一个 tab,直接切换 active 类
if (titleList.length === 1) {
if (titleList[0].classList.contains("active")) {
titleList[0].classList.remove("active");
tabContents[0].classList.remove("active");
tabContents[0].classList.add("hidden");
}else {
titleList[0].classList.add("active");
tabContents[0].classList.add("active");
tabContents[0].classList.remove("hidden");
}
return;
}
// 移除其他 tab 的 active 类
titleList.forEach((t) => t.classList.remove("active"));
tab.classList.add("active");
// 获取当前 tab 的索引
const index = titleList.indexOf(tab);
// 关闭所有 tab 内容
tabContents.forEach((content) => content.classList.remove("active"));
tabContents.forEach((content) => content.classList.add("hidden"));
// 打开对应索引的 tab 内容
if (tabContents[index]) {
tabContents[index].classList.remove("hidden");
tabContents[index].classList.add("active");
}
});
});
}
function toggleActiveState(buttons, contents, index) {
// 检查当前内容是否已经显示
const isActive = contents[index].classList.contains('active');
// 如果已经激活(显示),则移除激活(隐藏)状态
if (isActive) {
//buttons[index].classList.remove('active');
//contents[index].classList.remove('active');
} else {
// 否则,先移除所有按钮和内容的active类
Array.from(buttons).forEach(button => button.classList.remove('active'));
Array.from(contents).forEach(content => content.classList.remove('active'));
// 然后为被点击的按钮添加active类,并显示对应的内容
buttons[index].classList.add('active');
contents[index].classList.add('active');
}
} }); }]); </script>

沪公网安备 31011002002714 号