// ==UserScript==
// @name Image Downloader
// @name:zh-CN 图片下载器
// @name:zh-TW 图片下载器
// @name:ja 画像ダウンローダー
// @name:ko 이미지 다운로더
// @name:de Image Downloader
// @name:es Image Downloader
// @name:eo Image Downloader
// @name:fr Image Downloader
// @name:it Image Downloader
// @name:ru Image Downloader
// @name:vi Image Downloader
// @name:pt-BR Image Downloader
// @name:id Image Downloader
// @name:ar Image Downloader
// @name:bg Image Downloader
// @name:cs Image Downloader
// @name:tr Image Downloader
// @name:el Image Downloader
// @name:hu Image Downloader
// @name:th Image Downloader
// @namespace http://tampermonkey.net/
// @description You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:zh-CN 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
// @description:zh-TW 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
// @description:ja You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:ko You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:de You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:es You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:eo You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:fr You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:it You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:ru You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:vi You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:pt-BR You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:id You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:ar You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:bg You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:cs You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:tr You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:el You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:hu You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @description:th You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
// @version 1.90
// @author 桃源隐叟
// @include *
// @connect *
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @grant GM_download
// @require https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.2/dist/hotkeys.min.js
// @require https://cdn.bootcss.com/jszip/3.7.1/jszip.min.js
// @require https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.min.js
// @run-at document-end
// @match *
// @match https://www.bilibili.com/
// @match https://588ku.com/
// @homepageURL https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
// @supportURL https://greasyfork.org/zh-CN/scripts/419894/feedback
// @license GPLv3
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
var lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
var langSet;
var localization = {
zh: {
selectAll: "全选",
downloadBtn: "下载",
downloadMenuText: "打开脚本(Alt+w)",
zipDownloadBtn: "zip下载",
selectAlert:"请至少选中一张图片。",
fetchTip:"准备抓取canvas图片",
fetchCount1:`抓取canvas图片第`,
fetchCount2:'张',
fetchDoneTip1:"已选(0/",
fetchDoneTip1Type2:"已选(",
fetchDoneTip2:")张图片",
},
en: {
selectAll: "selectAll",
downloadBtn: "download",
downloadMenuText: "Open(Alt+w)",
zipDownloadBtn: "zip Download",
selectAlert:"Please at last select one image.",
fetchTip:"Ready to fetch canvas image.",
fetchCount1:`Fetch the`,
fetchCount2:' canvas image.',
fetchDoneTip1:"(0/",
fetchDoneTip1Type2:"(",
fetchDoneTip2:") Images selected",
}
}
if (lang.toLowerCase().includes("zh-")) {
langSet = localization.zh;
} else {
langSet = localization.en;
}
const autoBigImage={
bigImageArray:[],
defaultRules:[
{originReg:/(?<=(.+sinaimg\.(?:cn|com)\/))([\w\.]+)(?=(\/.+))/i,replacement:"large"},
{originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))_.+/i,replacement:""},
{originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+))(\.\w+)(?=(\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:""},
{originReg:/(?<=(.+360buyimg\.(?:cn|com)\/))(\w+\/)(?=(.+\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:"n0/"},
{originReg:/(?<=(.+hdslb\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))@.+/i,replacement:""},
],
replace(originImgUrls){
let that=this;
that.bigImageArray=originImgUrls;
that.bigImageArray.forEach(replaceByReg);
function replaceByReg(urlStr,urlIndex){
that.defaultRules.forEach((rule,ruleIndex)=>{
let bigImage=urlStr.replace(rule.originReg,rule.replacement);
bigImage&&that.bigImageArray.push(bigImage);
})
}
},
getBigImageArray(originImgUrls){
this.replace(originImgUrls);
let uniqueArray=Array.from(new Set(this.bigImageArray));
return uniqueArray;
},
showRules(){
}
}
GM_registerMenuCommand(langSet.downloadMenuText, wrapper);
hotkeys('alt+w', wrapper);
function wrapper() {
try {
document.querySelector(".tyc-image-container").remove();
} catch {
}
var imgUrls = [];
var bodyStr = document.body.innerHTML;
var imgSelected = [];
var zipImgSelected = [];
var imgWaitDownload = [];
var zipImgWaitDownload = [];
var widthFilter = { min: 0, max: 3000 };
var heightFilter = { min: 0, max: 3000 };
var filteredImgUrls = [];
var zipFilteredImgUrls = [];
try{
var zipFolder = new JSZip();
var zipSubFoler = zipFolder.folder('pics');
}
catch{
}
var fetchTip='';
try {
let imgEles = document.getElementsByTagName("img");
let canvasEles=document.getElementsByTagName("canvas");
for (let i = 0; i < imgEles.length; i++) {
////console.log(imgEles[i].src);
if (!imgUrls.includes(imgEles[i].src)) {
imgUrls.push(imgEles[i].src);
} else if (!imgUrls.includes(imgEles[i].srcset)) {
imgUrls.push(imgEles[i].srcset);
}
}
let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
for (let i = 0; i < imgRegs.length; i++) {
////console.log(imgRegs[i]);
if (!imgUrls.includes(imgRegs[i].replace(/"/g, ""))) {
imgUrls.push(imgRegs[i].replace(/"/g, ""));
}
}
if (window.location.href.includes("hathitrust.org")) {
let imgs = document.querySelectorAll(".image img");
if (imgs.length > 0) {
let canvas = document.createElement("canvas");
imgUrls = [];
for (let pi = 0; pi < imgs.length; pi++) {
canvas.width = imgs[pi].width;
canvas.height = imgs[pi].height;
canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
imgUrls.push(canvas.toDataURL("image/png"));
}
document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
} else {
}
}
if(window.location.href.toString().includes("manga.bilibili.com/")){
let iframeCanvas=``;
if(document.getElementById("tyc-insert-iframe")==null){
document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",``);
document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
}
}
let oldLength=imgUrls.length;
if(canvasEles.length>0){
fetchTip=langSet.fetchTip;
var completeFlag=0;
for(let j=0;j
.tyc-image-container{
position:fixed;
top:0px;
left:10%;
width:80vw;
z-index:2147483645;
background-color: #dedede;
border: 1px solid #aaa;
overflow:scroll;height:100%;
}
.tyc-image-container button{
border:1px solid #aaa;
border-radius:5px;
height:32px;line-height:32px;
margin:0px;padding:0 5px;
}
.tyc-image-container button:hover{
background-color: #f50;
color: #fff;
}
.control-section{
width:80vw;
z-index:2147483646;
position:fixed;
top:0px;
left:10%;
display: flex;
flex-direction: column;
justify-content: center;
line-height:40px;
background:#eee;border:1px solid #aaa;border-radius:2px;
}
.control-section-sub{
display: flex;
margin-bottom: 5px;
}
.tyc-normal-section{
display: flex;
align-items: center;
flex-direction: row;
justify-content: flex-start;
flex-wrap: nowrap;
align-content: normal;
}
.btn-download{
border:1px solid #aaa;border-radius:5px;
height:32px;line-height:32px;
margin:0px;padding:0 5px;
}
.btn-zipDownload{
border:1px solid #aaa;border-radius:5px;
height:32px;line-height:32px;
margin:0px;padding:0 5px;
}
.btn-close{
font-size:20px;position:absolute;
right:30px;top:4px;
height:32px;line-height:32px;
margin:0px;
border-radius:10px;border:1px solid #aaa;
width:30px;
}
.tyc-image-wrapper{
margin-top:82px;display:flex;justify-content:center;
align-items:center;flex-wrap:wrap;
}
.tyc-input-checkbox{
background-color: initial;
cursor: default;
appearance: auto;
box-sizing: border-box;
margin: 3px 3px 3px 4px;
padding: initial;
border: initial;
}
.tyc-extend-set{
padding: 10px;
border-top: 1px solid rgba(100,100,100,0.1);
}
.tyc-extend-set{
display: none;
align-items: stretch;
flex-direction: column;
justify-content: flex-start;
flex-wrap: nowrap;
padding: 5px;
width: auto;
}
.tyc-extend-set-container{
display: flex;
align-items: flex-start;
flex-direction: column;
justify-content: flex-start;
flex-wrap: nowrap;
align-content: normal;
border: 1px solid rgba(100,100,100,0.5);
padding: 5px;
margin-bottom: 5px;
}
.tyc-autobigimg-set{
display: flex;
align-items: flex-start;
flex-direction: column;
justify-content: flex-start;
flex-wrap: nowrap;
align-content: normal;
border: 1px solid rgba(100,100,100,0.5);
padding: 5px;
}
.tyc-set-domain{
display: flex;
align-items: flex-start;
flex-direction: column;
justify-content: flex-start;
flex-wrap: nowrap;
align-content: normal;
margin: 5px;
padding: 5px;
border: 1px solid rgba(100,100,100,0.3);
width: 95%;
}
.tyc-abi-title{
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
}
.tyc-abi-domain-title{
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 95%;
border-bottom: 1px solid #ddd;
}
.tyc-set-replacerule{
display: flex;
flex-direction: row;
justify-content: space-start;
align-items: center;
margin-bottom: 3px;
}
.tyc-set-replacerule *,.tyc-set-replacerule button{
margin-left: 5px;
}