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

用户:RedDragon/common.js:修订间差异

来自Rizline中文维基
RedDragon
RedDragon留言 | 贡献 (创建页面,内容为“$(function() { var shortlink = document.querySelector('.title-shortlink'); if (shortlink) { shortlink.removeAttribute('href'); shortlink.addEventListener('click', function(e) { e.preventDefault(); navigator.clipboard.writeText(this.textContent).then(function() { var originalText = shortlink.textContent; shortlink.textContent = '已复制!';…”)
 
 
(未显示同一用户的11个中间版本)
第1行: 第1行:
$(function() {
$(function() {
     var shortlink = document.querySelector('.title-shortlink');
// 红龙的神秘js
   
// 点击短链接复制
    if (shortlink) {
     mw.hook('wikipage.content').add(function() {
        shortlink.removeAttribute('href');
        var shortlink = document.querySelector('.title-shortlink')
        var parent = shortlink ? shortlink.parentNode : null
          
          
         shortlink.addEventListener('click', function(e) {
         if (shortlink) {
             e.preventDefault();
            shortlink.removeAttribute('href')
             shortlink.style.cursor = 'pointer'
            shortlink.title = '复制链接'
              
              
             navigator.clipboard.writeText(this.textContent).then(function() {
             shortlink.addEventListener('click', function(e) {
                 var originalText = shortlink.textContent;
                 e.preventDefault()
                shortlink.textContent = '已复制!';
                  
                  
                 setTimeout(function() {
                 navigator.clipboard.writeText(this.textContent).then(function() {
                    shortlink.textContent = originalText;
                    parent.removeChild(shortlink)
                }, 2000);
                    parent.insertBefore(shortlink, shortlink.nextSibling)
            }).catch(function(err) {
                    shortlink.title = '已复制'
                console.error('失败: ', err);
                   
            });
                    setTimeout(function() {
        });
                        shortlink.title = '复制链接'
          
                    }, 1000)
        shortlink.style.cursor = 'pointer';
                }).catch(function(err) {
        shortlink.title = '点击复制链接';
                    console.error('复制失败: ', err)
     }
                    shortlink.title = '复制失败'
});
                    parent.removeChild(shortlink)
                    parent.insertBefore(shortlink, shortlink.nextSibling)
                })
            })
         }
    })
   
      
})

2025年8月26日 (二) 01:32的最新版本

$(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)
                })
            })
        }
    })
    
    
})