Download JS

Downloads the available code from Greasy Fork镜像's code page in .js format

目前為 2025-08-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Download JS
// @name:pt-BR   Download JS
// @name:en      Download JS
// @name:es      Download JS
// @name:zh      Download JS
// @name:fr      Download JS
// @namespace    DownloadJS_OHAS
// @version      1.1.1
// @description  Downloads the available code from Greasy Fork镜像's code page in .js format
// @description:pt-BR Baixa o código disponível na página de códigos do Greasy Fork镜像 em formato .js
// @description:en  Downloads the available code from Greasy Fork镜像's code page in .js format
// @description:es Descarga el código disponible en la página de códigos de Greasy Fork镜像 en formato .js
// @description:zh 从 Greasy Fork镜像 的代码页面下载可用代码,格式为 .js
// @description:fr Télécharge le code disponible sur la page de code de Greasy Fork镜像 au format .js
// @author       OHAS
// @license      MIT
// @icon         https://cdn-icons-png.flaticon.com/512/10009/10009249.png
// @match        https://gf.qytechs.cn/*/scripts/*/code*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
  'use strict';
  const waitFor = (sel) =>
    new Promise((resolve) => {
      const el = document.querySelector(sel);
      if (el) return resolve(el);
      const obs = new MutationObserver(() => {
        const el = document.querySelector(sel);
        if (el) {
          obs.disconnect();
          resolve(el);
        }
      });
      obs.observe(document, { childList: true, subtree: true });
    });
  waitFor('label[for="wrap-lines"]').then((label) => {
    const toolbar = label.parentElement;
    const btn = document.createElement('button');
    btn.className = 'btn';
    btn.textContent = 'Download';
    btn.style.marginLeft = '12px';
    btn.style.backgroundColor = '#005200';
    btn.style.color = 'white';
    btn.style.border = 'none';
    btn.style.padding = '6px 16px';
    btn.style.borderRadius = '4px';
    btn.style.cursor = 'pointer';
    btn.addEventListener('mouseenter', () => {
      btn.style.backgroundColor = '#1e971e';
    });
    btn.addEventListener('mouseleave', () => {
      btn.style.backgroundColor = '#005200';
    });
    btn.addEventListener('click', () => {
      let code = '';
      const liLines = document.querySelectorAll('pre.prettyprint.lang-js li');
      if (liLines.length) {
        code = [...liLines].map((li) => li.textContent).join('\n');
      }
      if (!code) {
        const preBlock = document.querySelector('#script-content > div.code-container > pre');
        if (preBlock) {
          code = preBlock.textContent;
        }
      }
      if (!code) {
        alert('Code not found!');
        return;
      }
      const nameMatch = code.match(/\/\/\s*@name\s+(.+)/i);
      const fileName = nameMatch ? `${nameMatch[1].trim()}.js` : 'script.js';
      const blob = new Blob([code], { type: 'application/javascript' });
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = fileName;
      a.style.display = 'none';
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      URL.revokeObjectURL(url);
    });
    toolbar.appendChild(btn);
  });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址