User:Kuhlau/CopyTitle.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 18: | Line 18: | ||
#title-copy-content , | #title-copy-content , | ||
#title-copy-all { | #title-copy-all { | ||
color: | color: var(--alt-link-color); | ||
cursor: pointer; | cursor: pointer; | ||
} | } | ||
| Line 24: | Line 24: | ||
#title-copy-all:hover { | #title-copy-all:hover { | ||
text-decoration: underline; | text-decoration: underline; | ||
} | } | ||
`); | `); | ||
| Line 42: | Line 41: | ||
id: 'title-copy-all', | id: 'title-copy-all', | ||
class: 'mw-list-item title-copy-button', | class: 'mw-list-item title-copy-button', | ||
text: 'Copy title | text: 'Copy title (namespace)' | ||
}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list')); | }).appendTo($('#mw-panel #p-navigation .vector-menu-content-list')); | ||
Latest revision as of 11:18, 14 July 2026
/*
Appends two buttons to the edit tools to copy the title with/without namespace
Author: Caburum & Thundercraft5
Based on code by: RheingoldRiver
See also: [[w:c:dev:CopyTitle]] (the original script this was from before being modified)
Modified by: Kuhlau
Kuhlau's notes: This script adds a little button to the side of the page you can use to copy the real title of the current page (not the displayed title).
Modified further by: Mikevoir (to add lightbox usage and other cleanup)
Modified even further by: Kuhlau (to add it to vector list)
*/
$(function() {
if (window.CopyTitleLoaded) {return;}
window.CopyTitleLoaded = true;
mw.util.addCSS(`
#title-copy-content ,
#title-copy-all {
color: var(--alt-link-color);
cursor: pointer;
}
#title-copy-content:hover ,
#title-copy-all:hover {
text-decoration: underline;
}
`);
function init() {
$('<li>', {
id: 'title-copy-content',
class: 'mw-list-item title-copy-button',
text: 'Copy title'
}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));
if (mw.config.get('wgNamespaceNumber') !== 0) {
$('<li>', {
id: 'title-copy-all',
class: 'mw-list-item title-copy-button',
text: 'Copy title (namespace)'
}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));
}
$('#mw-panel .vector-menu-content-list #title-copy-content').click(function() {
copy(mw.config.get('wgTitle'), this);
});
$('#mw-panel .vector-menu-content-list #title-copy-all').click(function() {
copy(mw.config.get('wgPageName').replace(/_/g, ' '), this);
});
}
function copy(text, element) {
var copyEl = document.createElement('textarea');
copyEl.value = text;
document.body.appendChild(copyEl);
copyEl.select();
document.execCommand('copy');
document.body.removeChild(copyEl);
document.execCommand('copy');
var $el = $(element);
var originalText = $el.text();
$el
.addClass('copied')
.text('Copied!');
setTimeout(function () {
$el
.removeClass('copied')
.text(originalText);
}, 1000);
}
init();
});