User:Gryllida/js/copyPageTitleToClipboard-0.1.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
/*
Author : Svetlana Tkachenko svetlana@members.fsf.org
Licence: GPLv3+
Description: [beta] adds 'copy title' tab that copies current page title to clipboard
Version: 0.1
Date: 2018-03-29
TODO:
[ ] test
See also <https://en.wikinews.org/wiki/User:Gryllida/Tasks>. [[User:Gryllida/Tasks]]
*/
mw.loader.using(['mediawiki.api', 'jquery.ui'], function () {
"use strict";
// Add 'Copy title' tab
// Code stolen from [[User:Gryllida/js/plagiarismcheck.js]] and many other places
var link = mw.util.addPortletLink(mw.config.get('skin') === 'vector' ? 'p-views' : 'p-cactions',
'javascript:void(0);', 'Copy title', 'p-gryllida-copytitle', 'Copy this page title to clipboard', '6'
);
// Copy page title to clipboard
// Code stolen from [[User:The Earwig/permalink.js]]
var _copyTitle = function(){
var $temp = $("<textarea/>", {
val: wgCanonicalNamespace+":"+wgTitle
}).appendTo("body");
$temp.select();
document.execCommand("copy");
$temp.remove();
}
// Listen to clicks
link.addEventListener('click', _copyTitle);
});