gitile.js
1 | // SPDX-FileCopyrightText: 2021 Julien Lepiller <julien@lepiller.eu> |
2 | // |
3 | // SPDX-License-Identifier: AGPL-3.0-or-later |
4 | |
5 | window.onload = function() { |
6 | buttons = document.getElementsByClassName('copy') |
7 | |
8 | function mycopy(button) { |
9 | data = button.dataset.clipboardCopy |
10 | while(data == undefined) { |
11 | button = button.parentElement |
12 | data = button.dataset.clipboardCopy |
13 | } |
14 | i = document.createElement('input') |
15 | i.type = 'text' |
16 | i.value = data |
17 | i.display = 'none' |
18 | button.appendChild(i) |
19 | i.select() |
20 | i.setSelectionRange(0, 99999); /* For mobile devices */ |
21 | document.execCommand("copy") |
22 | button.removeChild(i) |
23 | } |
24 | |
25 | for(i=0;i<buttons.length;i++) { |
26 | buttons[i].addEventListener('click', function(e) { |
27 | mycopy(e.target) |
28 | }) |
29 | } |
30 | } |
31 |