打开/关闭菜单
Toggle preferences menu
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-tikuShuaTi.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第61行: 第61行:
         var nextPageID = (id+1) > indexPageNames.length-1 ? indexPageNames.length-1 : id+1
         var nextPageID = (id+1) > indexPageNames.length-1 ? indexPageNames.length-1 : id+1
         var lastPageName = indexPageNames[lastPageID] === undefined ? '无上一章节' : indexPageNames[lastPageID]
         var lastPageName = indexPageNames[lastPageID] === undefined ? '无上一章节' : indexPageNames[lastPageID]
        var shortedLastPageName = ''
 
         if(lastPageName.split('/')>1){
         if(lastPageName.split('/').length>1){
             shortedLastPageName = lastPageName.split('/')[lastPageName.split('/').length-1]
             lastPageName = lastPageName.split('/')[lastPageName.split('/').length-1]
         }
         }
         var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID]
         var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID]
        var shortedNextPageName = ''
         if(nextPageName.split('/').length>1){
         if(nextPageName.split('/')>1){
             nextPageName = nextPageName.split('/')[nextPageName.split('/').length-1]
             shortedNextPageName = nextPageName.split('/')[nextPageName.split('/').length-1]
         }
         }
         console.log(nextPageName.split('/'))
         console.log(nextPageName.split('/'))
第76行: 第75行:
                 'progressive'
                 'progressive'
             ],
             ],
             label: '<上一章节:'+shortedLastPageName,
             label: '<上一章节:'+lastPageName,
             href: 'https://www.medforest.cn/dic/'+ shortedLastPageName,
             href: 'https://www.medforest.cn/dic/'+lastPageName,
             rel: '',
             rel: '',
             disabled: shortedLastPageName==='无上一章节'
             disabled: lastPageName==='无上一章节'
         } )
         } )
         var nextBtn = new OO.ui.ButtonWidget( {
         var nextBtn = new OO.ui.ButtonWidget( {
第86行: 第85行:
                 'progressive'
                 'progressive'
             ],
             ],
             label: '下一章节:'+shortedNextPageName+'>',
             label: '下一章节:'+nextPageName+'>',
             href: 'https://www.medforest.cn/dic/'+shortedNextPageName,
             href: 'https://www.medforest.cn/dic/'+nextPageName,
             rel: '',
             rel: '',
             disabled: shortedNextPageName==='无下一章节'
             disabled: nextPageName==='无下一章节'
         } )
         } )
         var group = $('<div></div>').append(lastBtn.$element, '|', nextBtn.$element)
         var group = $('<div></div>').append(lastBtn.$element, '|', nextBtn.$element)

2023年6月20日 (二) 13:29的版本

/*<%-- [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'))


//添加到下一章节的按钮
//如果是题库名字空间再运行
console.log()
if($('.mw-page-title-namespace').text() === '题库'){
    var thisPageName = $('.mw-page-title-main').text().split('/')[0]
    console.log()
    var indexName = '模板:目录-'+thisPageName
    setTimeout(function(){
        getIndexPageWikiTextAndInsertButton(indexName, $('.mw-page-title-main').text())
    },0)
    
}
//找到列表中的位置
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]

        if(lastPageName.split('/').length>1){
            lastPageName = lastPageName.split('/')[lastPageName.split('/').length-1]
        }
        var nextPageName = indexPageNames[nextPageID] === undefined ? '无下一章节' : indexPageNames[nextPageID]
        if(nextPageName.split('/').length>1){
            nextPageName = nextPageName.split('/')[nextPageName.split('/').length-1]
        }
        console.log(nextPageName.split('/'))
        var lastBtn = new OO.ui.ButtonWidget( {
            framed: false,
            flags: [
                'progressive'
            ],
            label: '<上一章节:'+lastPageName,
            href: 'https://www.medforest.cn/dic/'+lastPageName,
            rel: '',
            disabled: lastPageName==='无上一章节'
        } )
        var nextBtn = new OO.ui.ButtonWidget( {
            framed: false,
            flags: [
                'progressive'
            ],
            label: '下一章节:'+nextPageName+'>',
            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
}