File copy button
This commit is contained in:
parent
8c06f61376
commit
5e810468e1
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
})();
|
Loading…
Reference in New Issue