Extra Fabulous Comics simplifier and next and previous buttons

Adds previous and next buttons/links to Extra Fabulous Comics to make it easier to read a lot of older comics.

当前为 2023-06-07 提交的版本,查看 最新版本

// ==UserScript==
// @name        Extra Fabulous Comics simplifier and next and previous buttons
// @namespace   Tehhund
// @match       *://*.extrafabulouscomics.com/*
// @grant       none
// @version     16
// @author      Tehhund
// @description Adds previous and next buttons/links to Extra Fabulous Comics to make it easier to read a lot of older comics.
// @license MIT
// ==/UserScript==

const calculateCurrentPrevNext = () => {
  let currentComic = window.location.href;
  currentComic = currentComic.slice(-5); // example: https://www.extrafabulouscomics.com/____1
  currentComic = parseInt(currentComic.replace(/\D/g, ''));

  let nextComic = currentComic + 1;
  nextComic = nextComic.toString().padStart(5, '_');
  nextComic = 'https://www.extrafabulouscomics.com/' + nextComic;

  let prevComic = currentComic - 1;
  prevComic = prevComic.toString().padStart(5, '_');
  prevComic = 'https://www.extrafabulouscomics.com/' + prevComic;

  return { 'current': currentComic, 'next': nextComic, 'prev': prevComic };
}

const addLinks = () => {
  let nextPrevLinks = document.getElementsByClassName('tehhundScript');
  while (nextPrevLinks.length > 0) {
    nextPrevLinks[0].remove(); // For of was skipping elements so this fixes that.
  }

  let comic = document.querySelectorAll('img')[0].cloneNode();
  document.body.innerHTML += '<style>* { background: black; }</style>';
  const allElems = document.body.getElementsByTagName('*');
  for (let elem of allElems) {
    if (elem.tagName != 'IMG') {
      elem.style.filter = 'brightness(0%)';
      elem.remove();
    } else {
      elem.style.zIndex = '100';
    }
  }
  document.body.appendChild(comic);


  const currentComic = window.location.href;

  document.body.innerHTML += '<a class="tehhundScript tehhundScriptPrev" href="https://paulkoepke.com/redirector/?redirectUrl=' + currentComic + '&direction=prev" style="position: fixed;bottom: 5rem;left: 0;border: 1px solid #000000;font-size: 1rem;">Prev</button>';
  document.body.innerHTML += '<a class="tehhundScript tehhundScriptPrev" href="https://paulkoepke.com/redirector/?redirectUrl=' + currentComic + '&direction=prev" style="position: fixed;top: 5rem;left: 0;border: 1px solid #000000;font-size: 1rem;">Prev</button>';


  document.body.innerHTML += '<a class="tehhundScript tehhundScriptNext" href="https://paulkoepke.com/redirector/?redirectUrl=' + currentComic + '&direction=next" style="position: fixed;bottom: 5rem;right: 0;border: 1px solid #000000;font-size: 1rem;">Next</button>';
  document.body.innerHTML += '<a class="tehhundScript tehhundScriptNext" href="https://paulkoepke.com/redirector/?redirectUrl=' + currentComic + '&direction=next" style="position: fixed;top: 5rem;right: 0;border: 1px solid #000000;font-size: 1rem;">Next</button>';

  // EFC website is slow to load new pages. This should speed it up a bit.
  const linkRels = ['prefetch','preload','preconnect','dns-prefetch','prerender'];
  for (let rel of linkRels) {
    document.body.innerHTML += '<link link rel="' + rel + '" href="' + calculateCurrentPrevNext()['next'] + '" >';
    document.body.innerHTML += '<link link rel="' + rel + '" href="' + calculateCurrentPrevNext()['prev'] + '" >';
  }

  //Move the whole body up a bit.
  /*document.getElementsByTagName('body')[0].style.position = 'relative';
  document.getElementsByTagName('body')[0].style.top = '-2rem';*/

}
addLinks();