Last active
April 2, 2018 04:46
-
-
Save 02Tea/b669bd928f040fc17a12e3fb6ca6ed11 to your computer and use it in GitHub Desktop.
[Watermelon BM test] #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t<e.length;t++)o[t]=e[t];return o}return Array.from(e)}function Watermelon(e){var t=[],o=void 0,r=void 0,n={colors:5,threshold:255},a=e?e:n,l={position:"absolute",width:"100%",height:"100%","z-index":99999},i={display:"inline-block",position:"relative","margin-bottom":"-5px",height:"100%",width:a.size+"%",transition:"all 0.3s ease"},c=function(e){return console.log(e)},d=function(){var e=50+Math.floor(Math.random()*a.threshold),t=50+Math.floor(Math.random()*a.threshold),o=50+Math.floor(Math.random()*a.threshold);return"rgb( "+e+", "+t+", "+o+" )"},s=function(e){var t="";for(var o in e)e.hasOwnProperty(o)&&(t+=o+":"+e[o]+";");return t},u=function(e,t,o){var r=o|t<<8|e<<16;return"#"+(16777216+r).toString(16).slice(1)},m=function(e){return e.substring(4,e.length-1).replace(/ /g,"").split(",")},p=function(){document.getElementById("exocarp")&&document.getElementById("exocarp").remove();var e=document.createElement("div");e.setAttribute("id","exocarp"),e.setAttribute("style",s(l)),document.body.prepend(e);for(var o=0;o<a.colors;o++){var r=document.createElement("div"),n=d();i["background-color"]=n,t[o]=u.apply(void 0,_toConsumableArray(m(n))),i.width=100/a.colors+"%",r.setAttribute("class","mesocarp"),r.setAttribute("style",s(i)),e.prepend(r)}b(t)},f=function(){return document.elementFromPoint(o,r)},y=function(e){if("add"===e){var t=document.createElement("div"),o=document.getElementsByClassName("mesocarp");o.length;i["background-color"]=d(),t.setAttribute("class","mesocarp"),t.setAttribute("style",s(i)),document.getElementById("exocarp").append(t),a.colors++,p()}if("remove"===e){var r=document.getElementById("exocarp").lastChild,n=document.getElementsByClassName("mesocarp");n.length>1&&(r.remove(),a.colors--,p())}},h=function(){document.body.onkeyup=function(e){32===e.keyCode&&p(),82===e.keyCode&&(a.colors=5,p()),187===e.keyCode&&y("add"),189===e.keyCode&&y("remove")},document.ondblclick=function(){var e=f(),t=e.style.backgroundColor.toString(16);c(u.apply(void 0,_toConsumableArray(m(t))))},document.onmousemove=function(e){e=e||window.event,o=e.clientX,r=e.clientY}},b=function(e){localStorage.setItem("palette_pastlife",JSON.stringify(e))},g=function(){var e=document.createElement("div"),t=document.createElement("span"),o={background:"rgba(0, 0, 0, 0.9)",color:"#fff",position:"absolute",bottom:"20px","z-index":"99999",left:"50%",transform:"translateX(-50%)",padding:"5px","font-weight":"bold","font-size":"16px","font-family":"Courier, Arial"};e.setAttribute("id","hotkeys"),e.setAttribute("style",s(o)),t.textContent="[spacebar] Reload [+] Add Color [-] Delete Color [r] Reset",e.prepend(t),document.body.prepend(e)},v=function(){g(),h(),p()};v()}var wm=new Watermelon({colors:6,threshold:255});})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment