User:Abbe98/copy-qid.js
Jump to navigation
Jump to search
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.
mw.loader.using('oojs-ui-core').done(function() {
$(function() {
if(mw.config.values.wgNamespaceNumber === 0) {
function copyID() {
var successPopup = new OO.ui.PopupWidget({
$content: $('<p>Copied!</p>'),
padded: true,
width: 80,
});
$('.mw-indicators').append(successPopup.$element);
var failPopup = new OO.ui.PopupWidget({
$content: $('<p>Copied!</p>'),
padded: true,
width: 80,
});
$('.mw-indicators').append(failPopup.$element);
navigator.clipboard.writeText(mw.config.values.wbEntityId).then(function() {
successPopup.toggle(true);
setTimeout(function() { successPopup.toggle(false) }, 1000);
}, function() {
successPopup.toggle(true);
setTimeout(function() { failPopup.toggle(false) }, 3000);
});
}
var button = new OO.ui.ButtonWidget({
label: 'Copy QID',
});
button.on('click', copyID);
$('.mw-indicators').append(button.$element);
}
});
});