From 926f2b571addaa33db2badba9d2f0c18d1a815e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Thu, 2 Nov 2023 01:10:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=82=B9=E5=87=BB=E4=B8=8B=E8=BD=BD=20?= =?UTF-8?q?B=20=E7=AB=99=E5=95=86=E5=9F=8E=E9=A6=96=E5=9B=BE=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bilibili-mall-cover-download.js | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bilibili-mall-cover-download.js diff --git a/bilibili-mall-cover-download.js b/bilibili-mall-cover-download.js new file mode 100644 index 0000000..d3fabc1 --- /dev/null +++ b/bilibili-mall-cover-download.js @@ -0,0 +1,69 @@ +// ==UserScript== +// @name BiliBili 商城首图下载 +// @namespace https://paul.ren +// @version 0.1 +// @description 下载透明手办图片到本地,可供上传到网站 +// @author You +// @match https://mall.bilibili.com/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com +// @grant none +// ==/UserScript== + +(function () { + 'use strict'; + + const styles = document.createElement("style"); + styles.innerHTML = "body { max-width: 600px; margin: auto; }"; + document.body.appendChild(styles); + + function downloadFile(url, filename) { + var xhr = new XMLHttpRequest(); + + xhr.open('GET', url, true); + xhr.responseType = 'blob'; + + xhr.onload = function () { + if (xhr.status === 200) { + var blob = xhr.response; + var link = document.createElement('a'); + link.href = window.URL.createObjectURL(blob); + link.download = filename; + link.click(); + } + }; + + xhr.send(); + } + + const getFirstImg = async () => { + await new Promise((resolve) => setTimeout(() => resolve(), 500)); + + const btn = document.querySelector(".bili-callapp-btn"); + + if (btn) { + const newBtn = document.createElement("div"); + newBtn.className = "bili-callapp-btn"; + + btn.style = "display: none !important;"; + newBtn.setAttribute('data-v-e55eac76', 1); + btn.parentElement.append(newBtn); + + newBtn.innerHTML = "下载首图"; + newBtn.onclick = (ev) => { + ev.preventDefault(); + const img = document.querySelector(".silde-item"); + const url = img.style.backgroundImage.replace("url(\"", "").replace("\")", ""); + + const href = new URL(location.href.replace("#noReffer", "&noReffer")); + const itemsId = href.searchParams.get("itemsId"); + + downloadFile(url, `${itemsId}.webp`); + + } + } + } + + if (location.href.includes("detail.html")) { + getFirstImg(); + } +})();