Greasy Fork

来自缓存

Greasy Fork is available in English.

FR:ES - Viewer

Show all QCs in TaoBao and Yupoo

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

// ==UserScript==
// @name        FR:ES - Viewer
// @namespace   https://www.reddit.com/user/RobotOilInc
// @author      RobotOilInc
// @version     1.1.0
// @description Show all QCs in TaoBao and Yupoo
// @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+/
// @connect     self
// @connect     localhost
// @require     https://code.jquery.com/jquery-3.4.1.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.js
// @require     http://greasyfork.icu/scripts/426983-gm-fetch/code/GM%20Fetch.js
// @require     https://unpkg.com/swagger-client
// @grant       GM_xmlhttpRequest
// @run-at      document-end
// ==/UserScript==
'use strict';

/* jshint esversion: 8 */
/* globals $: false, SwaggerClient: false */

const _version = "1.0.0";
const _swagger_doc_url = "https://localhost:8000/api/doc.json";
const _domains = ['https://localhost:8000', 'https://fashionreps.tools'];

(async function () {
    // Create Swagger client from our own documentation
    const client = await new SwaggerClient(_swagger_doc_url);

    const $iframe = $('<iframe id="qciframe" style="border:0" />')
    $iframe.on('load', function () {
        $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;
    }

    console.debug("Unsupported website/missing if statement");
})();