Skip to content

Instantly share code, notes, and snippets.

@cking
Last active December 20, 2023 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cking/f14c4d5302d1a982b08b3f9ba8a8bc26 to your computer and use it in GitHub Desktop.
Save cking/f14c4d5302d1a982b08b3f9ba8a8bc26 to your computer and use it in GitHub Desktop.
PainScroll
// ==UserScript==
// @name PainScroll
// @copyright Made by @kura@z0ne.social
// @author Kura
// @description Scrolling made more painful. And rewarding?
// @version 1.0
// @namespace z0ne
// @match *://*/*
// @downloadURL https://gist.github.com/cking/f14c4d5302d1a982b08b3f9ba8a8bc26/raw/painscroll.user.js
// @homepageURL https://gist.github.com/cking/f14c4d5302d1a982b08b3f9ba8a8bc26
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
function rand(min, max) { const rounds = parseInt(Math.random() * 10)
let rnd = Math.random()
for (let i = 0; i <= rounds; i++) {
rnd += Math.random()
}
rnd -= parseInt(rnd)
min = min || 0
max = max || 1
const v = rnd * (max - min) + min
if (max <= 1) {
return v
}
return parseInt(v)
}
function chance(min) {
return rand() > min
}
let lastPosition = {
x: 0,
y: 0
}
function onScroll(ev) {
const offset = {
x: lastPosition.x - ev.pageX,
y: lastPosition.y - ev.pageY
}
lastPosition.x = ev.pageX
lastPosition.y = ev.pageY
if (!chance(0.75)) {
return
}
const x = jumpScroll(offset.x)
const y = jumpScroll(offset.y)
window.scrollBy(x, y)
}
function jumpScroll(offset) {
if (offset == 0) {
return 0
}
if (chance(0.25)) {
return 0
}
let modifier = chance(0.66) ? 1 : -1
modifier *= rand(0, 32)
return offset * modifier
}
document.addEventListener("DOMMouseScroll", onScroll)
document.addEventListener("mousewheel", onScroll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment