Last active
November 2, 2024 17:55
-
-
Save sitek94/9cab7f782df4278f0be674d055c306b7 to your computer and use it in GitHub Desktop.
Toggle Focus Mode in Brave/Ahoy platforms
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 Toggle Focus Mode in Brave/Ahoy platforms | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-11-01 | |
// @description Removes distractions by hiding sidebar, navigation, etc. Leaves only article content. Default shortcut: `ctrl =` to toggle the focus on/off. | |
// @author Maciek Sitkowski | |
// @include https://bravecourses.circle.so* | |
// @include https://spolecznosc.eduweb.pl* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=circle.so | |
// @grant none | |
// ==/UserScript== | |
;(function () { | |
'use strict' | |
const styleSheet = document.createElement('style') | |
styleSheet.textContent = ` | |
.focus-mode div.main { | |
position: fixed !important; | |
inset: 0 !important; | |
z-index: 99999 !important; | |
overflow-y: auto !important; | |
height: 100vh !important; | |
width: 100vw !important; | |
color-scheme: dark !important; | |
} | |
` | |
document.head.appendChild(styleSheet) | |
// Make it possible to focus go to the page with the focus already applied | |
let hasFocus = new URL(window.location.href).searchParams.get('focus') === 'on' | |
if (hasFocus) { | |
document.body.classList.add('focus-mode') | |
} | |
document.addEventListener('keydown', event => { | |
// 👇👇👇 CHANGE SHORTCUT HERE | |
if (event.ctrlKey && event.key === '=') { | |
event.preventDefault() | |
hasFocus = !hasFocus | |
document.body.classList.toggle('focus-mode', hasFocus) | |
} | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment