Freediumify Medium

Bypasses Medium paywall using Freedium.cfd

// ==UserScript==
// @name         Freediumify Medium
// @namespace    https://greasyfork.org/users/3786
// @version      2025-08-03.1
// @description  Bypasses Medium paywall using Freedium.cfd
// @description:ru  Добавляет кнопку для чтения платных статей на medium.com через freedium.cfd
// @author       Maranchuk Sergey <[email protected]>
// @match        https://medium.com/*
// @match        https://*.medium.com/*
// @icon         https://icons.duckduckgo.com/ip2/freedium.cfd.ico
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';
    const freediumButtonId = 'freedium-button-container';
    function addFreediumButton() {
      // Check if button already exists
      if (document.getElementById(freediumButtonId)) {
          return;
      }
        
   
      const memberOnlyBtn = Array.from(document.querySelectorAll('p')).find(el => el.textContent.includes('Member-only story'));
      if (!memberOnlyBtn) {
          return;
      }
      const buttonContainer = document.createElement('div');
      buttonContainer.id = freediumButtonId;
      buttonContainer.style.display = 'inline-flex';
      buttonContainer.style.alignItems = 'center';
      buttonContainer.style.backgroundColor = '#22C55E';
      buttonContainer.style.color = 'white';
      buttonContainer.style.padding = '5px 5px';
      buttonContainer.style.marginLeft = '10px';
      buttonContainer.style.borderRadius = '5px';
      buttonContainer.style.cursor = 'pointer';
      buttonContainer.style.fontSize = '14px';

      const iconSvg = `
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" width="20px" height="20px" style="margin-right: 5px;">
              <path d="M0 0h24v24H0z" fill="none"/>
              <path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
          </svg>
      `;
      buttonContainer.innerHTML = iconSvg + 'Freedium';


      buttonContainer.addEventListener('click', function() {
          const currentUrl = window.location.href;
          const freediumUrl = 'https://freedium.cfd/' + currentUrl;
          window.open(freediumUrl, '_blank');
      });

      memberOnlyBtn.parentNode.insertAdjacentElement('afterend', buttonContainer);
    }
  
    // Initial check
    addFreediumButton();	
    
    let currentUrl = window.location.href;
    
    const observer = new MutationObserver(() => {
        if (window.location.href !== currentUrl) {
            const oldUrl = currentUrl;
            currentUrl = window.location.href;
            //console.log('URL changed:', oldUrl, '->', currentUrl);
            setTimeout(addFreediumButton, 1000);
        }
    });
    
    observer.observe(document, {
        childList: true,
        subtree: true
    });
})();