Created
February 22, 2023 21:06
-
-
Save xiaq/a0f4649fecbcd5f5449589b8afee8f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PageUp/PageDown buttons | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Add semi-transparent PageUp/PageDown buttons to the right of every page. Useful when reading web pages on e-ink screens. | |
// @author xiaq | |
// @match *://*/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const container = document.createElement('div'); | |
setStyle(container, { | |
position: 'fixed', right: '8px', top: 'calc(50% - 48px)', | |
display: 'flex', 'flex-direction': 'column', | |
opacity: '0.5', | |
}) | |
const buttonStyle = { | |
width: '48px', height: '48px', 'font-size': '32px', border: '1px solid black', | |
display: 'flex', 'align-items': 'center', 'justify-content': 'center', | |
}; | |
const scrollFactor = 0.8; | |
const pageUp = document.createElement('button'); | |
pageUp.innerText = '▲'; | |
setStyle(pageUp, buttonStyle); | |
pageUp.onclick = () => { window.scrollBy(0, -scrollFactor * window.innerHeight) }; | |
const pageDown = document.createElement('button'); | |
pageDown.innerText = '▼'; | |
setStyle(pageDown, buttonStyle); | |
pageDown.onclick = () => { window.scrollBy(0, scrollFactor * window.innerHeight) }; | |
container.appendChild(pageUp); | |
container.appendChild(pageDown); | |
document.body.appendChild(container); | |
function setStyle(elem, obj) { | |
elem.style = Object.entries(obj).map(([k, v]) => k+':'+v).join(';'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment