new tab shortcut & version bump

This commit is contained in:
17ms 2023-04-25 14:52:24 +03:00
parent 995d1aed46
commit 3cc9e0a9f0

View File

@ -6,11 +6,20 @@
// @namespace Violentmonkey Scripts // @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/thread/* // @match *://boards.4chan*.org/*/thread/*
// @exclude *://boards.4chan*.org/*/catalog // @exclude *://boards.4chan*.org/*/catalog
// @version 1.3.1 // @version 1.3.2
// ==/UserScript== // ==/UserScript==
// Shortcuts: decrease size, increase size, previous image, next image, jump to the source hash (i.e. post) /*
const keys = ["-", "+", "j", "k", "i"] Default shortcuts:
"-" decrease window size
"+" increase window size
"j" previous image
"k" next image
"i" jump to the source (i.e. post's hash)
"l" open the image to a new tab
*/
const keys = ["-", "+", "j", "k", "i", "l"]
const excludeWebm = true // not tested with webms enabled const excludeWebm = true // not tested with webms enabled
const dragElement = (elem) => { const dragElement = (elem) => {
@ -100,6 +109,11 @@ const moveToHash = () => {
window.location.href = url + hash window.location.href = url + hash
} }
const openToNew = () => {
const url = sources[i][0]
window.open(url, "_blank")
}
const preloadImgs = async () => { const preloadImgs = async () => {
for (let s of sources) { for (let s of sources) {
let img = new Image() let img = new Image()
@ -114,16 +128,25 @@ const keyUpEvent = async (e) => {
return return
} }
if (e.key === keys[0]) { switch (e.key) {
sizeDown() case keys[0]:
} else if (e.key === keys[1]) { sizeDown()
sizeUp() break
} else if (e.key === keys[2]) { case keys[1]:
prevImg() sizeUp()
} else if (e.key === keys[3]) { break
nextImg() case keys[2]:
} else if (e.key === keys[4]) { prevImg()
moveToHash() break
case keys[3]:
nextImg()
break
case keys[4]:
moveToHash()
break
case keys[5]:
openToNew()
break
} }
} }
@ -221,7 +244,6 @@ let imgs = []
const sources = collectSources() const sources = collectSources()
preloadImgs().then(() => console.log("4c-gallery: All images loaded")) preloadImgs().then(() => console.log("4c-gallery: All images loaded"))
const baseElem = document.getElementById("drGallery") const baseElem = document.getElementById("drGallery")
const imgElem = document.getElementById("drImg") const imgElem = document.getElementById("drImg")
dragElement(baseElem) dragElement(baseElem)