用户:RedDragon/common.js:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第1行: | 第1行: | ||
$(function() { | $(function() { | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
var shortlink = document.querySelector(' | var shortlink = document.querySelector('.title-shortlink') | ||
if (shortlink) { | if (shortlink) { | ||
| 第12行: | 第12行: | ||
navigator.clipboard.writeText(this.textContent).then(function() { | navigator.clipboard.writeText(this.textContent).then(function() { | ||
var parent = shortlink.parentNode | |||
var next = shortlink.nextSibling | |||
parent.removeChild(shortlink) | |||
parent.insertBefore(shortlink, next) | |||
shortlink.title = '已复制' | shortlink.title = '已复制' | ||
setTimeout(function() { | setTimeout(function() { | ||
shortlink.title = '点击复制' | shortlink.title = '点击复制' | ||
parent.removeChild(shortlink) | |||
parent.insertBefore(shortlink, next) | |||
}, 1000) | }, 1000) | ||
}).catch(function(err) { | }).catch(function(err) { | ||
console.error('复制失败: ', err) | console.error('复制失败: ', err) | ||
shortlink.title = '复制失败' | shortlink.title = '复制失败' | ||
var parent = shortlink.parentNode | |||
parent.removeChild(shortlink) | |||
parent.insertBefore(shortlink, shortlink.nextSibling) | |||
}) | }) | ||
}) | }) | ||
2025年8月16日 (六) 21:00的版本
$(function() {
mw.hook('wikipage.content').add(function() {
var shortlink = document.querySelector('.title-shortlink')
if (shortlink) {
shortlink.removeAttribute('href')
shortlink.style.cursor = 'pointer'
shortlink.title = '点击复制'
shortlink.addEventListener('click', function(e) {
e.preventDefault()
navigator.clipboard.writeText(this.textContent).then(function() {
var parent = shortlink.parentNode
var next = shortlink.nextSibling
parent.removeChild(shortlink)
parent.insertBefore(shortlink, next)
shortlink.title = '已复制'
setTimeout(function() {
shortlink.title = '点击复制'
parent.removeChild(shortlink)
parent.insertBefore(shortlink, next)
}, 1000)
}).catch(function(err) {
console.error('复制失败: ', err)
shortlink.title = '复制失败'
var parent = shortlink.parentNode
parent.removeChild(shortlink)
parent.insertBefore(shortlink, shortlink.nextSibling)
})
})
}
})
})