Skip to content

Commit

Permalink
Support a custom tag for copying text to the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Sep 27, 2023
1 parent cae879e commit e4f6119
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ export class BattleLog {
spotify: 0,
youtube: 0,
formatselect: 0,
copytext: 0,
twitch: 0,
});

Expand Down Expand Up @@ -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') {
// <psicon> is a custom element which supports a set of mutually incompatible attributes:
// <psicon pokemon> and <psicon item>
Expand Down

0 comments on commit e4f6119

Please sign in to comment.