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

添加2,306字节 、​ 2020年12月16日 (星期三)
// Edit via Wikiplus
(// Edit via Wikiplus)
(// Edit via Wikiplus)
$(function () {
for (let a of Array.from(document.querySelectorAll('.mw-rollback-link a'))) {
if (!a.addEventListenerhasAttribute('clickhref', function (ev)) { continue }
if (!confirma.addEventListener('确定要回退吗?click')) {, (ev.preventDefault() }=> {
ev.preventDefault()
confirmUI('确定要回退此页面吗?', (confirmed) => {
if (confirmed) { window.location.href = a.href }
})
})
}
/**
* 显示一个自定义确认框
* @param {string} text
* @param {(confirmed:boolean)=>void} callback
*/
function confirmUI(text = '', callback) {
// 容器
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', '#f9fde7')
yesBtn.textContent = '确定'
yesBtn.addEventListener('click', () => {
callback(true)
container.remove()
})
container.appendChild(yesBtn)
// 取消按钮
let noBtn = document.createElement('div')
noBtn.className = 'btn'
noBtn.style.setProperty('--hover-color', '#fdece7')
noBtn.textContent = '取消'
noBtn.addEventListener('click', () => {
callback(false)
container.remove()
})
container.appendChild(noBtn)
// 显示UI
document.body.appendChild(container)
// 调整位置
container.style.marginLeft = (container.offsetWidth * -0.5) + 'px'
container.style.marginTop = (container.offsetHeight * -0.5) + 'px'
}
// 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: #FDF6E6;
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);
}
`
document.head.appendChild(s)
})