// ==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 Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:zh-CN 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,右键失效或者图片不能另存的网站,用脚本均可以提取并下载。额外功能:zip下载/自动大图。详细见脚本描述(目前只适合chrome+tampermonkey,其他组合多少有问题)
// @description:zh-TW 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,右键失效或者图片不能另存的网站,用脚本均可以提取并下载。额外功能:zip下载/自动大图。详细见脚本描述(目前只适合chrome+tampermonkey,其他组合多少有问题)
// @description:ja Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:ko Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:de Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:es Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:eo Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:fr Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:it Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:ru Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:vi Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:pt-BR Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:id Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:ar Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:bg Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:cs Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:tr Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:el Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:hu Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @description:th Images can be extracted and batch downloaded from most websites. Especially for websites the right click fails or image can not save. Extra features: zip download / auto-enlarge image. See the script description at info page (only suitable for chrome+tampermonkey)
// @version 2.01
// @author 桃源隐叟
// @include *
// @connect *
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_download
// @require https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.2/dist/hotkeys.min.js
// @require https://cdn.bootcdn.net/ajax/libs/jszip/3.7.1/jszip.min.js
// @require https://cdn.bootcdn.net/ajax/libs/FileSaver.js/2.0.5/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:")张图片",
regRulePlace:"输入待替换正则",
regReplacePlace:"输入替换它的字符串或者函数",
zipOptionDesc:"勾选使用zip下载后,会请求跨域权限,否则zip下载基本下载不到图片。",
zipCheckText:"使用zip下载",
downloadUrlFile:"下载图片地址",
moreSetting:"更多设置",
autoBitImgModule:"自动大图设置模块",
defaultSettingRule:"设置默认规则",
exportCustomRule:"导出自定规则",
importCustomRule:"导入自定规则",
fold:"收起",
},
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",
regRulePlace:"enter reg express",
regReplacePlace:"enter replace string or function",
zipOptionDesc:"when zip option checked,will request cors right,otherwise zipDownload can not get pics",
zipCheckText:"Use ZipDownload",
downloadUrlFile:"Download Imgs Url",
moreSetting:"More Setting",
autoBitImgModule:"AutoBigImageModule",
defaultSettingRule:"SetDefaultRule",
exportCustomRule:"exportCustomRule",
importCustomRule:"importCustomRule",
fold:"fold",
}
}
if (lang.toLowerCase().includes("zh-")) {
langSet = localization.zh;
} else {
langSet = localization.en;
}
const autoBigImage={
bigImageArray:[],
defaultRules:[
{originReg:/(?<=(.+sinaimg\.(?:cn|com)\/))([\w\.]+)(?=(\/.+))/i,replacement:"large",tip:"用于新浪微博"},
{originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))_.+/i,replacement:"",tip:"用于淘宝系网站"},
{originReg:/(.+alicdn\.(?:cn|com)\/.+)(\.\d+x\d+)(\.(jpg|jpeg|gif|png|bmp|webp)).*/i,replacement:(match,p1,p2,p3)=>p1+p3,tip:"用于1688"},
{originReg:/(?<=(.+360buyimg\.(?:cn|com)\/))(\w+\/)(?=(.+\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:"n0/",tip:"用于京东"},
{originReg:/(?<=(.+hdslb\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))@.+/i,replacement:"",tip:"用于B站"},
],
defaultRulesChecked:[
],
userRules:[],
userRulesChecked:[],
replace(originImgUrls){
let that=this;
that.bigImageArray=[];
let tempArray=Array.from(new Set(originImgUrls)).filter(item=>item&&item);
that.setRulesChecked();
//console.log(that.bigImageArray);
tempArray.forEach(replaceByReg);
function replaceByReg(urlStr,urlIndex){
//if(!urlStr)return;
if(urlStr.includes("data:image/"))return;
that.defaultRules.forEach((rule,ruleIndex)=>{
if(that.defaultRulesChecked[ruleIndex]!=="checked"){
that.bigImageArray.push(urlStr);
return;
}
let bigImage=urlStr.replace(rule.originReg,rule.replacement);
if(bigImage!==urlStr){
that.bigImageArray.push(urlStr);
that.bigImageArray.push(bigImage);
}else{
that.bigImageArray.push(urlStr);
}
})
that.userRules.forEach((rule,ruleIndex)=>{
if(that.userRulesChecked[ruleIndex]!=="checked"){
that.bigImageArray.push(urlStr);
return;
}
let bigImage=urlStr.replace(rule.originReg,rule.replacement);
if(bigImage!==urlStr){
that.bigImageArray.push(urlStr);
that.bigImageArray.push(bigImage);
}else{
that.bigImageArray.push(urlStr);
}
})
}
},
getBigImageArray(originImgUrls){
this.replace(originImgUrls);
let uniqueArray=Array.from(new Set(this.bigImageArray));
return uniqueArray;
},
showDefaultRules(){
let that=this;
let defaultContainer=document.body.querySelector(".tyc-set-domain-default");
that.setRulesChecked();
this.defaultRules.forEach((v,i)=>{
let rulesHtml=`
${v.tip}
`
defaultContainer.insertAdjacentHTML("beforeend",rulesHtml);
})
},//showDefaultRules
showRules(containerName,rulesType,checkType,checkClassName){
let that=this;
let Container=document.body.querySelector("."+containerName);
that.setRulesChecked();
that.setCustomRules();
//console.log(that.userRules);
//console.log(that);
that[rulesType].forEach((v,i)=>{
//console.log(that[checkType])
let rulesHtml=`