User:Alex brollo/common.js

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(document).ready(function() {	$('<button class="baseButton" id="copiaId" style="display: inline; padding: 1px 2px;" type="button" title="Copia id pagina"><small>Copia id</small></button>').appendTo($(".wikibase-title"));		
	if (mw.config.get("wgPageName")==='Special:Search') {
		$(".mw-search-result-heading").hover(function() {navigator.clipboard.writeText(/Q\d+/.exec($(this).text()));}); 
		return false;
	}
	mw.alertMessage = function (title, text) {	
		if (text === undefined) {
			text = title;
			title = undefined;
		}
		var id = Math.random().toString(36).substring(5);
		var box = '<div class="alert-message" id="' + id + '">'+ '<button class="button alert-message-close">x</button>';
		if (title)
			box += '<strong>' + title + '</strong><br>' ;
		box += text + '</div>';
		$('#bodyContent').append(box);
		$('.alert-message-close').click(function() {
			$('.alert-message-close').parents('.alert-message').remove();
		});
		
		$("#" + id).fadeTo(3000, 500).slideUp(500, function() {
	    	$("#" + id).slideUp(500).remove();
		});
	};
	$('#copiaId').click(function() {
        navigator.clipboard.writeText($(".wikibase-title-id").text().slice(1,-1));
        mw.alertMessage("Id", "L'id dell'elemento è stato caricato negli appunti");
    });
});