Beehiiv Link Transparency

Decorate links on a Beehiiv newsletter page with title tags showing the target URLs

目前為 2024-01-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Beehiiv Link Transparency
// @version      0.1
// @description  Decorate links on a Beehiiv newsletter page with title tags showing the target URLs
// @author       Kevin Shay
// @namespace    https://greasyfork.org/users/154233
// @match        https://www.todayintabs.com/*
// @grant        GM_xmlhttpRequest
// @connect      flight.beehiiv.net
// @require      https://update.greasyfork.org/scripts/472236/1249646/GM%20Fetch.js
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// ==/UserScript==

/* globals gmFetch */

(function() {
    'use strict';

    const BEEHIIV_REDIRECT_RE = new RegExp('^https://flight.beehiiv.net/v2/clicks/');
    const ERROR_LOCATION_RE = new RegExp('Refused to connect to "([^]+)"');

    function checkLinks() {
        [...document.getElementsByTagName('a')].forEach((el) => {
            if (el.href.match(BEEHIIV_REDIRECT_RE)) {
                gmFetch(el.href, {
                    method: 'HEAD',
                    headers: {
                        'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey',
                    },
                }).then((res) => {
                    console.log(res);
                }).catch((e) => {
                    // FIXME: If GM_fetch and GM_xmlhttpRequest could be told not to follow redirects,
                    // we could look at the first redirect response and wouldn't need to rely on errors.
                    el.setAttribute('title', e.toString().match(ERROR_LOCATION_RE)[1].trim());
                });
            }
        });
    }

    checkLinks();
})();