Greasy Fork

Greasy Fork is available in English.

FR:ES - Viewer

Show all QCs in TaoBao and Yupoo

当前为 2021-05-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         FR:ES - Viewer
// @namespace    https://www.reddit.com/user/RobotOilInc
// @version      0.3.1
// @description  Show all QCs in TaoBao and Yupoo
// @author       RobotOilInc
// @match        http://*/*
// @grant        none
// @license      MIT
// @homepageURL  https://www.qc-server.cf/
// @supportURL   http://greasyfork.icu/en/scripts/426976-fr-es-viewer
// @include      /^https?://((?:item|2)\.taobao|detail\.tmall)\.com/(item|meal_detail)\.(htm|html)\?/
// @include      /^https?://world.(?:taobao|tmall).com/item/\d+.htm/
// @include      /^https?://world.(?:taobao|tmall).com/item/\d+.html/
// @include      /^https?://.*\.x\.yupoo\.com/albums/\d+/
// @require      https://unpkg.com/[email protected]/src/logger.min.js
// @require      https://unpkg.com/[email protected]/dist/jquery.min.js
// @require      https://unpkg.com/@sentry/[email protected]/build/bundle.min.js
// @require      https://unpkg.com/@sentry/[email protected]/build/bundle.tracing.min.js
// @require      https://unpkg.com/[email protected]/dist/swagger-client.browser.min.js
// @require      https://unpkg.com/[email protected]/js/iframeResizer.min.js
// @run-at       document-end
// ==/UserScript==

const _SWAGGER_DOC_URL = 'https://www.qc-server.cf/api/doc.json';
const _DOMAINS = ['https://localhost:8000', 'https://www.qc-server.cf'];
const _VERSION = GM_info.script.version;

// eslint-disable-next-line func-names
(async function () {
  // Setup the logger.
  Logger.useDefaults();

  // Log the start of the script.
  Logger.info(`Starting extension, version ${_VERSION}`);

  // Setup Sentry for proper error logging, which will make my lives 20x easier, use XHR since fetch dies.
  Sentry.init({
    dsn: 'https://[email protected]/5791114',
    integrations: [new Sentry.Integrations.BrowserTracing()],
    transport: Sentry.Transports.XHRTransport,
    release: `viewer-${_VERSION}`,
    environment: 'production',
  });

  /** @type {SwaggerClient} */
  let client;

  // Try to create Swagger client from our own documentation
  try {
    client = await new SwaggerClient({ url: _SWAGGER_DOC_URL });
  } catch (error) {
    Logger.error(`We are unable to connect to FR:ES: ${_SWAGGER_DOC_URL}`, error);
    Sentry.captureException(error);

    return;
  }

  const $iframe = $('<iframe id="qciframe" style="border:0" />');
  $iframe.on('load', () => {
    $iframe.iFrameResize({ checkOrigin: _DOMAINS, bodyMargin: 10, bodyPadding: 10 });
    $iframe.show();
  });

  // Are we on a Yupoo album?
  if (window.location.hostname.includes('yupoo.com')) {
    const id = window.location.href.match(/^https?:\/\/.*\.x\.yupoo\.com\/albums\/(\d+)/)[1];
    const author = window.location.hostname.replace('.x.yupoo.com', '');

    // Build URL
    const request = SwaggerClient.buildRequest({
      spec: client.spec,
      operationId: 'viewYupoo',
      parameters: { id, author },
      responseContentType: 'application/json',
    });

    // Hide, to later show and add the src
    $iframe.hide().attr('src', request.url);

    // Finally append
    $('.showalbum__imagecardwrap').append($iframe);
    return;
  }

  // Are we on a Taobao/Tmall item page?
  if (window.location.hostname.includes('taobao') || window.location.hostname.includes('tmall')) {
    const searchParams = new URLSearchParams(window.location.search);
    const id = searchParams.get('id');

    // Build URL
    const request = SwaggerClient.buildRequest({
      spec: client.spec,
      operationId: 'viewTaobao',
      parameters: { id },
      responseContentType: 'application/json',
    });

    // Hide, to later show and add the src
    $iframe.hide().css('width', '770px').attr('src', request.url);

    // Finally prepend
    $('#description').prepend($iframe);

    return;
  }

  Logger.debug('Unsupported website/missing if statement');
}());