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==
// @name 4c-autohide
// @description Keyword based thread hider
// @author 17ms
// @license MIT License
// @author ae
// @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/catalog
// @version 1.0

View File

@ -1,17 +1,25 @@
// ==UserScript==
// @name 4c-gallery
// @description Draggable image viewer
// @author 17ms
// @license MIT License
// @author ae
// @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/thread/*
// @exclude *://boards.4chan*.org/*/catalog
// @version 1.2
// @version 1.3.2
// ==/UserScript==
// Shortcuts: decrease size, increase size, previous image, next image, jump to the source hash (i.e. post)
const keys = ["-", "+", "j", "k", "i"]
const excludeWebm = true
/*
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 dragElement = (elem) => {
const handler = (e) => {
@ -26,13 +34,14 @@ const dragElement = (elem) => {
const enableDragger = (e) => {
e = e || window.event
e.preventDefault()
pos1 = pos3 - e.clientX
pos2 = pos4 - e.clientY
pos3 = e.clientX
pos4 = e.clientY
elem.style.top = (elem.offsetTop - pos2) + "px"
elem.style.left = (elem.offsetLeft - pos1) + "px"
elem.style.top = elem.offsetTop - pos2 + "px"
elem.style.left = elem.offsetLeft - pos1 + "px"
}
const closeDragger = () => {
@ -69,31 +78,28 @@ const nextImg = () => {
imgElem.src = imgs[i].src
}
// could probably be improved with proper css
const sizeUp = () => {
const e = document.getElementById("drGallery")
const newW = e.clientWidth + 100
const newH = e.clientHeight + 90
const newW = baseElem.clientWidth + 200
const newH = Math.round(newW * ratioMultiplier)
if (newW > window.innerWidth || newH > window.innerHeight) {
if (newW > window.innerWidth) {
return
}
document.getElementById("drGallery").style.width = newW + "px"
document.getElementById("drGallery").style.height = newH + "px"
baseElem.style.width = newW + "px"
baseElem.style.height = newH + "px"
}
const sizeDown = () => {
const e = document.getElementById("drGallery")
const newW = e.clientWidth - 100
const newH = e.clientHeight - 90
const newW = baseElem.clientWidth - 200
const newH = Math.round(newW * ratioMultiplier)
if (newW < 265 || newH < 240) {
return
}
document.getElementById("drGallery").style.width = newW + "px"
document.getElementById("drGallery").style.height = newH + "px"
baseElem.style.width = newW + "px"
baseElem.style.height = newH + "px"
}
const moveToHash = () => {
@ -103,6 +109,11 @@ const moveToHash = () => {
window.location.href = url + hash
}
const openToNew = () => {
const url = sources[i][0]
window.open(url, "_blank")
}
const preloadImgs = async () => {
for (let s of sources) {
let img = new Image()
@ -117,27 +128,39 @@ const keyUpEvent = async (e) => {
return
}
if (e.key === keys[0]) {
sizeDown(document.getElementById("drGallery"))
} else if (e.key === keys[1]) {
sizeUp(document.getElementById("drGallery"))
} else if (e.key === keys[2]) {
prevImg()
} else if (e.key === keys[3]) {
nextImg()
} else if (e.key === keys[4]) {
moveToHash()
switch (e.key) {
case keys[0]:
sizeDown()
break
case keys[1]:
sizeUp()
break
case keys[2]:
prevImg()
break
case keys[3]:
nextImg()
break
case keys[4]:
moveToHash()
break
case keys[5]:
openToNew()
break
}
}
const createElements = () => {
const limitElem = document.getElementsByClassName("boardBanner")[0]
const newNode = document.createElement("div")
newNode.innerHTML = `<div id="drGallery" class="reply">
<div id="drHeader" class="drag drDrag">Gallery</div>
newNode.innerHTML = `<div id="drGallery" class="reply drDrag drag">
<div id="drHeader">Gallery</div>
<div id="drContainer"><img id="drImg" src="" alt="" /></div>
</div>`
const initW = "265px"
const initH = Math.round(265 * ratioMultiplier) + "px"
const stylesheet = document.createElement("style")
stylesheet.innerText = `#drGallery {
position: absolute;
@ -145,33 +168,28 @@ const createElements = () => {
font-weight: bold;
text-align: center;
border: 1px solid black;
width: 265px;
height: 240px;
min-width: 265px;
min-height: 240px;
max-width: 100%;
max-height: 100%;
margin: 0px;
width: ${initW};
height: ${initH};
min-width: ${initW};
min-height: ${initH};
display: none;
flex-direction: column;
}
#drHeader {
z-index: 10;
min-height: max-content;
max-height: max-content;
padding: 5px;
cursor: move;
}
#drContainer {
width: inherit;
height: 85%;
height: 100%;
position: relative;
}
#drContainer img {
max-height: 100%;
max-width: 100%;
max-height: 98%;
width: auto;
height: auto;
position: absolute;
@ -184,14 +202,17 @@ const createElements = () => {
document.head.appendChild(stylesheet)
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 = () => {
let sources = []
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) {
const s = e.href.split(".")
@ -209,15 +230,16 @@ const collectSources = () => {
}
window.toggleGalleryVisibility = () => {
if (baseElem.style.display === "block") {
if (baseElem.style.display === "flex") {
baseElem.style.display = "none"
document.removeEventListener("keyup", keyUpEvent, false)
} else {
baseElem.style.display = "block"
baseElem.style.display = "flex"
document.addEventListener("keyup", keyUpEvent, false)
}
}
const ratioMultiplier = window.innerHeight / window.innerWidth
createElements()
let i = 0
@ -225,7 +247,6 @@ let imgs = []
const sources = collectSources()
preloadImgs().then(() => console.log("4c-gallery: All images loaded"))
const baseElem = document.getElementById("drGallery")
const imgElem = document.getElementById("drImg")
dragElement(baseElem)

View File

@ -1,26 +1,27 @@
// ==UserScript==
// @name 4c-image-expander
// @description General media expander
// @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/thread/*
// @exclude *://boards.4chan*.org/*/catalog
// @version 1.0
// ==/UserScript==
window.toggleImgs = () => {
const data = document.getElementsByClassName("fileThumb")
for (let i = 0; i < data.length; ++i) {
let img_data = data[i].getElementsByTagName("img")
if (img_data[0].className === "fileDeletedRes retina") {
continue
} else if (img_data.length === 1) {
ImageExpansion.expand(img_data[0])
} else {
ImageExpansion.contract(img_data[1])
}
}
}
const parentElem = document.getElementsByClassName("navLinks desktop")[0]
parentElem.innerHTML += " [<a href='javascript:toggleImgs()'>Toggle</a>]"
// ==UserScript==
// @name 4c-image-expander
// @description General media expander
// @author ae
// @namespace Violentmonkey Scripts
// @match *://boards.4chan*.org/*/thread/*
// @exclude *://boards.4chan*.org/*/catalog
// @version 1.0
// ==/UserScript==
window.toggleImgs = () => {
const data = document.getElementsByClassName("fileThumb")
for (let i = 0; i < data.length; ++i) {
let img_data = data[i].getElementsByTagName("img")
if (img_data[0].className === "fileDeletedRes retina") {
continue
} else if (img_data.length === 1) {
ImageExpansion.expand(img_data[0])
} else {
ImageExpansion.contract(img_data[1])
}
}
}
const parentElem = document.getElementsByClassName("navLinks desktop")[0]
parentElem.innerHTML += " [<a href='javascript:toggleImgs()'>Toggle</a>]"

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)