微蚁儿优惠

使用公众号【微蚁儿】返利赚佣金,你可以使用自己的Token也可以使用开发者的token帮助开发者获取佣金喝咖啡☕️

  1. // ==UserScript==
  2. // @name 微蚁儿优惠
  3. // @namespace http://tampermonkey.net/
  4. // @version 20210508.01
  5. // @description 使用公众号【微蚁儿】返利赚佣金,你可以使用自己的Token也可以使用开发者的token帮助开发者获取佣金喝咖啡☕️
  6. // @author shellvon<iamshellvon@gmail.com>
  7. // @match https://item.jd.hk/*
  8. // @match https://item.jd.com/*
  9. // @match https://npcitem.jd.hk/*
  10. // @match https://detail.tmall.hk/*
  11. // @match https://detail.tmall.com/*
  12. // @match https://chaoshi.detail.tmall.com/*
  13. // @match https://item.taobao.com/*
  14. // @match https://detail.vip.com/*
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_getValue
  17. // @grant GM_setValue
  18. // @connect api.3nian.cn
  19. // @icon http://api.3nian.cn/logo.png
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. "use strict";
  24.  
  25. /**
  26. * 默认的获取返利结果后回调函数.
  27. *
  28. * @param {EasyPromotion} easyPromotion
  29. * @param {Object} resp API接口返回的对象
  30. *
  31. * @returns
  32. */
  33. var defaultPromotionCallback = function (easyPromotion, resp) {
  34. var response = resp.response;
  35. var goods =
  36. response && response.data && response.data.list && response.data.list[0];
  37. var tip = "【微蚁儿】当前商品不支持返利";
  38. if (response.code != 200) {
  39. tip = `<span style="color:red;">【错误信息:${response.message}】</span>`;
  40. } else if (goods) {
  41. tip = `<a href='${
  42. goods.promotion_url
  43. }' style='color: #ed6a0c;'>【微蚁儿】预估返利${
  44. goods.commission.money
  45. }元,${
  46. goods.coupon.balance > 0 ? `${goods.coupon.name},` : ""
  47. }点击这里刷新页面再购买即可获得返利</a >`;
  48. }
  49. var container = document.querySelector("#simple-promotion-container");
  50. if (container) {
  51. return (container.firstChild.innerHTML = tip);
  52. }
  53. var 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>`;
  54. tip = containerHtmlTpl.replace("$$tpl", tip);
  55. easyPromotion.getContainer().insertAdjacentHTML("afterbegin", tip);
  56. document
  57. .querySelector("#simple-promotion-container > .reset-btn")
  58. .addEventListener("click", function () {
  59. if (confirm("你真的要重置Token么?")) {
  60. easyPromotion.askAndSaveToken();
  61. easyPromotion.fetchPromotion();
  62. }
  63. });
  64. };
  65.  
  66. /**
  67. * 当前页面被监测到已经推广,则执行该回调。 如果当前回调返回true则继续后续流程,否则提前终止后续流程.
  68. *
  69. * @param {EasyPromotion} easyPromotion
  70. *
  71. * @returns boolean 是否需要继续进行后续
  72. */
  73. var defaultOnPromotedCallback = function (easyPromotion) {
  74. if (!easyPromotion.options || !easyPromotion.options.showPromoted) {
  75. return true;
  76. }
  77. easyPromotion
  78. .getContainer()
  79. .insertAdjacentHTML(
  80. "afterbegin",
  81. `<div style='background: #ecf9ff; color: #1989fa;font-size: 14px;line-height: 50px;padding: 0 16px;margin: 10px 0;'>当前商品直接购买即可获得返利</div>`
  82. );
  83. return false;
  84. };
  85.  
  86. /**
  87. * 简易版分佣
  88. *
  89. * @param {string} uri 分佣站点
  90. * @param {Object} options 配置
  91. */
  92. function EasyPromotion(uri, options) {
  93. this.uri = uri || window.location.href;
  94. // 微蚁儿API接口地址
  95. this.api = "https://api.3nian.cn/openapi/promotion/transfer";
  96. var noop = function () {};
  97. var rules = [
  98. {
  99. name: "jd", // 平台名
  100. pattern: /item\.jd\.(com|hk)/, // 平台匹配模式
  101. container: ".itemInfo-wrap", // 平台放分佣信息的容器选择器,用于document.querySelector
  102. promoted: /(\?|&)utm_campaign=t_2010927340_(&|$)/, // 判断是否被【微蚁儿优惠】返利的正则
  103. },
  104. {
  105. name: "tb",
  106. pattern: /item\.taobao\.(com|hk)/,
  107. container: ".tb-title",
  108. promoted: /(\?|&)ak=28188063(&|$)/,
  109. },
  110. {
  111. name: "vip",
  112. pattern: /detail\.vip\.com/,
  113. container: ".pi-price-box",
  114. promoted: /!$/,
  115. },
  116. {
  117. name: "tmall",
  118. pattern: /detail\.tmall\.(com|hk)/,
  119. container: ".tb-detail-hd",
  120. promoted: /(\?|&)ak=28188063(&|$)/,
  121. },
  122. ];
  123. this.current = rules.filter((el) => el.pattern.test(this.uri))[0];
  124. this.options = Object.assign(
  125. {},
  126. {
  127. defaultToken: "D5QXrUTbtJqUZUFxqC", // 【微蚁儿】公众号内回复[TOKEN]返回的TOKEN,用于接口调用,这样返的佣金计入当前用户账下
  128. tokenKey: "shellvon:token",
  129. showPromoted: true,
  130. onFinish: noop,
  131. onPromoted: noop,
  132. },
  133. options
  134. );
  135. this.token = GM_getValue(this.options.tokenKey);
  136. }
  137.  
  138. /**
  139. * 检测当前uri是否支持
  140. * @returns boolean
  141. */
  142. EasyPromotion.prototype.isSupported = function () {
  143. return !!this.current;
  144. };
  145.  
  146. /**
  147. * 检测当前uri是否已经推广过了
  148. *
  149. * @returns
  150. */
  151. EasyPromotion.prototype.isPromoted = function () {
  152. return this.current && this.current.promoted.test(this.uri);
  153. };
  154.  
  155. /**
  156. * 获取容器
  157. * @returns
  158. */
  159. EasyPromotion.prototype.getContainer = function () {
  160. var selector = this.current && this.current.container;
  161. return document.querySelector(selector || "body");
  162. };
  163.  
  164. /**
  165. * 询问并保存token信息
  166. */
  167. EasyPromotion.prototype.askAndSaveToken = function () {
  168. this.token = prompt(
  169. "关注【微蚁儿】公众号回复“TOKEN”获取凭证,凭证决定佣金计入谁的账户中:",
  170. this.token || this.options.defaultToken
  171. );
  172. if (this.token) {
  173. GM_setValue(this.options.tokenKey, this.token);
  174. } else {
  175. this.askAndSaveToken();
  176. }
  177. };
  178.  
  179. /**
  180. * 调用后台获取返利信息
  181. */
  182. EasyPromotion.prototype.fetchPromotion = function () {
  183. var self = this;
  184. GM_xmlhttpRequest({
  185. method: "POST",
  186. url: self.api,
  187. headers: {
  188. "Content-Type": "application/json",
  189. },
  190. responseType: "json",
  191. data: JSON.stringify({
  192. url: self.uri,
  193. token: self.token,
  194. }),
  195. onload: function (resp) {
  196. self.options.onFinish(self, resp);
  197. },
  198. });
  199. };
  200.  
  201. /**
  202. * 执行真正的分佣流程
  203. *
  204. * @returns
  205. */
  206. EasyPromotion.prototype.doPromotion = function () {
  207. if (!this.isSupported()) {
  208. console.error(`[ERROR]: 当前站点:${uri}暂不支持,请联系开发者进行更新`);
  209. return false;
  210. }
  211. if (this.isPromoted() && !this.options.onPromoted(this)) {
  212. console.warn(
  213. `[WARN]: 当前站点:${uri}已推广且已终止后续流程,终止获取返利信息`
  214. );
  215.  
  216. return true;
  217. }
  218.  
  219. if (!this.token) this.askAndSaveToken();
  220.  
  221. this.fetchPromotion();
  222. };
  223.  
  224. var uri = window.location.href;
  225.  
  226. var easyPromotion = new EasyPromotion(uri, {
  227. defaultToken: "D5QXrUTbtJqUZUFxqC", // 【微蚁儿】公众号内回复[TOKEN]返回的TOKEN,用于接口调用,这样返的佣金计入当当前用户账下
  228. onFinish: defaultPromotionCallback, // 通过API获取到分佣信息之后的回调
  229. onPromoted: defaultOnPromotedCallback, // 监测到当前URL已经被分佣之后的回调
  230. });
  231.  
  232. easyPromotion.doPromotion();
  233. })();

QingJ © 2025

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