Check in copy.js

This commit is contained in:
idk
2021-03-11 21:18:29 -05:00
parent 56db652ee8
commit 15b6638538

View File

@@ -0,0 +1,37 @@
/* @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 */
/* see also licenses/LICENSE-GPLv2.txt */
function initCopyLink() {
var buttons = document.getElementsByClassName("tunnelHostnameCopy");
for (index = 0; index < buttons.length; index++) {
var button = buttons[index];
addClickHandler(button);
}
}
function addClickHandler(elem) {
elem.addEventListener("click", function() {
let prevElem = getPreviousHelper(elem).firstElementChild;
prevElem.select();
document.execCommand("copy");
alert("Copied the helper to the clipboard", prevElem.value);
});
}
document.addEventListener("DOMContentLoaded", function() {
initCopyLink();
}, true);
var getPreviousHelper = function (elem) {
var selector = ".tunnelPreview";
var parent = elem.parentElement
var sibling = parent.previousElementSibling;
while (sibling) {
if (sibling.matches(selector)) return sibling;
sibling = sibling.previousElementSibling;
}
return sibling
};
/* @license-end */