khinsider batch downloader

batch download for downloads.khinsider.com originalsoundtracks

Zainstaluj skrypt?
Skrypt zaproponowany przez autora

Może Ci się również spodobać. anime1-downloader

Zainstaluj skrypt

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name              khinsider batch downloader
// @name:zh-TW        khinsider 批量下載器
// @namespace         https://blog.maple3142.net/
// @description       batch download for downloads.khinsider.com originalsoundtracks
// @description:zh-TW 批量下載 downloads.khinsider.com 的原聲帶
// @version           0.2.0
// @author            maple3142
// @match             https://downloads.khinsider.com/game-soundtracks/album/*
// @require           https://cdn.jsdelivr.net/npm/[email protected]/dist/ponyfill.min.js
// @require           https://cdn.jsdelivr.net/npm/[email protected]/StreamSaver.min.js
// @require           https://cdn.jsdelivr.net/gh/maple3142/StreamSaver.js/examples/zip-stream.min.js
// @license           MIT
// @connect           23.237.126.42
// @grant             GM_xmlhttpRequest
// ==/UserScript==

function download(url) {
	return new Promise((resolve, reject) => {
		GM_xmlhttpRequest({
			method: 'GET',
			url,
			responseType: 'blob',
			onload: res => resolve(res.response)
		})
	})
}

let started = false
$('a:contains("click to download")').on('click', async e => {
	e.preventDefault()
	$(e.target).text("Don't close this tab until download complete.")
	if (started) return
	started = true
	const title = $('h2')[0].textContent
	const files = $('tr>td.clickable-row:not([align])')
		.toArray()
		.map(el =>
			$(el)
				.find('a')
				.attr('href')
		)
		.map(url => {
			const obj = {}
			obj.pageUrl = url
			obj.blobPromise = fetch(url)
				.then(r => r.text())
				.then(html => {
					obj.url = $(html)
						.find('a:contains("Click here to download as MP3")')
						.attr('href')
					obj.name = decodeURIComponent(obj.url.split('/').pop())
					return download(obj.url)
				})
			return obj
		})
	const ws = streamSaver.createWriteStream(title + '.zip')
	new ZIP({
		async pull(ctrl) {
			const f = files.shift()
			const stream = new Response(await f.blobPromise).body
			ctrl.enqueue({ name: f.name, stream: () => stream })
			if (files.length === 0) ctrl.close()
		}
	})
		.pipeTo(ws)
		.then(console.log, console.error)
})