diff --git a/js/client.js b/js/client.js index c9c0cc9a01..17fea020db 100644 --- a/js/client.js +++ b/js/client.js @@ -2159,6 +2159,21 @@ function toId() { }}); }, + copyText: function (value, target) { + var dummyInput = document.createElement("input"); + // This is a hack. You can only "select" an input field. + // The trick is to create a short lived input element and destroy it after a copy. + // (stolen from the replay code, obviously --mia) + dummyInput.id = "dummyInput"; + dummyInput.value = value || target.value || target.href || ""; + dummyInput.style.position = 'absolute'; + target.appendChild(dummyInput); + dummyInput.select(); + document.execCommand("copy"); + target.removeChild(dummyInput); + $(target).text('Copied!'); + }, + // layout bestWidth: 659, diff --git a/src/battle-log.ts b/src/battle-log.ts index 2d54337f5f..8c03cccf7a 100644 --- a/src/battle-log.ts +++ b/src/battle-log.ts @@ -760,6 +760,7 @@ export class BattleLog { spotify: 0, youtube: 0, formatselect: 0, + copytext: 0, twitch: 0, }); @@ -925,6 +926,16 @@ export class BattleLog { 'name', getAttrib('name') || '', ], }; + } else if (tagName === 'copytext') { + return { + tagName: 'button', + attribs: [ + 'type', getAttrib('type'), + 'class', getAttrib('class') || 'button', + 'value', getAttrib('value'), + 'name', 'copyText', + ], + } } else if (tagName === 'psicon') { // is a custom element which supports a set of mutually incompatible attributes: // and