Compare commits

...

10 Commits

Author SHA1 Message Date
ae
eb4b4dfe9c
refactor: rm outdated scripts during migration 2024-08-30 19:37:16 +03:00
17ms
f0ea331f57 eslint config 2023-06-01 17:55:54 +03:00
17ms
9b2f9d800b removed broken script 2023-05-06 02:34:15 +03:00
17ms
dd3a5351fc f1tv keyboard shortcuts 2023-04-25 23:26:00 +03:00
17ms
c70c012d4d default formatting to prettier 2023-04-25 20:07:30 +03:00
17ms
3cc9e0a9f0 new tab shortcut & version bump 2023-04-25 14:52:24 +03:00
17ms
995d1aed46 updated docs 2023-04-04 00:44:58 +03:00
17ms
71519fca49 fixed aspect ratio for tiled workspaces 2023-03-21 00:08:20 +02:00
17ms
0f72f7cce3 bump version 2023-03-17 18:40:21 +02:00
17ms
292321fa26 flexbox, proportional resizing & improved styling 2023-03-17 18:34:12 +02:00
7 changed files with 113 additions and 158 deletions

15
.eslintrc.json Normal file
View File

@ -0,0 +1,15 @@
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2021
},
"rules": {
"quotes": ["warn", "double"],
"semi": ["warn", "never"],
"indent": ["warn", 4],
"prettier/prettier": 0
}
}

View File

@ -1,8 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 4c-autohide // @name 4c-autohide
// @description Keyword based thread hider // @description Keyword based thread hider
// @author 17ms // @author ae
// @license MIT License
// @namespace Violentmonkey Scripts // @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/catalog // @match *://boards.4chan*.org/*/catalog
// @version 1.0 // @version 1.0

View File

@ -1,17 +1,25 @@
// ==UserScript== // ==UserScript==
// @name 4c-gallery // @name 4c-gallery
// @description Draggable image viewer // @description Draggable image viewer
// @author 17ms // @author ae
// @license MIT License
// @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.2 // @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:
const excludeWebm = true "-" 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 dragElement = (elem) => { const dragElement = (elem) => {
const handler = (e) => { const handler = (e) => {
@ -26,13 +34,14 @@ const dragElement = (elem) => {
const enableDragger = (e) => { const enableDragger = (e) => {
e = e || window.event e = e || window.event
e.preventDefault() e.preventDefault()
pos1 = pos3 - e.clientX pos1 = pos3 - e.clientX
pos2 = pos4 - e.clientY pos2 = pos4 - e.clientY
pos3 = e.clientX pos3 = e.clientX
pos4 = e.clientY pos4 = e.clientY
elem.style.top = (elem.offsetTop - pos2) + "px" elem.style.top = elem.offsetTop - pos2 + "px"
elem.style.left = (elem.offsetLeft - pos1) + "px" elem.style.left = elem.offsetLeft - pos1 + "px"
} }
const closeDragger = () => { const closeDragger = () => {
@ -69,31 +78,28 @@ const nextImg = () => {
imgElem.src = imgs[i].src imgElem.src = imgs[i].src
} }
// could probably be improved with proper css
const sizeUp = () => { const sizeUp = () => {
const e = document.getElementById("drGallery") const newW = baseElem.clientWidth + 200
const newW = e.clientWidth + 100 const newH = Math.round(newW * ratioMultiplier)
const newH = e.clientHeight + 90
if (newW > window.innerWidth || newH > window.innerHeight) { if (newW > window.innerWidth) {
return return
} }
document.getElementById("drGallery").style.width = newW + "px" baseElem.style.width = newW + "px"
document.getElementById("drGallery").style.height = newH + "px" baseElem.style.height = newH + "px"
} }
const sizeDown = () => { const sizeDown = () => {
const e = document.getElementById("drGallery") const newW = baseElem.clientWidth - 200
const newW = e.clientWidth - 100 const newH = Math.round(newW * ratioMultiplier)
const newH = e.clientHeight - 90
if (newW < 265 || newH < 240) { if (newW < 265 || newH < 240) {
return return
} }
document.getElementById("drGallery").style.width = newW + "px" baseElem.style.width = newW + "px"
document.getElementById("drGallery").style.height = newH + "px" baseElem.style.height = newH + "px"
} }
const moveToHash = () => { const moveToHash = () => {
@ -103,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()
@ -117,27 +128,39 @@ const keyUpEvent = async (e) => {
return return
} }
if (e.key === keys[0]) { switch (e.key) {
sizeDown(document.getElementById("drGallery")) case keys[0]:
} else if (e.key === keys[1]) { sizeDown()
sizeUp(document.getElementById("drGallery")) 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
} }
} }
const createElements = () => { const createElements = () => {
const limitElem = document.getElementsByClassName("boardBanner")[0] const limitElem = document.getElementsByClassName("boardBanner")[0]
const newNode = document.createElement("div") const newNode = document.createElement("div")
newNode.innerHTML = `<div id="drGallery" class="reply"> newNode.innerHTML = `<div id="drGallery" class="reply drDrag drag">
<div id="drHeader" class="drag drDrag">Gallery</div> <div id="drHeader">Gallery</div>
<div id="drContainer"><img id="drImg" src="" alt="" /></div> <div id="drContainer"><img id="drImg" src="" alt="" /></div>
</div>` </div>`
const initW = "265px"
const initH = Math.round(265 * ratioMultiplier) + "px"
const stylesheet = document.createElement("style") const stylesheet = document.createElement("style")
stylesheet.innerText = `#drGallery { stylesheet.innerText = `#drGallery {
position: absolute; position: absolute;
@ -145,33 +168,28 @@ const createElements = () => {
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
border: 1px solid black; border: 1px solid black;
width: 265px; width: ${initW};
height: 240px; height: ${initH};
min-width: 265px; min-width: ${initW};
min-height: 240px; min-height: ${initH};
max-width: 100%;
max-height: 100%;
margin: 0px;
display: none; display: none;
flex-direction: column;
} }
#drHeader { #drHeader {
z-index: 10;
min-height: max-content; min-height: max-content;
max-height: max-content;
padding: 5px; padding: 5px;
cursor: move;
} }
#drContainer { #drContainer {
width: inherit; width: inherit;
height: 85%; height: 100%;
position: relative; position: relative;
} }
#drContainer img { #drContainer img {
max-height: 100%;
max-width: 100%; max-width: 100%;
max-height: 98%;
width: auto; width: auto;
height: auto; height: auto;
position: absolute; position: absolute;
@ -184,14 +202,17 @@ const createElements = () => {
document.head.appendChild(stylesheet) document.head.appendChild(stylesheet)
document.body.insertBefore(newNode, limitElem) document.body.insertBefore(newNode, limitElem)
document.getElementsByClassName("navLinks desktop")[0].innerHTML += " [<a href='javascript:toggleGalleryVisibility()'>Gallery</a>]" document.getElementsByClassName("navLinks desktop")[0].innerHTML +=
" [<a href='javascript:toggleGalleryVisibility()'>Gallery</a>]"
} }
const collectSources = () => { const collectSources = () => {
let sources = [] let sources = []
const fileDivs = document.getElementsByClassName("fileThumb") const fileDivs = document.getElementsByClassName("fileThumb")
const hashPrefix = document.getElementsByClassName("postNum")[0].children[0].hash.slice(0, 3) const hashPrefix = document
.getElementsByClassName("postNum")[0]
.children[0].hash.slice(0, 3)
for (let e of fileDivs) { for (let e of fileDivs) {
const s = e.href.split(".") const s = e.href.split(".")
@ -209,15 +230,16 @@ const collectSources = () => {
} }
window.toggleGalleryVisibility = () => { window.toggleGalleryVisibility = () => {
if (baseElem.style.display === "block") { if (baseElem.style.display === "flex") {
baseElem.style.display = "none" baseElem.style.display = "none"
document.removeEventListener("keyup", keyUpEvent, false) document.removeEventListener("keyup", keyUpEvent, false)
} else { } else {
baseElem.style.display = "block" baseElem.style.display = "flex"
document.addEventListener("keyup", keyUpEvent, false) document.addEventListener("keyup", keyUpEvent, false)
} }
} }
const ratioMultiplier = window.innerHeight / window.innerWidth
createElements() createElements()
let i = 0 let i = 0
@ -225,7 +247,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)

View File

@ -1,6 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 4c-image-expander // @name 4c-image-expander
// @description General media expander // @description General media expander
// @author ae
// @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

View File

@ -1,9 +0,0 @@
## Collection of small userscripts
Tested with [Violentmonkey](https://violentmonkey.github.io/) & Gecko. Available on [Greasyfork](https://greasyfork.org/en/users/1033565-17ms).
* [4c-autohide.js](visual/4c-autohide.js)
* [4c-gallery.js](visual/4c-gallery.js)
* [4c-image-expander.js](visual/4c-image-expander.js)
* [y-image-expander.js](visual/y-image-expander.js)
* [y-media-downloader.js](download/y-media-downloader.js)

View File

@ -1,43 +0,0 @@
// ==UserScript==
// @name y-media-downloader
// @description General media downloader
// @author 17ms
// @license MIT License
// @namespace Violentmonkey Scripts
// @match *://ylilauta.org/*
// @version 1.0
// ==/UserScript==
function download(url) {
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()
})
}
function init() {
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)
}
}
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)

View File

@ -1,29 +0,0 @@
// ==UserScript==
// @name y-image-expander
// @description General media expander
// @author 17ms
// @license MIT License
// @namespace Violentmonkey Scripts
// @match *://ylilauta.org/*
// @version 1.0
// ==/UserScript==
const toggleImages = () => {
const mediaJpg = document.querySelectorAll("a.jpg")
const mediaPng = document.querySelectorAll("a.png")
for (let i = 0; i < mediaJpg.length; ++i) {
mediaJpg[i].click()
}
for (let i = 0; i < mediaPng.length; ++i) {
mediaPng[i].click()
}
}
const activateLink = document.createElement("button")
const parentElem = document.getElementById("navbar")
activateLink.innerText = "Toggle"
activateLink.style.fontSize = "9px"
activateLink.onclick = () => toggleImages()
parentElem.append(activateLink)