微蚁儿优惠

使用自己的推广信息进行购买商品,然后佣金自己赚

目前為 2021-03-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         微蚁儿优惠
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  使用自己的推广信息进行购买商品,然后佣金自己赚
// @author       shellvon
// @match        https://item.jd.com/*
// @match        https://detail.tmall.com/*
// @match        https://chaoshi.detail.tmall.com/*
// @match        https://item.taobao.com/*
// @match        https://detail.vip.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @connect      api.3nian.cn
// ==/UserScript==

(function() {
    'use strict';
    const uri = window.location.href;
    // 判断当前商品页需要用来展示提示信息的class名字,不同站点名字不一样
    const productItemCls = (/\.jd\.com/.test(uri) && 'itemInfo-wrap') || (/item\.taobao\.com/.test(uri) && 'tb-title') || (/detail\.tmall\.com/.test(uri) && 'tb-detail-hd') || (/detail\.vip\.com/ && 'pi-price-box');
    // 检查是否已经转链
    const qs = window.location.search.substr(1);
    const isTransfered = (/\.jd\.com/.test(uri) && /utm_campaign=t_2010927340_/.test(qs))
                     || ((/item\.taobao\.com/.test(uri) || /detail.tmall.com/.test(uri)) && /ak=28188063/.test(qs));
    if (isTransfered) {
        document.getElementsByClassName(productItemCls)[0].insertAdjacentHTML('afterBegin', `<div style='background: #ecf9ff; color: #1989fa;font-size: 14px;line-height: 50px;padding: 0 16px;margin: 10px 0;'>当前商品直接购买即可获得返利</div>`);
        return ;
    }
    // 微蚁儿API接口地址
    const api = 'https://api.3nian.cn/openapi/promotion/transfer';
    // 微蚁儿公众号内回复[TOKEN]返回的token,用于接口调用,这样返的佣金计入当当前用户账下
    const defaultToken = 'D5QXrUTbtJqUZUFxqC';
    const TOKEN_KEY = "shellvon:token";
    let token = GM_getValue(TOKEN_KEY)
    const askAndSaveToken = function () {
         token = prompt("关注【微蚁儿】公众号回复“TOKEN”获取凭证,凭证决定佣金计入谁的账户中:", defaultToken)
         if (token) GM_setValue(TOKEN_KEY, token)
    }
    if (!token) askAndSaveToken();

    const containerHtmlTpl = "<div id='simple-promotion-container' style='background: #fffbe8;font-size: 14px;line-height: 50px;padding: 0 16px;margin: 10px 0;'>$$tpl<br/><span class='reset-btn' style='background-color: #000; color:white; padding:5px 10px; border-radius:1px; font-size:14px; cursor:pointer'>重置凭证</span></div>";
    GM_xmlhttpRequest({
        method: "POST",
        url: api,
        headers: {
            "Content-Type": "application/json",
        },
        responseType: "json",
        data: JSON.stringify({
            url: uri,
            token: token,
        }),
        onload: function(resp) {
            var response = resp.response
            var goods = response && response.data && response.data.list && response.data.list[0];
            var tip = '当前商品不支持返利'
            if (response.code != 200) {
                tip = `<span style="color:red;">【错误信息:${response.message}】</span>`
            } else if (goods) {
                tip = `<a href='${goods.promotion_url}' style='color: #ed6a0c;'>【微蚁儿】预估返利${goods.commission.money}元,${goods.coupon.balance > 0 ? `${goods.coupon.name},` : ''}点击这里刷新页面再购买即可获得返利</a >`;
            }
            var el = document.querySelector('#simple-promotion-container')
            if (el) {
                el.firstChild.innerHTML = tip;
                return;
            }
            document.getElementsByClassName(productItemCls)[0].insertAdjacentHTML('afterBegin', containerHtmlTpl.replace('$$tpl', tip));
            document.querySelector('#simple-promotion-container > .reset-btn').addEventListener('click', function () {
                if(confirm("你真的要重置Token么?")) {
                    askAndSaveToken();
                    sendRequest()
                }
            })
        }
    });
})();

QingJ © 2025

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