userscripts/download/y-media-downloader.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-10-25 19:39:14 +02:00
// ==UserScript==
2023-01-11 18:59:18 +01:00
// @name General media downloader
2022-10-25 19:39:14 +02:00
// @namespace Violentmonkey Scripts
// @match *://ylilauta.org/*
// @version 1.0
// ==/UserScript==
function download(url) {
2022-12-09 02:42:45 +01:00
fetch(url, {
mode: "no-cors"
})
.then((response) => response.blob())
.then((blob) => {
let blob_url = window.URL.createObjectURL(blob)
let a = document.createElement("a")
a.download = url.split("/")[5]
a.href = blob_url
document.body.appendChild(a)
a.click()
a.remove()
2022-10-25 19:39:14 +02:00
})
}
function init() {
2022-12-09 02:42:45 +01:00
const links = Array.from(document.getElementsByClassName("jpg")).concat(
Array.from(document.getElementsByClassName("png"))
)
for (let i = 0; i < links.length; ++i) {
let url = links[i].href
download(url)
}
2022-10-25 19:39:14 +02:00
}
const activate_link = document.createElement("button")
const parent_element = document.getElementById("navbar")
activate_link.innerText = "⮶"
activate_link.style.fontSize = "30px"
activate_link.onclick = () => init()
parent_element.append(activate_link)