部分js代码
<script type="text/javascript"> (() => { let obj = {}; //获取DOM对象的方法 let $ = function(id){ return document.getElementById(id); } //获取预览图片路径 let getObjectURL = function(file){ let url = null ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } return url ; } //十六进制转换器 let hexadecimal = function(num) { var r = parseInt(num).toString(16); if (r.length == 1) { return '0' + r; } return r.toUpperCase(); } //判断颜色是否已存在 let checkHasColor = function(arr, r, g, b) { for (var i = 0; i < arr.length; i++) { var n = equalsColor(arr[0], arr[1], arr[2], r, g, b); if (n >= 0.8) { return true; } } return false; } //判断相同颜色 let equalsColor = function(r1, g1, b1, r2, g2, b2) { return (255 - Math.abs(r1 - r2) * 0.297 - Math.abs(g1 - g2) * 0.593 - Math.abs(b1 - b2) * 0.11) / 255; } //建立canvas画布 let canvas = function(obj,size,param){ let canvas = document.createElement("canvas"); if (!canvas.getContext) { alert("很遗憾,您浏览器版本太老了,无法使用我们的小工具 !"); return; } })() </script>