O'Reilly Helper

🎴 Enhance your O'Reilly learning experience: smoothly hide header and footer on scroll down, and show them (with cute transparency!) on scroll up.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        O'Reilly Helper
// @namespace   https://github.com/mefengl
// @version     0.2.0
// @description 🎴 Enhance your O'Reilly learning experience: smoothly hide header and footer on scroll down, and show them (with cute transparency!) on scroll up.
// @author      mefengl
// @match       https://learning.oreilly.com/library/view/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=oreilly.com
// @license     MIT
// @grant       GM_addStyle
// ==/UserScript==

(function () {
  'use strict';

  GM_addStyle(`
      header, #content-navigation {
          transition: opacity 0.5s linear;
      }
  `);

  let lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
  let isScrollingDown = false;

  let header = document.querySelector('header');
  let footer = document.querySelector('#content-navigation');

  if (header) {
    header.style.opacity = '0.6';
    header.style.transition = 'opacity 0.5s';
  }

  if (footer) {
    footer.style.opacity = '0';
    footer.style.transition = 'opacity 0.5s';
  }

  window.addEventListener('scroll', function () {
    let scrollTop = window.pageYOffset || document.documentElement.scrollTop;

    if (scrollTop > lastScrollTop && !isScrollingDown) {
      isScrollingDown = true;
      // On scroll down, hide header and footer
      if (header) header.style.opacity = '0';
      if (footer) footer.style.opacity = '0';
    } else if (scrollTop < lastScrollTop && isScrollingDown) {
      isScrollingDown = false;
      // On scroll up, show header and footer
      if (header) header.style.opacity = '0.6';
      if (footer) footer.style.opacity = '0.6';
    }

    lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; // For mobile
  }, false);

})();