File copy button

This commit is contained in:
Shadowfacts 2016-09-10 12:08:12 -04:00
parent 8c06f61376
commit 5e810468e1
No known key found for this signature in database
GPG Key ID: F802198A7D7F309D
2 changed files with 35 additions and 0 deletions

View File

@ -1,3 +1,15 @@
function addStyle(style) {
$("body").after(`<style>${style}</style>`);
}
function copyToClipBoard(text) {
let textArea = $("<textarea></textarea>");
textArea.css("opacity", "0");
textArea.css("position", "fixed");
textArea.val(text);
$("body").append(textArea);
textArea.select();
document.execCommand("copy");
textArea.remove();
}

View File

@ -185,4 +185,27 @@ let currentUser = $("ul.header-nav.float-right > li:last > a > img").attr("alt")
});
});
});
})();
// file copy button
(function() {
if (!$("[data-line-number='1']").length) {
return;
}
let targetSibling = $("#raw-url")
let fileUrl = targetSibling.attr("href");
let copyBtn = $("<a></a>");
copyBtn.text("Copy");
copyBtn.attr("href", fileUrl);
copyBtn.addClass("btn btn-sm copy-btn");
copyBtn.click((e) => {
e.preventDefault();
let fileContents = $(".js-file-line-container").get(0).innerText;
copyToClipBoard(fileContents);
});
targetSibling.after(copyBtn);
})();