Greasy Fork

Bunkrr DL Button

Add a direct download button below each thumbnails

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

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