Skip to content

Instantly share code, notes, and snippets.

@yutsuku
Last active August 21, 2023 22:37
Show Gist options
  • Save yutsuku/ad383b80a86651c96a754504bd9ebc19 to your computer and use it in GitHub Desktop.
Save yutsuku/ad383b80a86651c96a754504bd9ebc19 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name DoujinStyle Download Command
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Replaces donwload button with download link. You will need to disable Same Origin Policy in your browser (using addon like https://addons.mozilla.org/en-US/firefox/addon/cors-everywhere).
// @author moh@yutsuku.net
// @match https://doujinstyle.com/
// @match https://doujinstyle.com/?p=home*
// @match https://doujinstyle.com/?p=page&type=1*
// @grant none
// @run-at document-end
// @updateURL https://gist.github.com/yutsuku/ad383b80a86651c96a754504bd9ebc19/raw/doujinstyle.com.download-command.user.js
// @downloadURL https://gist.github.com/yutsuku/ad383b80a86651c96a754504bd9ebc19/raw/doujinstyle.com.download-command.user.js
// ==/UserScript==
(function() {
'use strict';
const button = document.querySelector('#downloadForm')
button.insertAdjacentHTML('beforebegin',
`<div id="download-cmd"></div>`
)
button.addEventListener('click', (event) => {
let params = {}
const action = event.target.parentNode.action
const method = event.target.parentNode.method
event.target.parentNode.querySelectorAll('input').forEach( (input) => {
if (input.name && input.value) {
params[input.name] = input.value
}
})
params[event.target.name] = event.target.value
fetch(action, {
method: method,
body: new URLSearchParams(params),
redirect: 'follow'
})
.then((response) => {
window.response = response;
console.log(response)
if (response.redirected) {
const downloadCmd = event.target.parentNode.querySelector('#download-cmd')
let link = response.url;
if (response.url.includes('mega.')) {
link = `mega-get -q --ignore-quota-warn ${response.url}`
}
downloadCmd.innerHTML =
`<input onclick="this.select()" type="text" value="${link}">`
}
})
.catch((reject) => {
console.log(reject)
})
event.preventDefault()
}, true)
button.click()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment