Unfix

Unfixes all fixed elements such as navigation bar and keeps them unfixed. Keybind: ctrl+alt+u

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Unfix
// @namespace    com.gmail.fujifruity.greasemonkey
// @version      1.2
// @description  Unfixes all fixed elements such as navigation bar and keeps them unfixed. Keybind: ctrl+alt+u
// @author       fujifruity
// @match        *://*/*
// @grant        none
// ==/UserScript==

{
    const cssOf = e => document.defaultView.getComputedStyle(e, '')

    const isFixed = e => ['fixed', 'sticky'].includes(cssOf(e).position)

    const unfix = e => {
        if (!isFixed(e)) return
        if (e.id == 'fujifruity-toc') return
        e.style.setProperty('position', 'unset', 'important')
        console.log('unfixed: ', e)
    }

    // Keeps all elements unfixed
    const unfixForever = () => {
        // Unfix all fixed elements
        const allElems = Array.from(document.body.getElementsByTagName("*"))
        allElems.forEach(unfix)

        // Start observing elements get fixed
        const observer = new window.MutationObserver((mutationRecords) => {
            mutationRecords.forEach((mutationRecord) => {
                unfix(mutationRecord.target)
            })
        })
        const config = { attributes: true, subtree: true }
        observer.observe(document.body, config)
    }

    // Set keybinds
    window.addEventListener('keydown', event => {
        if (!event.altKey && !event.metaKey || !event.ctrlKey || event.key != 'u') return
        unfixForever()
    })
}