FileCR Assistant Bypass & Helper

A script for FileCR that is capable of obtaining software download links (including 'fast download' URLs) and providing access to premium contents.

当前为 2023-11-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           FileCR Assistant Bypass & Helper
// @name:zh        FileCR 助手
// @namespace      xiakele
// @version        2.0
// @description    A script for FileCR that is capable of obtaining software download links (including 'fast download' URLs) and providing access to premium contents.
// @description:zh 一键获取FileCR的软件下载链接(包括快速下载),无需拓展即可访问premium内容。
// @author         xiakele
// @license        MIT
// @match          *://filecr.com/*
// @icon           https://filecr.com/favicon.png
// @grant          window.onurlchange
// ==/UserScript==

(function () {
  const versionInfo = {
    id: 'ddgilliopjknmglnpkegbjpoilgachlm',
    version: '9.9.9',
  };

  if (!document.cookie.includes('extensionIsInstalled')) {
    document.cookie = 'extensionIsInstalled=true;';
  }

  window.addEventListener(
    'message',
    (event) => {
      const data = {
        direction: 'from-content-script',
        responseFor: event.data.id,
        type: 'response',
      };
      if (event.data.action === 'app.info') {
        data.data = versionInfo;
        window.postMessage(data);
      } else if (event.data.action === 'downloads.extractLink') {
        data.data = event.data.data.url;
        window.postMessage(data);
      }
    },
  );

  async function getLinks(meta) {
    if (['Torrent', 'Internal'].includes(meta.type)) {
      const result = {};
      result.provider = meta.type;
      result.url = await fetch(`/api/actions/downloadlink/?id=${meta.id}`)
        .then((data) => data.json())
        .then((json) => json.url);
      return result;
    }
    const result = await fetch(`https://filecr.com/api/actions/worker/?link_id=${meta.id}`)
      .then((data) => data.json())
      .then((json) => ({ provider: json.download_provider, url: json.url }));
    return result;
  }

  async function displayLinks(json) {
    if (document.querySelector('#link-field')) {
      return;
    }
    const trigger = document.querySelector('#trigger');
    const div = document.createElement('div');
    div.id = 'link-field';
    document.querySelector('.download-info').appendChild(div);
    trigger.innerText = 'Loading...';
    const linksMeta = json.props.pageProps.post.downloads[0].links;
    const downloadLinks = await Promise.all(linksMeta.map((meta) => getLinks(meta)));
    downloadLinks.forEach((link, i) => {
      const a = document.createElement('a');
      a.href = link.url;
      a.classList.add('link-light');
      a.innerText = `Link ${i + 1} (${link.provider})\n`;
      div.appendChild(a);
    });
    trigger.innerText = 'COMPLETE!';
  }

  let reloaded = false;
  function addTrigger() {
    if (document.querySelector('.e-404') && !reloaded) {
      reloaded = true;
      window.location.reload();
    }
    if (!document.querySelector('.download-info') || document.querySelector('#trigger')) {
      return;
    }
    const rawJSON = JSON.parse(document.querySelector('#__NEXT_DATA__').textContent);
    const a = document.createElement('a');
    a.id = 'trigger';
    a.innerText = 'GET DOWNLOAD LINKS';
    a.classList.add('link-light');
    if (!window.location.pathname.includes(rawJSON.query.postSlug)) {
      a.addEventListener('click', () => window.location.reload());
      a.innerText += '\n(Data mismatch. Reload is required.)';
    } else {
      a.addEventListener('click', () => displayLinks(rawJSON));
    }
    document.querySelector('.download-info').appendChild(a);
  }

  addTrigger();
  if (window.onurlchange === null) {
    window.addEventListener('urlchange', () => addTrigger());
  } else {
    const observer = new MutationObserver(() => addTrigger());
    observer.observe(document.head, { childList: true });
  }
}());