Warning: fopen(/www/sites/greasyfork.cloud/index/store/forever/0f8dc0a1c347b4de549cf17b62bc7449.html): failed to open stream: No space left on device in /www/sites/greasyfork.cloud/index/scriptsControl.php on line 127
Adobe Fonts Downloader - 源代码

Greasy Fork

Adobe Fonts Downloader

Adds a download button to Adobe Fonts.

当前为 2024-11-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         Adobe Fonts Downloader
// @description  Adds a download button to Adobe Fonts.
// @icon         https://badnoise.net/TypeRip/favicon.png
// @version      1.0
// @author       afkarxyz
// @namespace    https://github.com/afkarxyz/misc-scripts/
// @supportURL   https://github.com/afkarxyz/misc-scripts/issues
// @license      MIT
// @match        https://fonts.adobe.com/*
// @match        https://badnoise.net/TypeRip/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        window.close
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    if (window.location.hostname === 'badnoise.net') {
        const adobeUrl = GM_getValue('adobeFontUrl', '');
        if (adobeUrl) {
            GM_setValue('adobeFontUrl', '');
            
            setTimeout(() => {
                const urlInput = document.getElementById('url_input');
                const submitButton = document.getElementById('url_submit_button');
                
                if (urlInput && submitButton) {
                    urlInput.value = adobeUrl;
                    urlInput.dispatchEvent(new Event('input', { bubbles: true }));
                    submitButton.click();
                }
            }, 1000);
        }
        return;
    }

    function createDownloadButton() {
        let container = document.querySelector('.adobe-fonts-family__top-actions-add-family');
        
        if (!container) {
            const topActions = document.querySelector('.adobe-fonts-family__top-actions');
            if (!topActions) {
                console.error('Top actions container not found');
                return;
            }
            container = document.createElement('div');
            container.className = 'adobe-fonts-family__top-actions-add-family';
            topActions.appendChild(container);
        } else {
            container.innerHTML = '';
        }
        
        container.classList.remove('ng-hide');
        
        const button = document.createElement('button');
        button.className = 'spectrum-Button spectrum-Button--primary add-family-button add-outline-button ng-scope';
        
        const iconSpan = document.createElement('span');
        iconSpan.className = 'spectrum-Icon creative-cloud-icon';
        iconSpan.innerHTML = `
            <svg xmlns="http://www.w3.org/2000/svg" id="icons" width="18" height="18" viewBox="0 -2 18 18">
                <path id="_256" data-name=" 256" class="currentColor" d="M16.147,4.111A6.654,6.654,0,0,0,11.246,2,6.839,6.839,0,0,0,6.405,4.022c-.219-.02-.438-.04-.647-.04A5.756,5.756,0,0,0,0,9.711a5.9,5.9,0,0,0,1.614,4A5.687,5.687,0,0,0,5.758,15.5h5.488a6.745,6.745,0,0,0,4.9-11.389ZM5.658,14.539A4.753,4.753,0,1,1,8.806,6.232l.02.02,1.982,2.022a.844.844,0,0,1-.02,1.2.854.854,0,0,1-1.2-.02l-1.963-2a3.054,3.054,0,0,0-4.293.317A2.992,2.992,0,0,0,2.59,9.741,3.133,3.133,0,0,0,5.7,12.814h.388v.01a9.327,9.327,0,0,0,2.122,1.715Zm9.772-1.715a5.706,5.706,0,0,1-4.084,1.744,5.952,5.952,0,0,1-4.1-1.784l-2.61-2.607a.852.852,0,0,1,.01-1.2A.856.856,0,0,1,5.847,9l2.6,2.587a4.2,4.2,0,0,0,2.9,1.288,3.936,3.936,0,0,0,2.869-1.239,4.179,4.179,0,0,0,1.2-2.924,4.085,4.085,0,0,0-4.084-4.063A3.707,3.707,0,0,0,9.065,5.3c-.01-.01-.2-.129-.409-.258-.129-.079-.269-.159-.388-.218S7.79,4.587,7.581,4.5c-.05-.02-.12-.05-.15-.06h.01a5.556,5.556,0,0,1,3.885-1.486A5.777,5.777,0,0,1,17.113,8.71,5.845,5.845,0,0,1,15.43,12.824Z"></path>
            </svg>
        `;
        
        const labelSpan = document.createElement('span');
        labelSpan.className = 'spectrum-Button-label add-family-label';
        labelSpan.textContent = 'Download';
        
        button.appendChild(iconSpan);
        button.appendChild(labelSpan);
        
        button.addEventListener('click', function(e) {
            e.preventDefault();
            
            GM_setValue('adobeFontUrl', window.location.href);
            
            window.open('https://badnoise.net/TypeRip/', '_blank');
        });
        
        container.appendChild(button);
        
        return button;
    }

    function init() {
        const existingButtons = document.querySelectorAll('.adobe-fonts-family__top-actions-add-family button');
        existingButtons.forEach(button => button.remove());
        
        createDownloadButton();
    }

    init();

    let lastUrl = location.href;
    new MutationObserver(() => {
        const url = location.href;
        if (url !== lastUrl) {
            lastUrl = url;
            init();
        }
    }).observe(document, {subtree: true, childList: true});
})();