diff --git a/index.htm b/index.htm index 6a667d5..2ee1c32 100644 --- a/index.htm +++ b/index.htm @@ -217,7 +217,10 @@ -
+
+
click to copy
+
+
Please note: This command is too long to be executed from chat. You need to place it inside a command block. (see below) diff --git a/js/main.js b/js/main.js index 2b594c5..76842cf 100644 --- a/js/main.js +++ b/js/main.js @@ -80,6 +80,32 @@ Point = { y:null }; +jQuery.fn.selectAndCopyText = function(){ + // https://stackoverflow.com/a/9976413/1456971 + this.find('input').each(function() { + if($(this).prev().length == 0 || !$(this).prev().hasClass('p_copy')) { + $('

').insertBefore($(this)); + } + $(this).prev().html($(this).val()); + }); + + var doc = document; + var element = this[0]; + if (doc.body.createTextRange) { + var range = document.body.createTextRange(); + range.moveToElementText(element); + range.select(); + } else if (window.getSelection) { + var selection = window.getSelection(); + var range = document.createRange(); + range.selectNodeContents(element); + selection.removeAllRanges(); + selection.addRange(range); + } + + document.execCommand("copy"); +}; + $(document).ready(function(){ //Init setup(); @@ -90,6 +116,11 @@ $(document).ready(function(){ window.onbeforeunload = function(){ return "Changes will NOT be saved. Exit anyways?"; }; + + // Copy code on click + $(".code").click(function(){ + $("#code").selectAndCopyText(); + }); //Stuff to handle and update input $("input").on("input", function(){ diff --git a/style.css b/style.css index a379918..8250b95 100644 --- a/style.css +++ b/style.css @@ -78,6 +78,13 @@ input[type="text"]:not(:last-child){ border-radius: 3px; color: #ffffff; } +#code-copy-hint{ + font-family: sans-serif; + font-style: italic; + font-size: 0.8em; + text-align: right; + opacity: 0.6; +} #disabledslots{ display: block;