// ==UserScript== // @name GM_xhr读取图片显示例子 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://github.com/Owyn/HandyImage/issues/451 // @icon https://www.google.com/s2/favicons?domain=github.com // @grant unsafeWindow // @grant GM_xmlhttpRequest // ==/UserScript== function arrayBufferToBase64(buffer) { var binary = ''; var bytes = new Uint8Array(buffer); var len = bytes.byteLength; for (var i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]); } return window.btoa(binary); } GM_xmlhttpRequest({ url:'https://i.piccy.info/i9/ac44f4a35e09a0d62fc0365dd33e7828/1635318743/16734/1446202/2021_10_27_10_07_37.jpg', responseType:'arraybuffer', method :"GET", headers: { }, onload:function(xhr){ let url= arrayBufferToBase64(xhr.response); var img=document.createElement('img') img.src='data:image/jpeg;base64,'+url; document.body.append(img) } });