Hacker News Anti-Paywall

A userscript for HackerNews that points out paywalled articles and provides anti-paywall urls.

当前为 2022-11-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hacker News Anti-Paywall
// @namespace    https://github.com/MostlyEmre/hn-anti-paywall
// @version      0.7
// @description  A userscript for HackerNews that points out paywalled articles and provides anti-paywall urls.
// @author       MostlyEmre
// @match        https://news.ycombinator.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com
// @grant        none
// @license MIT
// ==/UserScript==

/* jshint esversion:6 */

(function() {
    'use strict';
const paywalls = [
  "adweek.com",
  "ad.nl",
  "ambito.com",
  "americanbanker.com",
  "baltimoresun.com",
  "barrons.com",
  "bloomberg.com",
  "bloombergquint.com",
  "bndestem.nl",
  "bostonglobe.com",
  "bd.nl",
  "brisbanetimes.com.au",
  "businessinsider.com",
  "caixinglobal.com",
  "centralwesterndaily.com.au",
  "cen.acs.org",
  "chicagotribune.com",
  "corriere.it",
  "chicagobusiness.com",
  "dailypress.com",
  "gelderlander.nl",
  "groene.nl",
  "demorgen.be",
  "denverpost.com",
  "speld.nl",
  "destentor.nl",
  "tijd.be",
  "volkskrant.nl",
  "df.cl",
  "editorialedomani.it",
  "dynamed.com",
  "ed.nl",
  "elmercurio.com",
  "elmundo.es",
  "elpais.com",
  "elperiodico.com",
  "elu24.ee",
  "britannica.com",
  "estadao.com.br",
  "examiner.com.au",
  "expansion.com",
  "fnlondon.com",
  "financialpost.com",
  "ft.com",
  "firstthings.com",
  "foreignpolicy.com",
  "fortune.com",
  "genomeweb.com",
  "glassdoor.com",
  "globes.co.il",
  "grubstreet.com",
  "haaretz.com",
  "haaretz.co.il",
  "harpers.org",
  "courant.com",
  "hbr.org",
  "hbrchina.org",
  "heraldsun.com.au",
  "fd.nl",
  "historyextra.com",
  "humo.be",
  "ilmanifesto.it",
  "inc.com",
  "interest.co.nz",
  "investorschronicle.co.uk",
  "lanacion.com.ar",
  "repubblica.it",
  "lastampa.it",
  "latercera.com",
  "lavoixdunord.fr",
  "lecho.be",
  "ledevoir.com",
  "leparisien.fr",
  "lesechos.fr",
  "loebclassics.com",
  "lrb.co.uk",
  "labusinessjournal.com",
  "latimes.com",
  "medium.com",
  "medscape.com",
  "mexiconewsdaily.com",
  "sloanreview.mit.edu",
  "technologyreview.com",
  "mv-voice.com",
  "nationalgeographic.com",
  "nationalpost.com",
  "nzz.ch",
  "newstatesman.com",
  "nydailynews.com",
  "nymag.com",
  "nzherald.co.nz",
  "nrc.nl",
  "ntnews.com.au",
  "ocregister.com",
  "orlandosentinel.com",
  "paloaltoonline.com",
  "parool.nl",
  "postimees.ee",
  "pzc.nl",
  "qz.com",
  "quora.com",
  "gelocal.it",
  "republic.ru",
  "reuters.com",
  "sandiegouniontribune.com",
  "sfchronicle.com",
  "scientificamerican.com",
  "seekingalpha.com",
  "slate.com",
  "sofrep.com",
  "startribune.com",
  "statista.com",
  "stuff.co.nz",
  '"sueddeutsche.de"',
  "sun-sentinel.com",
  "techinasia.com",
  "telegraaf.nl",
  "time.com",
  "adelaidenow.com.au",
  "theadvocate.com.au",
  "theage.com.au",
  "the-american-interest.com",
  "theathletic.com",
  "theathletic.co.uk",
  "theatlantic.com",
  "afr.com",
  "theaustralian.com.au",
  "bizjournals.com",
  "canberratimes.com.au",
  "thecourier.com.au",
  "couriermail.com.au",
  "thecut.com",
  "dailytelegraph.com.au",
  "thediplomat.com",
  "economist.com",
  "theglobeandmail.com",
  "theherald.com.au",
  "thehindu.com",
  "irishtimes.com",
  "japantimes.co.jp",
  "kansascity.com",
  "themarker.com",
  "mercurynews.com",
  "themercury.com.au",
  "mcall.com",
  "thenation.com",
  "thenational.scot",
  "news-gazette.com",
  "newyorker.com",
  "nytimes.com",
  "theolivepress.es",
  "inquirer.com",
  "thesaturdaypaper.com.au",
  "seattletimes.com",
  "spectator.com.au",
  "spectator.co.uk",
  "spectator.us",
  "smh.com.au",
  "telegraph.co.uk",
  "thestar.com",
  "wsj.com",
  "washingtonpost.com",
  "thewrap.com",
  "the-tls.co.uk",
  "towardsdatascience.com",
  "trouw.nl",
  "tubantia.nl",
  "vanityfair.com",
  "vn.nl",
  "vulture.com",
  "journalnow.com",
  "wired.com",
  "zeit.de",
];

let titles = document.querySelectorAll("table tr.athing");
let postTitle = document.querySelector("tbody table.fatitem tr.athing");

// The main function that updates the UI with the links.
const passTheButter = (node) => {
  let meta = node.nextSibling.querySelector(".subtext");
  let link = node.querySelector(".titleline a").href;
  let domain = node.querySelector("span.sitestr") ? node.querySelector("span.sitestr").innerText : "";
  let paywall = paywalls.find((paywall) => domain.includes(paywall));

  if (paywall) {
    let paywallSpan = document.createElement("span");
    // Add archive.is / 12ft.io / archive.org links
    paywallSpan.innerHTML += `
    | 💰 
    | <a href="https://archive.is/${link}" target="_blank">Archive.is</a> 
    | <a href="https://12ft.io/${link}" target="_blank">12ft.io</a> 
    | <a href="https://web.archive.org/web/${link}" target="_blank">Archive.org</a> 
    | <a href="https://github.com/MostlyEmre/hn-anti-paywall" target="_blank">ℹ</a> 
    `;

    meta.appendChild(paywallSpan);
  }
};

postTitle
  ? passTheButter(postTitle)
  : titles.forEach((title) => {
      passTheButter(title);
    });

})();