拆解页面脚本和应用层脚本的强关联

This commit is contained in:
aixianling
2024-01-10 15:02:05 +08:00
parent 53e8d2da74
commit eaea055f6c
3 changed files with 7211 additions and 7137 deletions

View File

@@ -2,7 +2,26 @@
利用chrome的fetch来避免跨域
**/
import {getImageBlob} from "@/utils/image";
/**
* 根据图片URL获取Blob对象
* @param imageUrl
* @returns {Promise<unknown>}
*/
function getImageBlob(imageUrl) {
return new Promise((resolve) => {
fetch(imageUrl).then((response) => response.blob()) // 将响应转换为Blob对象
.then((blobData) => {
const fileName = imageUrl.match(/\/([^/]+)$/).at(-1)
const reader = new FileReader();
// 读取Blob对象的内容
reader.onloadend = function () {
const image = {blobData, fileName}
resolve({image});
};
reader.readAsArrayBuffer(blobData); // 将Blob对象作为参数传递给FileReader的readAsArrayBuffer()方法
})
});
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type == 'api') {