User:Mdaniels5757/Easy-permalink.js
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// By [[User:Mdaniels5757]], copied and modified from [[User:DannyS712/Easy-link.js]]
//<nowiki>
$(function (){
var copy_link_config = {
name: '[[User:Mdaniels5757/Easy-permalink.js|Easy-permalink.js]]',
version: 1,
debug: false
};
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
mw.util.addPortletLink ( 'p-tb', '', 'Easy permalink', 'ca-copy-permalink', 'Copy and format the current link to this revision');
$('#ca-copy-permalink').on('click', function( e ) {
e.preventDefault();
copy_link();
} );
} );
} );
function copy_link(){
section = window.location.hash;
revid = mw.config.get('wgCurRevisionId');
new_url = '[[Special:Permalink/' + revid + section + ']]';
if (copy_link_config.debug) console.log( new_url );
var ignore_this = document.createElement("input");
document.createElement("input");
document.body.appendChild(ignore_this);
ignore_this.setAttribute('value', new_url);
ignore_this.select();
document.execCommand("copy");
document.body.removeChild(ignore_this);
}
});
//</nowiki>