proper formatting & fixed syntax

This commit is contained in:
17ms 2022-12-09 03:42:45 +02:00
parent 7c1f2d9d75
commit 5bbde86d50
4 changed files with 46 additions and 56 deletions

View File

@ -5,38 +5,36 @@
// @version 1.0 // @version 1.0
// ==/UserScript== // ==/UserScript==
function download(url) { function download(url) {
fetch(url, { fetch(url, {
mode: "no-cors", 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()
}) })
.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()
})
} }
function init() { function init() {
const links = Array.from(document.getElementsByClassName("jpg")).concat(Array.from(document.getElementsByClassName("png"))) const links = Array.from(document.getElementsByClassName("jpg")).concat(
Array.from(document.getElementsByClassName("png"))
)
for (let i = 0 i < links.length ++i) { for (let i = 0; i < links.length; ++i) {
let url = links[i].href let url = links[i].href
download(url) download(url)
} }
} }
const activate_link = document.createElement("button") const activate_link = document.createElement("button")
const parent_element = document.getElementById("navbar") const parent_element = document.getElementById("navbar")
activate_link.innerText = "⮶" activate_link.innerText = "⮶"
activate_link.style.fontSize = "30px" activate_link.style.fontSize = "30px"
activate_link.onclick = () => init() activate_link.onclick = () => init()
parent_element.append(activate_link) parent_element.append(activate_link)

View File

@ -6,23 +6,20 @@
// @version 1.0 // @version 1.0
// ==/UserScript== // ==/UserScript==
window.toggle_images = function () { window.toggle_images = function () {
const data = document.getElementsByClassName("fileThumb") const data = document.getElementsByClassName("fileThumb")
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
let img_data = data[i].getElementsByTagName("img") let img_data = data[i].getElementsByTagName("img")
if (img_data[0].className === "fileDeletedRes retina") { if (img_data[0].className === "fileDeletedRes retina") {
continue continue
} else if (img_data.length === 1) { } else if (img_data.length === 1) {
ImageExpansion.expand(img_data[0]) ImageExpansion.expand(img_data[0])
} else { } else {
ImageExpansion.contract(img_data[1]) ImageExpansion.contract(img_data[1])
}
} }
}
} }
const parent_element = document.getElementsByClassName("navLinks desktop")[0] const parent_element = document.getElementsByClassName("navLinks desktop")[0]
parent_element.innerHTML += " [<a href='javascript:toggle_images()'>Toggle</a>]" parent_element.innerHTML += " [<a href='javascript:toggle_images()'>Toggle</a>]"

View File

@ -6,18 +6,16 @@
// @version 1.0 // @version 1.0
// ==/UserScript== // ==/UserScript==
window.addEventListener("load", function () { window.addEventListener("load", function () {
const keywords = [] // e.g. ["/sdg/", "luke smith"] const keywords = [] // e.g. ["/sdg/", "luke smith"]
const data = document.getElementsByClassName("teaser") const data = document.getElementsByClassName("teaser")
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
let inner_txt = data[i].innerText let inner_txt = data[i].innerText
for (let j = 0; j < keywords.length; ++j) { for (let j = 0; j < keywords.length; ++j) {
if (inner_txt.includes(keywords[j])) { if (inner_txt.includes(keywords[j])) {
data[i].offsetParent.style.display = "none" data[i].offsetParent.style.display = "none"
} }
}
} }
}
}) })

View File

@ -5,25 +5,22 @@
// @version 1.0 // @version 1.0
// ==/UserScript== // ==/UserScript==
function toggle_images() { function toggle_images() {
const media_jpg = document.querySelectorAll("a.jpg") const media_jpg = document.querySelectorAll("a.jpg")
const media_png = document.querySelectorAll("a.png") const media_png = document.querySelectorAll("a.png")
for (let i = 0 i < media_jpg.length ++i) { for (let i = 0; i < media_jpg.length; ++i) {
media_jpg[i].click() media_jpg[i].click()
} }
for (let i = 0 i < media_png.length ++i) { for (let i = 0; i < media_png.length; ++i) {
media_png[i].click() media_png[i].click()
} }
} }
const activate_link = document.createElement("button") const activate_link = document.createElement("button")
const parent_element = document.getElementById("navbar") const parent_element = document.getElementById("navbar")
activate_link.innerText = "Toggle" activate_link.innerText = "Toggle"
activate_link.style.fontSize = "9px" activate_link.style.fontSize = "9px"
activate_link.onclick = () => toggle_images() activate_link.onclick = () => toggle_images()
parent_element.append(activate_link) parent_element.append(activate_link)