MediumUnlocker

unlock medium content by redirect to freedium.cfd

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         MediumUnlocker
// @namespace    https://github.com/domonnss
// @version      1.0
// @description  unlock medium content by redirect to freedium.cfd
// @author       domonnss
// @match        https://medium.com/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
// @license      GPLv3 License
// ==/UserScript==

const $ = jQuery.noConflict(true);

// 定义当前URL变量
const curURL = window.location.href;

// 移除URL协议的辅助函数
function removeProtocol(url) {
  return url.replace(/^(https?:|)\/\//, '');
}

// 定义sites对象,包含需要处理的网站
const sites = {
  medium: {
    match: 'medium.com',
    redirect: function() {
      // 自定义重定向逻辑
      const freediumBase = "https://freedium.cfd/";
      const mediumUrl = window.location.href;
      // 构建目标URL并跳转
      window.location.replace(freediumBase + mediumUrl);
    }
  }
};

/**
 * @function
 * @name match
 * @param {string} pattern - URL模式
 * @param {boolean} enableRegex - 是否启用正则表达式
 * @param {boolean} checkProtocol - 是否检查协议
 * @description 检查当前URL是否匹配给定模式
 */
function match(pattern, enableRegex = false, checkProtocol = false) {
  var curURLProto;
  if (checkProtocol) {
    curURLProto = curURL;
  } else {
    curURLProto = removeProtocol(curURL);
    pattern = removeProtocol(pattern);
  }

  if (enableRegex) {
    return curURLProto.search(pattern) > -1;
  } else {
    return curURLProto.indexOf(pattern) === 0;
  }
}

// 主执行函数
(function() {
  'use strict';

  // 判断当前URL是否匹配Medium
  if (match(sites.medium.match)) {
    console.log("检测到Medium网站,准备重定向...");
    sites.medium.redirect();
  }
})();