walfie / gbf-raidfinder

Granblue Raid Finder (Archived: Granblue no longer has raid tweets)
https://gbf-raidfinder.aikats.us
MIT License
206 stars 106 forks source link

Automatically copy latest raid id to clipboard if option is set to true #64

Closed KuroNoDev closed 8 years ago

KuroNoDev commented 8 years ago

Maybe a checkbox on each column

walfie commented 8 years ago

Unfortunately this isn't possible due to browser security policies -- copying to clipboard has to be from a user-initiated action (e.g., a click event). Or I could be wrong.

KuroNoDev commented 8 years ago

This should be possible by creating a hidden input text and updating its value for every api response (assuming the user enabled auto-copying option), focus then select, then copy it to clipboard via document.execCommand('Copy');

walfie commented 8 years ago

Yeah, that's how I'm doing the copying now. The document.execCommand('copy') doesn't work unless it's inside an event handler: It'd be alarming if a website could copy arbitrary text without user interaction.

<textarea id="id1">this doesn't get copied</textarea>
<textarea id="id2">this gets copied</textarea>
<button>Copy id2</button>

<script>
var div1 = document.querySelector('#id1');
div1.select();
document.execCommand('copy'); // Shouldn't work

var div2 = document.querySelector('#id2');
var button = document.querySelector('button');
button.onclick = function(e) {
  div2.select();
  document.execCommand('copy'); // Should work
};
</script>

(codepen)

Does that work for you? id1 doesn't get copied for me, id2 gets copied if I click.

KuroNoDev commented 8 years ago

aahh tried to also trigger click automatically but it also didn't work. I apologize for the waste of time (that's actually irresponsible of me to not try it first).

walfie commented 8 years ago

No worries!