UNPKG

@mhg/blog

Version:
1 lines 1.61 kB
<meta name="robots" content="noindex,nofollow,noarchive"><script src="https://cdn.jsdelivr.net/npm/jquery@3.4/dist/jquery.min.js"></script><script>function uploadimg(e,t){var a=new Date,n=""+a.getFullYear()+(a.getMonth()+1)+a.getDate()+a.getHours()+a.getMinutes()+a.getSeconds()+"."+houzhui,i="https://cdn.jsdelivr.net/gh/MHuiG/imgbed/data/"+n,r={url:"https://api.github.com/repos/MHuiG/imgbed/contents/data/"+n,method:"PUT",timeout:0,headers:{Authorization:"Bearer "+t,"Content-Type":"text/plain"},data:'{\r\n "message": "upload",\r\n "content": "'+e+'"\r\n}'};$.ajax(r).done((function(e){imgurlmd="![]("+i+")";var t="<li>"+imgurlmd+"</li>";document.getElementById("neirong").innerHTML=t}))}function imgChange(e){var t=$("#key").val();let a=localStorage&&localStorage.getItem("ImgCache");a&&(a=JSON.parse(a),t||(t=a.k)),localStorage&&localStorage.setItem("ImgCache",JSON.stringify({k:t}));const n=new FileReader;n.onload=function(e){var a=e.target.result;base64url=a.replace(/(.*)?,/,""),houzhui=a.substring(a.indexOf("/")+1,a.indexOf(";")),uploadimg(base64url,t)},n.readAsDataURL(e.files[0])}document.addEventListener("paste",(function(e){var t=e.clipboardData&&e.clipboardData.items,a=null;if(t&&t.length)for(var n=0;n<t.length;n++)if(-1!==t[n].type.indexOf("image")){a=t[n].getAsFile();var i={},r=[];r.push(a),i.files=r,imgChange(i);break}}))</script> <input id="key"><div style="font-size:30px;display:inline;cursor:pointer" onclick="myimg.click()">🤣</div><div id="neirong"></div> <input type="file" id="myimg" onchange="imgChange(this)" style="visibility:hidden" accept="image/png,image/gif,image/jpeg">