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

MediaWiki:Gadget-tikuShuaTi.js

MediaWiki界面页面
Cirno.9讨论 | 贡献2023年6月20日 (二) 09:42的版本

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/*<%-- [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'))


//添加到下一章节的按钮
//如果是题库名字空间再运行
if($('.mw-page-title-namespace').text === '题库'){
    var thisPageName = $('.mw-page-title-main').text().split('/')[0]
    var indexName = '模板:目录-'+thisPageName
    getIndexPageWikiTextAndInsertButton(indexName)
}

//
function getIndexPageWikiTextAndInsertButton(title){
    var api = new mw.Api();
    api.get( {
        "action": "query",
        "format": "json",
        "prop": "revisions",
        "titles": title,
        "utf8": 1,
        "rvprop": "content",
        "rvlimit": 1,
        "rvslots": "*",
        "rvdir": "older"
    } ).done( function ( data ) {
        console.log( data );
    } );
}
//解析目录项
//** {{目录项|题库:诊断学学习指导与习题集(第4版)/第一篇/第一节|第一节 发热}}
function rIndex(text){
    console.log(text)
    if(text.length>0){
        var reg1 = new RegExp('(?<=\\{\\{目录项)(.+?)(?=\\}\\})','g')
        var reg2 = new RegExp('\\{\\{目录项(.+?)\\}\\}','g')
        var content = text.match(reg1)[0]
        text=text.replace(reg2,'')
        var level = text.match(/\*/g).length
        content = content.split('/').slice(-1)
        var finalText = ''
        for(var i=0;i<level;i++){
            finalText+='*'
        }
        finalText+=' '+content+'\n'
        console.log(finalText)
        return finalText
    }else{
        return ''
    }
}