User:Gryllida/js/copyPageTitleToClipboard-0.2.js

From Wikinews, the free news source you can write!
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.2pre
Date: 2018-03-29
Changes:
 [x] moved link to 'tools' section of vector skin
TODO: 
  [ ] test
See also <https://en.wikinews.org/wiki/User:Gryllida/Tasks>. [[User:Gryllida/Tasks]]
*/
var gryllidaCopyTitle = function(){
	
    var $temp = $("<textarea/>", {
        val: wgCanonicalNamespace+":"+wgTitle
    }).appendTo("body");
    alert($temp);
    $temp.select();
    document.execCommand("copy");
    $temp.remove();
};
mw.loader.using(['mediawiki.api', 'jquery.ui'], function () {
	"use strict";
	// Copy page title to clipboard
	// Code stolen from [[User:The Earwig/permalink.js]]
	// Add link in 'tools' section
	// Code stolen from [[MediaWiki:Gadget-onScreenEdit.js]]
	mw.util.addPortletLink('p-tb', 'javascript:gryllidaCopyTitle();void%200', 'Copy title');
});