function init() {
    if (window.location.href.startsWith('https://www.aliexpress.us/item/')) {
        const popup = document.createElement("div")
        popup.innerText = "下载图片"
        const styles = {
            position: "fixed",
            right: '10px',
            top: '60px',
            zIndex: 9999,
            padding: "8px",
            background: "#409EFF",
            color: "#fff",
            borderRadius: "8px",
            cursor: "pointer"
        }
        for (const e in styles) {
            popup.style[e] = styles[e]
        }

        popup.addEventListener('click', async () => {
            let obj = window.runParams.data;
            let id = obj.productInfoComponent.idStr

            var baseList = [];
            var downloadList = []

            var imgObjList = document.querySelectorAll('#product-description img')
            for (var i = 0; i < imgObjList.length; i++) {
                baseList.push({type: 0, index: i+1, src: imgObjList[i].src})
            }

            for (var j = 0; j < obj.imageComponent.imagePathList.length; j++) {
                baseList.push({type: 1, index: j+1, src: obj.imageComponent.imagePathList[j]})
            }

            var video = document.querySelector('video')
            if (video) {
                baseList.push({type: 2, index: 1, src: video.src})
            }

            var zip = new JSZip();
            var imgsBanner = zip.folder("轮播图");
            var imgsDetail = zip.folder("详情图");
            var videos = zip.folder("视频");
            for (var k = 0; k < baseList.length; k++) {
                let type = baseList[k].type
                let index = baseList[k].index
                if (type == 2) {
                    let x = new XMLHttpRequest()
                    x.open('GET', baseList[k].src, true)
                    x.responseType = 'blob'
                    x.onload = (e) => {
                        downloadList.push({type: type, index: index, data: x.response});
                        if (downloadList.length === baseList.length && downloadList.length > 0) {
                            for (let l = 0; l < downloadList.length; l++) {
                                if (downloadList[l].type == '0') {
                                    imgsDetail.file(`详情图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                                } else if (downloadList[l].type == '1') {
                                    imgsBanner.file(`轮播图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                                } else if (downloadList[l].type == '2') {
                                    videos.file(`视频.mp4`, downloadList[l].data, { Blob: true });
                                }
                            }
                            zip.generateAsync({ type: "blob" }).then(function (content) {
                              // see FileSaver.js
                              saveAs(content, "aliexpress_" + id + ".zip");
                            });
                        }
                    }
                    x.send()
                } else {
                    let image = new Image();
                    // 解决跨域 Canvas 污染问题
                    image.setAttribute("crossOrigin", "anonymous");
                    image.onload = function () {
                      let canvas = document.createElement("canvas");
                      canvas.width = image.width;
                      canvas.height = image.height;
                      let context = canvas.getContext("2d");
                      context.drawImage(image, 0, 0, image.width, image.height);
                      let url = canvas.toDataURL(); // 得到图片的base64编码数据
                      canvas.toDataURL("image/png");
                      downloadList.push({type: type, index: index, data: url.substring(22)}); // 去掉base64编码前的     data:image/png;base64,
                      if (downloadList.length === baseList.length && downloadList.length > 0) {
                        for (let l = 0; l < downloadList.length; l++) {
                            if (downloadList[l].type == '0') {
                                imgsDetail.file(`详情图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                            } else if (downloadList[l].type == '1') {
                                imgsBanner.file(`轮播图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                            }  else if (downloadList[l].type == '2') {
                                videos.file(`视频.mp4`, downloadList[l].data, { Blob: true });
                            }
                        }
                        zip.generateAsync({ type: "blob" }).then(function (content) {
                          // see FileSaver.js
                          saveAs(content, "aliexpress_" + id + ".zip");
                        });
                      }
                    };
                    image.src = baseList[k].src;
                }
              }
        })
        document.body.appendChild(popup)
    } else if (window.location.href.startsWith('https://www.amazon.com/')) {
        var content = document.getElementById('ATFCriticalFeaturesDataContainer').innerHTML
        content = content.substring(content.indexOf('jQuery.parseJSON('))
        content = content.substring(content.indexOf("("))
        content = content.substring(2, content.indexOf("');"))
        let obj = JSON.parse(content)
        let colorImages = obj.colorImages
        if (colorImages) {
            const popup = document.createElement("div")
            popup.innerText = "下载图片"
            const styles = {
                position: "fixed",
                right: '10px',
                top: '60px',
                zIndex: 9999,
                padding: "8px",
                background: "#409EFF",
                color: "#fff",
                borderRadius: "8px",
                cursor: "pointer"
            }
            for (const e in styles) {
                popup.style[e] = styles[e]
            }

            popup.addEventListener('click', async () => {
                var baseList = [];
                var downloadList = []

                var zip = new JSZip();
                var imgsBanner = zip.folder("轮播图");
                var imgsDetail = zip.folder("详情图");
                // var videos = zip.folder("视频");

                for (let i in colorImages) {
                    let folderName = imgsBanner.folder(i)
                    let item1 = colorImages[i]
                    let index = 0
                    for (let j in item1) {
                        let item2 = item1[j]
                        baseList.push({type: 1, index: ++index, src: item2.hiRes, folder: folderName})
                    }
                }

                var imgObjList = document.querySelectorAll('div.aplus-v2 img')
                for (var i = 0; i < imgObjList.length; i++) {
                    baseList.push({type: 0, index: i+1, src: imgObjList[i].getAttribute('data-src') || imgObjList[i].src, folder: imgsDetail})
                }

                for (var k = 0; k < baseList.length; k++) {
                    let type = baseList[k].type
                    let index = baseList[k].index
                    let folder = baseList[k].folder

                    let image = new Image();
                    // 解决跨域 Canvas 污染问题
                    image.setAttribute("crossOrigin", "anonymous");
                    image.onload = function () {
                      let canvas = document.createElement("canvas");
                      canvas.width = image.width;
                      canvas.height = image.height;
                      let context = canvas.getContext("2d");
                      context.drawImage(image, 0, 0, image.width, image.height);
                      let url = canvas.toDataURL(); // 得到图片的base64编码数据
                      canvas.toDataURL("image/png");
                      downloadList.push({type: type, index: index, folder: folder, data: url.substring(22)}); // 去掉base64编码前的     data:image/png;base64,
                      if (downloadList.length === baseList.length && downloadList.length > 0) {
                        for (let l = 0; l < downloadList.length; l++) {
                            if (downloadList[l].type == '0') {
                                downloadList[l].folder.file(`详情图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                            } else if (downloadList[l].type == '1') {
                                downloadList[l].folder.file(`轮播图${downloadList[l].index}.png`, downloadList[l].data, { base64: true });
                            }
                        }
                        zip.generateAsync({ type: "blob" }).then(function (content) {
                          // see FileSaver.js
                          saveAs(content, "amazon.zip");
                        });
                      }
                    };
                    image.src = baseList[k].src;
                }
            })
            document.body.appendChild(popup)
        }
    }
}

init();