diff --git a/Alembic.sketchplugin/Contents/Resources/assets/js/main.js b/Alembic.sketchplugin/Contents/Resources/assets/js/main.js index 57600c0..767caff 100644 --- a/Alembic.sketchplugin/Contents/Resources/assets/js/main.js +++ b/Alembic.sketchplugin/Contents/Resources/assets/js/main.js @@ -63,12 +63,12 @@ document.addEventListener("DOMContentLoaded", function() { for (var i = 0; i < colors.length; i++) { colors[i].addEventListener("click", function() { var color = this.getAttribute("data-color"); - var input = document.createElement("input"); - input.value = color; - document.body.appendChild(input); - input.select(); - document.execCommand('copy'); - document.body.removeChild(input); + var data = { + "type": "clipboard", + "color": color, + "date": new Date().getTime() + } + window.location.hash = JSON.stringify(data); document.querySelector(".imagePreview__toast span").style.backgroundColor = color; document.querySelector(".imagePreview__toast").classList.remove("hidden"); if (toastTimeout) clearTimeout(toastTimeout); diff --git a/Alembic.sketchplugin/Contents/Sketch/alembic.js b/Alembic.sketchplugin/Contents/Sketch/alembic.js index c5af50b..e74ea65 100644 --- a/Alembic.sketchplugin/Contents/Sketch/alembic.js +++ b/Alembic.sketchplugin/Contents/Sketch/alembic.js @@ -77,6 +77,16 @@ function onRun(context) { expandPanel(panel); windowObject.evaluateWebScript("update('" + base64 + "')"); } + }), + "webView:didChangeLocationWithinPageForFrame:": (function(webView, webFrame) { + var hash = windowObject.evaluateWebScript("window.location.hash.substring(1)"); + var data = JSON.parse(hash); + + if (data.type == "clipboard") { + var clipboard = NSPasteboard.generalPasteboard(); + clipboard.clearContents(); + clipboard.setString_forType_(data.color, NSStringPboardType); + } }) })