更多操作
无编辑摘要 |
小 (导入1个版本) |
||
(未显示同一用户的5个中间版本) | |||
第1行: | 第1行: | ||
// 添加刷题按钮 | // 添加刷题按钮 | ||
var title = $('#immerse_button').children('p').text() | var title = $('#immerse_button').children('p').text() | ||
第14行: | 第5行: | ||
//添加到下一章节的按钮 | //添加到下一章节的按钮 | ||
//找到列表中的位置 | //找到列表中的位置 | ||
function findListIndex(list,item){ | function findListIndex(list,item){ | ||
第35行: | 第16行: | ||
// | // | ||
function getIndexPageWikiTextAndInsertButton(indexTitle,currentPageTitle){ | function getIndexPageWikiTextAndInsertButton(indexTitle,currentPageTitle){ | ||
new mw.Api().get( { | |||
"action": "query", | "action": "query", | ||
"format": "json", | "format": "json", | ||
第47行: | 第27行: | ||
"rvdir": "older" | "rvdir": "older" | ||
} ).done( function ( data ) { | } ).done( function ( data ) { | ||
//从返回的数据data中提取页面 | |||
var pages = data.query.pages | var pages = data.query.pages | ||
var text = '' | var text = '' | ||
第55行: | 第35行: | ||
} | } | ||
} | } | ||
//获取目录页中的目录项列表 | |||
var indexPageNames = getIndexPageName(text) | var indexPageNames = getIndexPageName(text) | ||
//获取当前页面前后两个页面的id,名词,无前缀名词 | |||
var id = findListIndex(indexPageNames,'题库:'+currentPageTitle) | var id = findListIndex(indexPageNames,'题库:'+currentPageTitle) | ||
var lastPageID = | var lastPageID = id-1 | ||
var nextPageID = | var nextPageID = id+1 | ||
var lastPageName = indexPageNames[lastPageID] === undefined ? '无上一章节' : indexPageNames[lastPageID] | var lastPageName = indexPageNames[lastPageID] === undefined ? '无上一章节' : indexPageNames[lastPageID] | ||
var shortLast= lastPageName | |||
if(lastPageName.split('/').length>1){ | if(lastPageName.split('/').length>1){ | ||
shortLast = lastPageName.split('/')[lastPageName.split('/').length-1] | |||
} | } | ||
var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID] | var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID] | ||
var shortNext = nextPageName | |||
if(nextPageName.split('/').length>1){ | if(nextPageName.split('/').length>1){ | ||
shortNext = nextPageName.split('/')[nextPageName.split('/').length-1] | |||
} | } | ||
//生成按钮并添加到DOM | |||
var lastBtn = new OO.ui.ButtonWidget( { | var lastBtn = new OO.ui.ButtonWidget( { | ||
framed: false, | framed: false, | ||
第75行: | 第60行: | ||
'progressive' | 'progressive' | ||
], | ], | ||
label: '<上一章节:'+ | label: '<上一章节:'+shortLast, | ||
href: 'https://www.medforest.cn/dic/'+lastPageName, | href: 'https://www.medforest.cn/dic/'+lastPageName, | ||
rel: '', | rel: '', | ||
第85行: | 第70行: | ||
'progressive' | 'progressive' | ||
], | ], | ||
label: '下一章节:'+ | label: '下一章节:'+shortNext+'>', | ||
href: 'https://www.medforest.cn/dic/'+nextPageName, | href: 'https://www.medforest.cn/dic/'+nextPageName, | ||
rel: '', | rel: '', | ||
第97行: | 第82行: | ||
//** {{目录项|题库:诊断学学习指导与习题集(第4版)/第一篇/第一节|第一节 发热}} | //** {{目录项|题库:诊断学学习指导与习题集(第4版)/第一篇/第一节|第一节 发热}} | ||
function getIndexPageName(text){ | function getIndexPageName(text){ | ||
var pageList = [] | var pageList = [] | ||
text = text.split('{{目录项|') | text = text.split('{{目录项|') |
2023年6月29日 (四) 15:04的最新版本
// 添加刷题按钮
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){
new mw.Api().get( {
"action": "query",
"format": "json",
"prop": "revisions",
"titles": indexTitle,
"utf8": 1,
"rvprop": "content",
"rvlimit": 1,
"rvslots": "*",
"rvdir": "older"
} ).done( function ( data ) {
//从返回的数据data中提取页面
var pages = data.query.pages
var text = ''
if(pages['-1'] === undefined){
for(var key in pages){
text = pages[key]['revisions'][0]['slots']['main']['*']
}
}
//获取目录页中的目录项列表
var indexPageNames = getIndexPageName(text)
//获取当前页面前后两个页面的id,名词,无前缀名词
var id = findListIndex(indexPageNames,'题库:'+currentPageTitle)
var lastPageID = id-1
var nextPageID = 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]
}
//生成按钮并添加到DOM
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){
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
}