Single Page Everything

Load single page version of page for supported sites

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

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

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         Single Page Everything
// @namespace    @leesei/userscripts
// @version      2.0.0
// @description  Load single page version of page for supported sites
// @author       [email protected]
// @license      MIT
// @supportURL   https://github.com/leesei/userscripts/issues
// @match        http*://*.howstuffworks.com/*
// @match        http*://www.anandtech.com/show/*
/// @match        http*://www.tomshardware.com/reviews/*.html
// @match        http*://learn.adafruit.com/*
// @match        http*://learn.sparkfun.com/tutorials/*
// @match        http*://arstechnica.com/*
// @run-at       document-start
// @grant        GM_log
// @grant        GM_info
// @noframes
// ==/UserScript==

function log(level, text) {
  GM_log(level + ": " + text);
}

const handlers = {
  howstuffworks: function (params) {
    if (!location.pathname.endsWith(".htm")) return;

    const links = document.querySelectorAll("a[rel='nofollow']");
    for (const link of links) {
      if (link.innerText == "Print") {
        return location.replace(link.href);
      }
    }
  },
  anandtech: function (params) {
    location.replace(location.pathname.replace("/show", "/print"));
  },
  // tomshardware: function (params) {
  //   location.replace(
  //     location.pathname.replace("/reviews", "/print").replace(",", ",reviews-")
  //   );
  // },
  adafruit: function (params) {
    const links = document.querySelectorAll(
      "ul[aria-label='Guide resources'] li a"
    );
    for (const link of links) {
      if (link.innerText == "Single page") {
        return location.replace(link.href);
      }
    }
  },
  sparkfun: function (params) {
    const links = document.querySelectorAll("a.list-group-item");
    for (const link of links) {
      if (link.innerText == "Single Page") {
        return location.replace(link.href);
      }
    }
  },
  arstechnica: function (params) {
    const link = document.querySelector("link[rel='amphtml']");
    if (link) location.replace(link.href);
  },
};

(function () {
  "use strict";

  log(
    "info",
    ">>> [" + GM_info.script.namespace + "] " + GM_info.script.name + " <<<"
  );

  const params = new URLSearchParams(location.search);
  // log("info", JSON.stringify(params.entries()));

  for (const domain in handlers) {
    if (location.hostname.includes(domain)) {
      handlers[domain](params);
      break;
    }
  }
})();