You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
function copyToClipboard(elementId) {
|
|
|
|
/* Get the text field */
|
|
var copyText = document.getElementById(elementId);
|
|
|
|
/* Select the text field */
|
|
copyText = copyText.textContent;
|
|
|
|
/* Copy the text inside the text field */
|
|
navigator.clipboard.writeText(copyText);
|
|
|
|
var tooltip = document.getElementsByClassName('tooltiptext');
|
|
for (var i = 0; i < tooltip.length; i++) {
|
|
tooltip[i].innerHTML = "Copied";
|
|
}
|
|
|
|
}
|
|
|
|
function resetCopy() {
|
|
|
|
var tooltip = document.getElementsByClassName('tooltiptext');
|
|
for (var i = 0; i < tooltip.length; i++) {
|
|
tooltip[i].innerHTML = "Copy to clipboard";
|
|
}
|
|
|
|
}
|
|
|
|
// Event Listeners
|
|
|
|
//const clipboard = querySelector('.tooltiptext');
|
|
const minecraft = document.getElementById('minecraft-clip');
|
|
minecraft.addEventListener('click', function (event) { copyToClipboard('minecraft-server'); });
|
|
|
|
const terraria = document.getElementById('terraria-clip');
|
|
terraria.addEventListener('click', function (event) { copyToClipboard('terraria-server'); });
|
|
|
|
const factorio = document.getElementById('factorio-clip');
|
|
factorio.addEventListener('click', function (event) { copyToClipboard('factorio-server'); });
|
|
|
|
var tooltipped = document.getElementsByClassName('tooltipped');
|
|
for (var i = 0; i < tooltipped.length; i++) {
|
|
//tooltipped[i].addEventListener('click', function (event) { copyToClipboard(); });
|
|
// this clipboard
|
|
tooltipped[i].addEventListener('mouseout', function (event) { resetCopy(); });
|
|
}
|
|
|