Greasy Fork

Bunkrr DL Button

Add a direct download button below each thumbnails

目前为 2024-01-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         Bunkrr DL Button
// @version      2.2
// @description  Add a direct download button below each thumbnails
// @include      https://bunkr.tld/a/*
// @namespace    bunkrr
// @license      MIT
// @grant        GM_download
// ==/UserScript==

const o=".grid-";const t="_box";const n=`${o}images${t}-img`;const x=".";const s="*";const c="images";const $=">";const e="div";const d="p";const i="of-type";const r="-";const a="first";const m="last";const p=":";const u=`${o}${c} ${$} ${s}`;const f="/";const l="scope";const b=`${o}${c}${t}`;const g=`${e}${p}${m}${r}${i}`;const w=`${d}${p}${a}${r}${i}`;const h=`${b} ${$} ${g} ${$} ${w}`;const v=`${p}${l} ${$} ${s}`;const j=".";const y="src";const O="href";const k="https";const B=/i-(\w+).(\w+).(\w+)\/thumbs\/(.*).png/;const D=".";const _=/-(?!.*-)(.*?)(?=\.)/;const A="://";const G="/";const M="#ffd369";const R={display:"flex",flexDirection:"column",border:"none",padding:"0"};const q="div";const z={position:"relative",padding:"0.625rem",paddingBottom:"0",border:`solid ${M} 2px`,borderBottom:"none"};const C="a";const E="Download";const F={border:`solid ${M} 2px`,borderRadius:"0px 0px 20px 20px",width:"100%"};(()=>{"use strict";const o=[...document.querySelectorAll(n)];const l=document.querySelectorAll(u);const b=[...document.querySelectorAll(h)].map(o=>o.textContent.split(".").pop());o.map((o,t)=>{const n=o.getAttribute(y);const s=n.match(B);const[c,$,e,d,i]=s;const r=`${k}${A}${$}${D}${e}${j}${d}${f}${i}${x}${b[t]}`;const a=l[t];Object.assign(a.style,R);const m=a.querySelectorAll(v);m[m.length-1].style.bottom="0";const p=document.createElement(q);Object.assign(p.style,z);p.append(...m);const u=document.createElement(C);u.setAttribute(O,r);u.textContent=E;H(u);Object.assign(u.style,F);a.append(p,u)})})();function H(c){c.addEventListener("click",async o=>{o.preventDefault();const t=c.getAttribute(O);const n=t.split(G).pop();const s=n.replace(_,"");GM_download({url:t,name:s,o:true,onerror:o=>console.error(o)})});c.addEventListener("mouseover",o=>{o.target.style.backgroundColor=M;o.target.style.color="black"});c.addEventListener("mouseout",o=>{o.target.style.backgroundColor="";o.target.style.color="white"})}