User:RedDragon/common.js
From Rizline中文维基
More actions
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$(function() {
// 红龙的神秘js
// 点击短链接复制
mw.hook('wikipage.content').add(function() {
var shortlink = document.querySelector('.title-shortlink')
var parent = shortlink ? shortlink.parentNode : null
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() {
parent.removeChild(shortlink)
parent.insertBefore(shortlink, shortlink.nextSibling)
shortlink.title = '已复制'
setTimeout(function() {
shortlink.title = '复制链接'
}, 1000)
}).catch(function(err) {
console.error('复制失败: ', err)
shortlink.title = '复制失败'
parent.removeChild(shortlink)
parent.insertBefore(shortlink, shortlink.nextSibling)
})
})
}
})
})