Mineplex2018-withcommit/Plugins/Mineplex.ReportServer/web/main.js
Keir Nellyer a663cb3e01 Revert "Revert "Report system (version 1)""
This reverts commit d0d2de1e21.

# Conflicts:
#	Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java
2016-05-04 15:24:29 +01:00

56 lines
1.5 KiB
JavaScript

const TAG_UUID = "data-player-uuid";
var elements = document.querySelectorAll('[' + TAG_UUID + ']'); // NodeList type
for (var i = 0; i < elements.length; i++)
{
var element = elements.item(i);
element.addEventListener("click", (function(element)
{
return function(e)
{
var uuid = element.getAttribute("data-player-uuid");
copy(uuid);
alertElement('<b>Copied UUID to clipboard.</b>', element, 1500);
}
})(element));
}
/**
* Attempts to copy the supplied text into the users clipboard.
* If this fails they are presented with a box allowing them to copy and paste the text.
* This will only work on a supported browser and if this action is caused by some sort of player input.
*
* @param text the text to put in the users clipboard
*/
function copy(text)
{
var copyElement = document.createElement('input');
copyElement.setAttribute('type', 'text');
copyElement.setAttribute('value', text);
copyElement = document.body.appendChild(copyElement);
copyElement.select();
try
{
document.execCommand('copy');
}
catch (e)
{
console.log("document.execCommand('copy'); is not supported by this browser.");
prompt('Copy the value below. (CTRL + C, ENTER)', text);
}
finally
{
copyElement.remove();
}
}
function alertElement(html, element, millis)
{
var original = element.innerHTML;
element.innerHTML = html;
setTimeout(function() { element.innerHTML = original; }, millis);
}