GBT gallery downloader (GBTGD)

Creates a button to downloads all images from gallery in a .zip file.

2024-11-29 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         GBT gallery downloader (GBTGD)
// @namespace    _pc
// @version      4.9
// @license      MIT
// @description  Creates a button to downloads all images from gallery in a .zip file.
// @author       verydelight
// @match        *://*.gayboystube.com/galleries/*
// @icon         https://www.gayboystube.com/favicon.ico
// @run-at       document-end
// @grant        GM.xmlHttpRequest
// @grant        GM_download
// @grant        GM_xmlHttpRequest
// @grant        GM.download
// @require      https://update.greasyfork.org/scripts/473358/1237031/JSZip.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js
// ==/UserScript==
'use strict';
window.onload = function(){
	var zip = new JSZip();
	let button = document.createElement("button");
    let downloadStatus = document.createElement("div");
	button.append("Download Gallery");
	button.setAttribute("type","button");
	button.addEventListener ("click", fullSize, false);
	document.getElementById('tab_video_info').append(button);
	async function downloadFile(url, filename,iCurr,iMax) {
		try {
			const response = await GM.xmlHttpRequest({
				method: 'GET',
				responseType: 'blob',
				url: url,
				headers: {
					"Content-Type": "image/jpeg", "Accept": "image/jpeg"
				},
			});
            //console.log("GBTGD: Downloaded: ",filename,iCurr)
            //console.log("GBTGD: Response Headers; ",response.headers);
			const blob = new Blob([response.response],{type: 'image/jpeg'});
			zip.file(filename, blob, {binary: true})
            //console.log("GBTGD Zip: ", zip,iCurr,iMax)
		} catch (err) {
			console.error("GBTGD: Error in fetching and downloading file: ",iCurr," " , err);
		}
		if(iCurr==iMax-1){
            downloadStatus.innerHTML = "Now creating zip-file and sending for download...";
			await zip.generateAsync({ type: "blob", compression: "DEFLATE", compressionOptions: { level: 6 } }).then(content => saveAs(content, "GBT_gallery"));
            downloadStatus.innerHTML = "Download complete!";
		}
	}
	async function fullSize(){
        button.style.visibility='hidden';
        document.getElementById('tab_video_info').append(downloadStatus);
		var images = document.getElementById('album_view_album_view').getElementsByTagName('img');
		var iMax = images.length;
        var downloadTime = 0;
        var downloadEstimate = 0;
        var downloadEstimateMins = 0;
        var downloadEstimateSecs = 0;
        var counteri = 0;
        //console.log("GBTGD: Found pix: ",iMax)
		for (var i=0, n=images.length;i<n;i++) {
			var currentSrc = images[i].getAttribute('data-src');
			var pattern1 = /\/thumbs/;
			var pattern2 = /\/main\/\d{1,4}x\d{1,4}/;
			if (currentSrc.match(pattern1)) {
				currentSrc = currentSrc.replace(pattern1, '');
			};
			if (currentSrc.match(pattern2)) {
				currentSrc = currentSrc.replace(pattern2, '/sources');
			};
			var fileName = currentSrc.split('/');
			fileName = fileName[fileName.length-1];
            //console.log("GBTGD: Downloading: ",fileName,i)
            counteri = i+1;
            if (downloadTime==0){
                downloadStatus.innerHTML = "Downloading & zipping image "+ counteri +"/"+ iMax;
            }else{
                if (downloadEstimateMins>0) {
                    downloadStatus.innerHTML = "Downloading & zipping image "+ counteri +"/"+ iMax +" (Estimated remaining time: "+ downloadEstimateMins +":"+ downloadEstimateSecs +" minutes)";
                }else{
                    downloadStatus.innerHTML = "Downloading & zipping image "+ counteri +"/"+ iMax +" (Estimated remaining time: "+ downloadEstimateSecs +" seconds)";
                }
            }
			var downloadStart = Date.now();
            await downloadFile(currentSrc,fileName,i,iMax);
            var downloadEnd = Date.now();
            downloadTime += downloadEnd-downloadStart;
            downloadEstimate = Math.round(((((downloadTime/(i+1))*iMax)-downloadTime)/1000)*1.05);
            downloadEstimateMins = Math.floor(downloadEstimate/60);
            downloadEstimateSecs = Math.round(downloadEstimate-(downloadEstimateMins*60));
            downloadEstimateSecs = String(downloadEstimateSecs).padStart(2,"0");
		};
	}
};