@@ -14,6 +14,16 @@ if("serviceWorker" in navigator) {
1414 } ) ;
1515}
1616
17+ function fileReader ( blob ) {
18+ return new Promise ( ( resolve , reject ) => {
19+ let reader = new FileReader ( )
20+ reader . onload = ( e ) => {
21+ resolve ( e . target . result )
22+ }
23+ reader . readAsDataURL ( blob )
24+ } )
25+ }
26+
1727function httpGetAsync ( theUrl , callback ) {
1828 var xmlHttp = new XMLHttpRequest ( ) ;
1929 xmlHttp . onreadystatechange = function ( ) {
@@ -147,6 +157,18 @@ async function html2Img(html) {
147157 div . id = 'capture' ;
148158 div . setAttribute ( 'style' , 'padding: 30px 20px;background: #000;color: #f7f4cb;font-family: "LXGW WenKai";max-width: 768px;margin: auto;' ) ;
149159 div . innerHTML = html ;
160+ let containImages = div . getElementsByTagName ( 'img' ) ;
161+ for ( let i = 0 ; i < containImages . length ; i ++ ) {
162+ let originImg = containImages [ i ] ;
163+ let originImgSrc = originImg . getAttribute ( 'src' ) ;
164+ let imgDataURL = await fetch ( originImgSrc )
165+ . then ( function ( response ) {
166+ return response . blob ( ) ;
167+ } ) . then ( function ( blob ) {
168+ return fileReader ( blob ) ;
169+ } ) ;
170+ originImg . src = imgDataURL ;
171+ }
150172 addDatePart ( div ) ;
151173 let footer = document . createElement ( 'div' ) ;
152174 footer . setAttribute ( 'style' , 'display: flex;flex-direction: row;justify-content: space-between;align-items: center;margin-top: 20px;padding-top: -20px;padding-top: -20px;border-top-style: dashed;border-top-width: 1px;padding-top: 10px;' ) ;
0 commit comments