更多操作
无编辑摘要 |
无编辑摘要 |
||
第14行: | 第14行: | ||
//添加到下一章节的按钮 | //添加到下一章节的按钮 | ||
//找到列表中的位置 | //找到列表中的位置 | ||
function findListIndex(list,item){ | function findListIndex(list,item){ |
2023年6月21日 (三) 01:01的版本
/*<%-- [PAGE_INFO]
comment = #Please do not remove this struct. It's record contains some important information of edit. This struct will be removed automatically after you push edits.#
pageTitle = #MediaWiki:Gadget-tikuShuaTi.js#
pageID = #3486#
revisionID = #68607#
contentModel = #javascript#
contentFormat = #text/javascript#
[END_PAGE_INFO] --%>*/
// 添加刷题按钮
var title = $('#immerse_button').children('p').text()
$('<button class="button" onclick="window.open(\'https://www.medforest.cn/tools/tiku?title='+title+'\')">进入做题页面</button>').appendTo($('#immerse_button'))
//添加到下一章节的按钮
//找到列表中的位置
function findListIndex(list,item){
for(var i=0;i<list.length;i++){
if(list[i]===item){
return i
}
}
}
//
function getIndexPageWikiTextAndInsertButton(indexTitle,currentPageTitle){
var api = new mw.Api();
api.get( {
"action": "query",
"format": "json",
"prop": "revisions",
"titles": indexTitle,
"utf8": 1,
"rvprop": "content",
"rvlimit": 1,
"rvslots": "*",
"rvdir": "older"
} ).done( function ( data ) {
console.log( data );
var pages = data.query.pages
var text = ''
if(pages['-1'] === undefined){
for(var key in pages){
text = pages[key]['revisions'][0]['slots']['main']['*']
}
}
console.log(text)
var indexPageNames = getIndexPageName(text)
var id = findListIndex(indexPageNames,'题库:'+currentPageTitle)
var lastPageID = (id-1) < 0 ? 0 : id-1
var nextPageID = (id+1) > indexPageNames.length-1 ? indexPageNames.length-1 : id+1
var lastPageName = indexPageNames[lastPageID] === undefined ? '无上一章节' : indexPageNames[lastPageID]
var shortLast= lastPageName
if(lastPageName.split('/').length>1){
shortLast = lastPageName.split('/')[lastPageName.split('/').length-1]
}
var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID]
var shortNext = nextPageName
if(nextPageName.split('/').length>1){
shortNext = nextPageName.split('/')[nextPageName.split('/').length-1]
}
var lastBtn = new OO.ui.ButtonWidget( {
framed: false,
flags: [
'progressive'
],
label: '<上一章节:'+shortLast,
href: 'https://www.medforest.cn/dic/'+lastPageName,
rel: '',
disabled: lastPageName==='无上一章节'
} )
var nextBtn = new OO.ui.ButtonWidget( {
framed: false,
flags: [
'progressive'
],
label: '下一章节:'+shortNext+'>',
href: 'https://www.medforest.cn/dic/'+nextPageName,
rel: '',
disabled: nextPageName==='无下一章节'
} )
var group = $('<div></div>').append(lastBtn.$element, '|', nextBtn.$element)
group.prependTo($('.mw-parser-output'))
} );
}
//解析目录项
//** {{目录项|题库:诊断学学习指导与习题集(第4版)/第一篇/第一节|第一节 发热}}
function getIndexPageName(text){
console.log(text)
var pageList = []
text = text.split('{{目录项|')
if(text.length>1){
for(var i=1;i<text.length;i++){
pageList.push(text[i].split('|')[0])
}
}
console.log(pageList)
return pageList
}