Last active
August 28, 2022 14:10
-
-
Save kirileec/4fa28be58e0dcff1290b77fdf10f0b48 to your computer and use it in GitHub Desktop.
图集岛看图下载
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name 图集岛看图下载 | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.2 | |
| // @description VIP并且附带点击下载(文件名不是1.jpg这种样子) | |
| // @author linx | |
| // @include /^https?://.*\.tujidao.* | |
| // @connect tjg.gzhuibei.com | |
| // @grant GM_xmlhttpRequest | |
| // @grant unsafeWindow | |
| // @license MIT | |
| // ==/UserScript== | |
| (function () { | |
| "use strict"; | |
| var h = 'https://www.tujidao03.com/'; | |
| var html1 = | |
| '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>img_title</title>' + | |
| "<style>img {vertical-align: top;text-align: center;}" + | |
| ".imgbox{position: relative;overflow: hidden;}" + | |
| ".imgbox img{max-width: 100%}" + | |
| ".imgdown{position: absolute;left: 90px;top: 5px;cursor:pointer;background: #17A1FF;background: rgba(23,161,255,0.5);z-index: 100;padding: 0px 5px;color: #f9f9f9;border-radius: 2px;}"+ | |
| ".imgnum{position: absolute;left: 5px;top: 5px;background: #17A1FF;background: rgba(23,161,255,0.5);z-index: 100;padding: 0px 5px;color: #f9f9f9;border-radius: 2px;}" + | |
| "a:link{color:pink;}a:visited{color:purple;}" + | |
| "</style></head>" + | |
| '<body bgcolor="#27282d"><div align="center">'; | |
| var pic_base = | |
| "<div class='imgbox'><div class='imgnum'>{imgnum}</div><div class='imgdown' onclick='download1({pic_id},{num})'>下载"+ | |
| "</div><img alt='{pic_id}_{num}.jpg' src='https:///tjg.gzhuibei.com/a/1/{pic_id}/{num}.jpg'></div>"; | |
| // 下载函数 | |
| function download(imageTag,imageId) { | |
| console.log('download') | |
| GM_xmlhttpRequest({ | |
| method: "GET", | |
| url: `https://tjg.gzhuibei.com/a/1/${imageTag}/${imageId}.jpg`, | |
| headers: { | |
| referer: h | |
| }, | |
| responseType:"blob", | |
| onload: function(xhr) { | |
| var r = xhr.responseText, | |
| data = new Uint8Array(r.length), | |
| i = 0; | |
| while (i < r.length) { | |
| data[i] = r.charCodeAt(i); | |
| i++; | |
| } | |
| let blob = new Blob([data], { | |
| type: "image/jpeg" | |
| }); | |
| var blobURL = window.URL.createObjectURL(blob); | |
| console.log(blobURL) | |
| var downA = document.createElement("a"); | |
| downA.href = blobURL; | |
| downA.setAttribute("download", `${imageTag}_${imageId}.jpg`); | |
| downA.click(); | |
| window.URL.revokeObjectURL(blobURL); | |
| } | |
| }) | |
| } | |
| // 打开新窗口展示图片 | |
| var createnew = function (num, pic_id, tags) { | |
| var pic_new = pic_base.replaceAll("{pic_id}", pic_id); | |
| var tagHtml = []; | |
| var last = tags.pop(); | |
| for (let t of tags) { | |
| tagHtml.push(t.outerHTML); | |
| } | |
| tagHtml.push(last.innerText); | |
| tagHtml = | |
| "<div style='color:white;font-size:25px'>" + | |
| tagHtml.join(" / ") + | |
| "</div>"; | |
| var imgs = []; | |
| for (var i = 1; i <= num; i++) { | |
| imgs.push( | |
| pic_new.replaceAll("{num}", i).replace("{imgnum}", ` [${i}/${num}]`) | |
| ); | |
| } | |
| let html = html1.replace("img_title", `${last.innerText} - ${num}P @ ${pic_id}`); | |
| html += imgs.join("\n"); | |
| var w = window.open(h); | |
| w.onload = () => { | |
| w.download1 = download; | |
| w.document.write(''); | |
| w.document.write(tagHtml + html); | |
| w.document.close(); | |
| }; | |
| }; | |
| // 小图链接 | |
| var liImages = document.querySelectorAll('div.hezi>ul>li>a') | |
| for (const img of liImages) { | |
| //第一个a | |
| img.onclick = function (){ | |
| var _parentNode = img.parentNode; | |
| // 获取数量 | |
| var num = _parentNode.querySelector('span.shuliang').innerText.split("P")[0] | |
| num = parseInt(num); | |
| // id | |
| var id = img.getAttribute("href"); | |
| id = id.split("id=")[1]; | |
| img.removeAttribute("href"); // 删除链接,防止跳转 | |
| //丢掉最后一个 | |
| var tags = _parentNode.querySelectorAll('p>a'); | |
| createnew(num, id,[...tags]); | |
| } | |
| } | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2022-08-28 更新