油猴脚本使用 async 入口模版
// ==UserScript==
// @name         Image Converter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Convert images to AVIF format
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';

  async function convert(sourceType, outputType, fileBuffer) {
    const worker = new Worker(new URL(
      "https://html5.1000w123.com/assets/worker-jGUFv2Mo.js"

    ), { type: "module" });
    worker.postMessage({ sourceType, outputType, fileBuffer });
    return new Promise((resolve, reject) => {
      worker.addEventListener("message", (event) => {
        resolve(event.data);
      });
      worker.addEventListener("error", reject);
    });
  }

  function blobToBase64(blob) {
    return new Promise((resolve, _) => {
      const reader = new FileReader();
      reader.onloadend = () => resolve(reader.result);
      reader.readAsDataURL(blob);
    });
  }

  async function showOutput(imageBuffer, outputType) {
    const preview = document.createElement("div");
    preview.id = "preview";
    document.body.appendChild(preview);

    const imageBlob = new Blob([imageBuffer], { type: `image/${outputType}` });
    const base64String = await blobToBase64(imageBlob);
    const previewImg = document.createElement("img");
    previewImg.src = base64String;
    preview.innerHTML = "";
    preview.appendChild(previewImg);
  }

  async function loadImage(url) {
    const response = await fetch(url);
    const blob = await response.blob();
    return await blob.arrayBuffer();
  }

  async function main() {
    const imageUrl = "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"; // 替换为你的图片 URL
    const outputType = "avif";
    const fileBuffer = await loadImage(imageUrl);
    const imageBuffer = await convert("jpeg", outputType, fileBuffer); // 假设源类型是 jpeg
    showOutput(imageBuffer, outputType);
  }

  main();
})();
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇