// ==UserScript== // @name bcy(半次元)打包原图 // @version 1.1.1 // @description 请先安装"zip格式支持",原图包可从详细页或图片封面下载。 // @author opentdoor // @match http://bcy.net/* // @grant none // @namespace https://greasyfork.org/users/92069 // @downloadURL none // ==/UserScript== var gl = {}; (function () { 'use strict'; function DownLoad(url, progress, callback) { try { var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function (e) { if (this.readyState == 4) { callback(this.response, this.status); } }; xhr.responseType = 'blob'; xhr.onprogress = function (e) { progress(e); }; xhr.send(null); } catch (ex) { callback(null, 500); } } function urlsToZip(urlFiles, zipName, av) { var zipWriter, index = 0; var writer = new zip.BlobWriter(); function onError() { console.log(arguments); } function downloadProgress(e) { if (e.lengthComputable) { av.innerHTML = "正在打包第" + (index + 1) + "个:" + (e.loaded / e.total * 80).toFixed(0) + "%"; } } function zipProgress(current, total) { av.innerHTML = "正在打包第" + (index) + "个:" + (80 + 20 * current / total).toFixed(0) + "%"; } function zipEnd() { zipWriter.close(function (blob) { saveFile(blob, zipName); }); av.isdown = false; av.innerHTML = "打包带走"; } zip.createWriter(writer, function (wr) { zipWriter = wr; }, onError); function saveFile(blob, filename) { if (window.navigator.msSaveBlob) { window.navigator.msSaveBlob(blob, filename); } else { var a = document.createElement("a"); var url = URL.createObjectURL(blob); a.href = url; a.download = filename; a.click(); URL.revokeObjectURL(url); } } function nextFile() { var file = urlFiles[index]; DownLoad(file.url, downloadProgress, function (blob, status) { index++; if (status == 200) { zipWriter.add(file.name, new zip.BlobReader(blob), function () { if (index < urlFiles.length) nextFile(); else zipEnd(); }, zipProgress); } else { file.tryTime = (file.tryTime || 0) + 1; if (file.tryTime < 4) index--; if (!av.oldclick) { av.oldclick = av.onclick; } av.onclick = function () { av.onclick = av.oldclick; if (index < urlFiles.length) nextFile(); else zipEnd(); }; setTimeout(function () { var ff = urlFiles[index]; av.innerHTML = "第" + (index + 1) + "个下载失败,点击重试(" + (ff.tryTime || 0) + "次)!"; }, 60); } }); } nextFile(); } gl.urlsToZip = urlsToZip; })(); (function () { 'use strict'; var p = $(".js-content-img-wrap"); var title = document.title.replace(/\|.*$/i, '').replace(/(^\s*|\s*$)/ig, ""); var cn = $(".l-detailUser-name .blue1").html(); if (cn) title += "-cn_" + cn; title = title.replace(/[\\\/\?\<\>\|\*"]/ig, '_'); var urls = []; var imgs = $(".content-img-wrap img"); var i = 1; imgs.each(function () { var $this = $(this); var url = this.src.replace(/\/w650$/i, ''); var ex = /\.\w+$/i.exec(url); var name = title + (i > 9 ? i : '0' + i) + (ex && ex.length ? ex[0] : ".jpg"); urls.push({ name: name, url: url }); i++; }); if (p.length && urls.length) { var av = document.createElement('a'); p.css({ "position": "relative" }); av.href = "javascript:;"; av.innerHTML = "打包带走"; av.style.width = "250px"; $("#phone").html('').append(av); av.onclick = function (e) { if (!this.isdown) { this.isdown = true; gl.urlsToZip(urls, title + ".zip", this); } }; } })(); (function () { 'use strict'; function getInfo(url, an, callback) { try { var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onprogress = function (e) { if (e.lengthComputable) { an.innerHTML = "开始解析链接:" + (e.loaded / e.total * 100).toFixed(0) + "%"; } }; var urls = []; xhr.onreadystatechange = function (e) { if (this.readyState == 4) { if (this.status == 200) { var resText = this.responseText.replace(/[\r\n]*/g, ""); var i1 = resText.indexOf("js-content-img-wrap"); var i2 = resText.indexOf(" i3 && i3 != -1) { i2 = resText.indexOf("/ig; var str = resText.substring(i1, i2); i1 = resText.indexOf('