MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
/* Botão de copiar para blocos de código */ | |||
$(function() { | |||
$('pre, .mw-code, .syntaxhighlight').each(function() { | |||
var $this = $(this); | |||
var $button = $('<button>') | |||
.text('Copy') | |||
.addClass('copy-code-button') | |||
.css({ | |||
'float': 'right', | |||
'cursor': 'pointer', | |||
'padding': '2px 8px', | |||
'font-size': '12px' | |||
}) | |||
.click(function() { | |||
var text = $this.text().replace(/Copy$/, ''); // Remove o texto do próprio botão | |||
navigator.clipboard.writeText(text).then(function() { | |||
$button.text('Copied!'); | |||
setTimeout(function() { $button.text('Copy'); }, 2000); | |||
}); | |||
}); | |||
$this.prepend($button); | |||
}); | |||
}); | |||