Miniflux add more previous and next links

Adds another Next button to Miniflux UI that doesn't jump all over the place

当前为 2024-05-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         Miniflux add more previous and next links
// @namespace    https://reader.miniflux.app/
// @version      14
// @description  Adds another Next button to Miniflux UI that doesn't jump all over the place
// @author       Tehhund
// @match        *://*.miniflux.app/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=miniflux.app
// @run-at       document-start
// ==/UserScript==

const addLinks = () => {
  // Add Previous and Next above header
  /*const pagination = document.getElementsByClassName('pagination')[0];
  document.getElementsByClassName('entry')[0].innerHTML = pagination.outerHTML + document.getElementsByClassName('entry')[0].innerHTML;*/

  // Add Previous and Next fixed to bottom sides of page
  /*let bottomPagination = document.createElement('div');
  bottomPagination.innerHTML = pagination.outerHTML;
  bottomPagination.innerHTML = bottomPagination.firstChild.innerHTML;
  bottomPagination.className += 'pagination';
  bottomPagination.style.position = 'fixed';
  bottomPagination.style.bottom = '0%';
  bottomPagination.style.left = '.5%';
  bottomPagination.style.width = '99%';
  document.body.appendChild(bottomPagination);*/

  // Check if Previous and Next are at the top of the main entry, and if not add them there. Unsure why Miniflux sometimes hides them.
  /*const entryHeader = document.getElementsByClassName('entry-header')[0];
  if (entryHeader.nextElementSibling.className !== 'pagination-entry-top') {
    entryHeader.after(pagination);
  }*/

  // Add Links fixed to page sides.
  const nextLink = document.querySelector('[rel="next"]');
  if (nextLink) {
    /*const newNextLinkTop = nextLink.cloneNode(true);
    newNextLinkTop.style = 'position: fixed;top: 5rem;right: 0;border: 1px solid #000000;font-size: 1rem;';
    document.body.appendChild(newNextLinkTop);
    newNextLinkBottom = nextLink.cloneNode(true);
    newNextLinkBottom.style = 'position: fixed;bottom: 5rem;right: 0;border: 1px solid #000000;font-size: 1rem;';
    document.body.appendChild(newNextLinkBottom);*/
    const newNextLink = nextLink.cloneNode(true);
    newNextLink.style.position = 'fixed';
    newNextLink.style.right = '0';
    newNextLink.style.border = '1px solid #000000';
    const newNextLinks = [];
    for (let i = 0; i < 3; i++) {
      newNextLinks[i] = newNextLink.cloneNode(true);
      newNextLinks[i].style.top = ((i + 1) * 11) + 'rem';
    }
    for (let elem of newNextLinks) {
      document.body.appendChild(elem);
    }
  }

  const prevLink = document.querySelector('[rel="prev"]');
  if (prevLink) {
    /*const newPrevLinkTop = prevLink.cloneNode(true);
    const newPrevLinkBottom = prevLink.cloneNode(true);
    newPrevLinkTop.style = 'position: fixed;top: 5rem;left: 0;border: 1px solid #000000;font-size: 1rem;';
    newPrevLinkBottom.style = 'position: fixed;bottom: 5rem;left: 0;border: 1px solid #000000;font-size: 1rem;';
    document.body.appendChild(newPrevLinkTop);
    document.body.appendChild(newPrevLinkBottom);
    newPrevLinkBottom = prevLink.cloneNode(true);
    newPrevLinkBottom.style = 'position: fixed;bottom: 5rem;left: 0;border: 1px solid #000000;font-size: 1rem;';
    document.body.appendChild(newPrevLinkBottom);*/
    const newPrevLink = prevLink.cloneNode(true);
    newPrevLink.style.position = 'fixed';
    newPrevLink.style.left = '0';
    newPrevLink.style.border = '1px solid #000000';
    const newPrevLinks = [];
    for (let i = 0; i < 3; i++) {
      newPrevLinks[i] = newPrevLink.cloneNode(true);
      newPrevLinks[i].style.top = ((i + 1) * 11) + 'rem';
    }
    for (let elem of newPrevLinks) {
      document.body.appendChild(elem);
    }
  }

  // If it's a Twitter/X domain, add a button to navigate to that directly.
  const externalLinkSpan = document.getElementsByClassName("page-link")[1];
  if (externalLinkSpan.href.includes("privacydev.net") || externalLinkSpan.href.includes("poast.org")) {
    const directLink = externalLinkSpan.cloneNode(true);
    const newUrl = new URL(externalLinkSpan.href);
    newUrl.host = "x.com";
    directLink.href = newUrl.href.replace("#m", ""); // remove annoying #m that Nitter adds.
    directLink.textContent = "Direct Twitter link."
    externalLinkSpan.insertAdjacentElement("afterend", directLink);
  }
};
try { addLinks(); } catch (e) { }// If the script runs after DOMContentLoaded this will add the links. If it runs before DOMContentLoaded, this will error and the listener below will run it instead.
window.addEventListener("DOMContentLoaded", addLinks);