跳转到内容

User:Bencmq/script/sectionPermalink.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/** Creates a popup besides each heading. Provides a shortened permanent link to that section of the current version.
      Links only appear on given subpages
      Links are protocol-relative URLs.
       It also modifies the permanent link in Toolbox section to remove the title parameter, which is usually encoded to be ultra long and unreadable anyway. 
*/
$(function() {
    if (wgPageName.indexOf('更改用户名') >-1 || wgPageName.indexOf('更改用戶名') >-1) {
       // [[MediaWiki:Gadget-ShortLink.js]]
        var pLink = document.getElementById('t-permalink')
        if (pLink) {
            var permalink = pLink.firstChild.href.replace(/title=[^&]*&/,'');
            var relativePermalink = permalink.replace(/https?:/,'');
            pLink.firstChild.href = permalink;
        };
 
        var lis = document.getElementsByClassName('mw-headline');
        if (!lis) {return false};
 
        for (var i=0; i < lis.length; i++){
            li = lis[i];
            section_name = li.getAttribute('id');
            copy_button = document.createElement('a');
            copy_button.href = 'https:' + relativePermalink + '#' + section_name;
            copy_button.appendChild(document.createTextNode('Permalink'));
            copy_button.setAttribute('onClick', 'linkPopUp("https:' + relativePermalink + '#' + section_name + '"); return false;');
            copy_button.style.fontSize = "10pt";
            copy_button.style.fontWeight = "normal";
            copy_button.style.styleFloat = "none"; 
            copy_button.style.cssFloat = "none";
            copy_button.style.marginLeft = "4px";
            li.parentNode.appendChild(copy_button);
 
        }
    }
});
function linkPopUp(link) {
            prompt("Copy the following link to clipboard ", link);
};