MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

用户:Salt lovely/user.js:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
(// Edit via Wikiplus)
(// Edit via Wikiplus)
第63行: 第63行:
let yesBtn = document.createElement('div')
let yesBtn = document.createElement('div')
yesBtn.className = 'btn'
yesBtn.className = 'btn'
yesBtn.style.setProperty('--hover-color', '#f9fde7')
yesBtn.style.setProperty('--hover-color', '#FDF6E6')
yesBtn.textContent = '确定'
yesBtn.textContent = '确定'
yesBtn.addEventListener('click', () => {
yesBtn.addEventListener('click', () => {
第76行: 第76行:
let noBtn = document.createElement('div')
let noBtn = document.createElement('div')
noBtn.className = 'btn'
noBtn.className = 'btn'
noBtn.style.setProperty('--hover-color', '#fdece7')
noBtn.style.setProperty('--hover-color', '#FDF6E6')
noBtn.textContent = '取消'
noBtn.textContent = '取消'
noBtn.addEventListener('click', () => {
noBtn.addEventListener('click', () => {
第86行: 第86行:
})
})
container.appendChild(noBtn)
container.appendChild(noBtn)
// 关闭按钮

let closeBtn = document.createElement('div')

closeBtn.className = 'close'
closeBtn.textContent = '×'
closeBtn.addEventListener('click', () => {
if (safe) {
safe = false
selfRemove()
}
})
container.appendChild(closeBtn)
// 显示UI
// 显示UI
container.style.opacity = '0'
container.style.opacity = '0'
container.style.top = '-100%'
container.style.top = '20%'
container.style.transitionTimingFunction = 'ease-out'
document.body.appendChild(container)
document.body.appendChild(container)
// 调整位置
// 调整位置
container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
container.style.transitionDuration = '.3s'
container.style.opacity = '1'
container.style.opacity = '1'
container.style.top = '50%'
container.style.top = '50%'
setTimeout(() => { container.style.transitionTimingFunction = 'ease-in' }, 500)
/**移除自己 */
/**移除自己 */
function selfRemove() {
function selfRemove() {
container.style.top = '-100%'
container.style.top = '20%'
container.style.opacity = '1'
container.style.opacity = '1'
setTimeout(() => { container.remove() }, 500)
setTimeout(() => { container.remove() }, 500)
第116行: 第128行:
left: 50%;
left: 50%;
min-width: 20vw;
min-width: 20vw;
background: #FDF6E6;
background: #fbf2dc;
user-select: none;
user-select: none;
transition: .3s ease;
}
}
.confirmUIcontainer > center{
.confirmUIcontainer > center{
第139行: 第150行:
.confirmUIcontainer .btn:hover{
.confirmUIcontainer .btn:hover{
background-color: var(--hover-color,transparent);
background-color: var(--hover-color,transparent);
}
.confirmUIcontainer .close{
position: absolute;
width: 2rem;
height: 2rem;
top: 0;
right: 0;
font-size: 2rem;
line-height: 2rem;
text-align: center;
}
}
`
`

2020年12月16日 (三) 19:26的版本

var thisHref = window.location.href;
//使用wikiplus
mw.loader.load('https://wikiplus-app.com/Main.min.js');

// ------------------
// 文档准备完毕后执行
// ------------------
$(function(){
    //清理缓存
    $('#pt-logout').before('<li id="pt-purge"><a title="刷新页面并清理缓存" href="?action=purge">清理缓存</a></li>'
                          +'<li id="pt-editcount"><a title="查看编辑数" href="https://mcbbs-wiki.cn/wiki/特殊:编辑计数/Salt_lovely">编辑计数</a></li>');
    //日志统计
    countLog("#mw-log-deleterevision-submit>ul")
    //编辑器更改
    loadAddon('WikiEditorModify')
    //loadAddon('loadprism')
    // 挂在GitHub,用CDN获取
    // mw.loader.load('https://cdn.jsdelivr.net/gh/Salt-lovely/MCBBSWikiPrismLoader/load.js')
})

// ------------------
// 一些函数,需要自取
// ------------------
//加载Addon-XXX.js
function loadAddon(s) {
    mw.loader.load("//mcbbs-wiki.cn/index.php?title=MediaWiki:Addon-" + s + ".js&action=raw&ctype=text/javascript"
    , "text/javascript");
}
//计算日志有几行
function countLog(obj) {
    $(obj).each(function(){
        var count=$(this).children('li').length
        $(this).prepend('<span>共计'+count+'条记录</span>')
    })
}

// ------------------
// 防止手贱回退页面
// ------------------
$(function () {
    for (let a of Array.from(document.querySelectorAll('.mw-rollback-link a'))) {
        if (!a.hasAttribute('href')) { continue }
        a.addEventListener('click', (ev) => {
            ev.preventDefault()
            confirmUI('确定要回退此页面吗?', (confirmed) => {
                if (confirmed) { window.location.href = a.href }
            })
        })
    }
    /**
     * 显示一个自定义确认框
     * @param {string} text 
     * @param {(confirmed:boolean)=>void} callback 
     */
    function confirmUI(text = '', callback) {
        // 安全锁,防止用户多次点击
        let safe = true
        // 容器
        let container = document.createElement('div')
        container.className = 'confirmUIcontainer'
        container.innerHTML = `<center>${text}</center>`
        // 确定按钮
        let yesBtn = document.createElement('div')
        yesBtn.className = 'btn'
        yesBtn.style.setProperty('--hover-color', '#FDF6E6')
        yesBtn.textContent = '确定'
        yesBtn.addEventListener('click', () => {
            if (safe) {
                safe = false // 安全锁
                callback(true)
                selfRemove() // 移除确认框
            }
        })
        container.appendChild(yesBtn)
        // 取消按钮
        let noBtn = document.createElement('div')
        noBtn.className = 'btn'
        noBtn.style.setProperty('--hover-color', '#FDF6E6')
        noBtn.textContent = '取消'
        noBtn.addEventListener('click', () => {
            if (safe) {
                safe = false
                callback(false)
                selfRemove()
            }
        })
        container.appendChild(noBtn)
        // 关闭按钮
        let closeBtn = document.createElement('div')
        closeBtn.className = 'close'
        closeBtn.textContent = '×'
        closeBtn.addEventListener('click', () => {
            if (safe) {
                safe = false
                selfRemove()
            }
        })
        container.appendChild(closeBtn)
        // 显示UI
        container.style.opacity = '0'
        container.style.top = '20%'
        container.style.transitionTimingFunction = 'ease-out'
        document.body.appendChild(container)
        // 调整位置
        container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
        container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
        container.style.transitionDuration = '.3s'
        container.style.opacity = '1'
        container.style.top = '50%'
        setTimeout(() => { container.style.transitionTimingFunction = 'ease-in' }, 500)
        /**移除自己 */
        function selfRemove() {
            container.style.top = '20%'
            container.style.opacity = '1'
            setTimeout(() => { container.remove() }, 500)
        }
    }
    // CSS
    let s = document.createElement('style')
    s.textContent = `
.confirmUIcontainer{
    position: fixed;
    border: 8px solid #0003;
    border-radius: 8px;
    overflow: hidden;
    padding: 0;
    top: 50%;
    left: 50%;
    min-width: 20vw;
    background: #fbf2dc;
    user-select: none;
}
.confirmUIcontainer > center{
    padding: 1.2rem .6rem 1.2rem .6rem;
    font-size: 1.05rem;
}
.confirmUIcontainer .btn{
    width: 50%;
    border: 1px solid #ccc;
    padding: 1rem;
    box-sizing: border-box;
    font-size: 1.15rem;
    line-height: 1.15rem;
    float: left;
    background-color: transparent;
    text-align: center;
    transition: .3s ease;
    cursor: pointer;
}
.confirmUIcontainer .btn:hover{
    background-color: var(--hover-color,transparent);
}
.confirmUIcontainer .close{
    position: absolute;
    width: 2rem;
    height: 2rem;
    top: 0;
    right: 0;
    font-size: 2rem;
    line-height: 2rem;
    text-align: center;
}
    `
    document.head.appendChild(s)
})