Base64 Auto Decoder

Decode base64-encoded links

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Base64 Auto Decoder
// @namespace   Wiki-Index
// @match       *://wiki-index.pages.dev/*
// @grant       none
// @version     1.0
// @description Decode base64-encoded links
// ==/UserScript==

setTimeout(() => {
  'use strict';
  const base64Regex = /^[A-Za-z0-9+/]+=*$/;
  const isURL = (str) => /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i.test(str);
  const decodeAndDisplay = (element) => {
    const content = element.textContent.trim();
    if (base64Regex.test(content)) {
      const decodedString = atob(content).trim();
      if (isURL(decodedString)) {
        element.innerHTML = `<a href="${decodedString}" target="_self">${decodedString}</a>`;
      }
    }
  };
  const observer = new IntersectionObserver((entries, observer) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        decodeAndDisplay(entry.target);
        observer.unobserve(entry.target);
      }
    });
  });
  document.querySelectorAll('code, p').forEach(element => {
    observer.observe(element);
  });
}, 5000);