JLC-TB搜索栏的增强按钮组

TB搜索栏的增强按钮组,为了不误解评论大佬的意思,故改个插件名字,留给有需要的人

目前为 2024-05-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name JLC-TB搜索栏的增强按钮组
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.2
  5. // @description TB搜索栏的增强按钮组,为了不误解评论大佬的意思,故改个插件名字,留给有需要的人
  6. // @author You
  7. // @match https://s.taobao.com/search?**
  8. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.9/layui.min.js
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=taobao.com
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. // 配置信息
  19. const config = () => {
  20. return {
  21. // func中,替换替换对象Key '优信电子'中的func $OBJECT_KEY$会被替换成 "优信电子"
  22. // 这里不做配置
  23. '$OBJECT_KEY$': '_',
  24. storeConf: {
  25. // 优信电子-模糊 这块,名字不能重复
  26. // 只取第一个横线前面的字符
  27. '优信电子-模糊': {
  28. // 支持精确店铺查询,为空则在淘宝首页搜索
  29. url: ``,
  30. },
  31. '集芯电子-模糊': {
  32. // 支持精确店铺查询,为空则在淘宝首页搜索
  33. url: ``,
  34. },
  35. '优信电子-主': {
  36. // 支持精确店铺查询,为空则在淘宝首页搜索
  37. url: `https://youxin-electronic.taobao.com/`,
  38. },
  39. '优信电子-备': {
  40. // 支持精确店铺查询,为空则在淘宝首页搜索
  41. url: `https://shop35338630.taobao.com/`,
  42. },
  43. '集芯电子': {
  44. // 支持精确店铺查询,为空则在淘宝首页搜索
  45. url: `https://shop107953716.taobao.com/`,
  46. },
  47. }
  48. }
  49. }
  50.  
  51. /**
  52. * config加工处理
  53. * @returns
  54. */
  55. const getConfig = () => {
  56. const config_ = config();
  57.  
  58. for (let storeName of Object.keys(config_.storeConf)) {
  59. let storeConfig = config_.storeConf[storeName];
  60. // 混入店铺的基础配置
  61. config_.storeConf[storeName] = { ...storeConfig, ...baseConf() }
  62. }
  63.  
  64. return config_;
  65. }
  66.  
  67. /**
  68. * 深色 随机色
  69. * @returns
  70. */
  71. const srdmRgbColor = () => {
  72. //随机生成RGB颜色
  73. let arr = [];
  74. for (var i = 0; i < 3; i++) {
  75. // 暖色
  76. arr.push(Math.floor(Math.random() * 128 + 64));
  77. // 亮色
  78. // arr.push(Math.floor(Math.random() * 128 + 128));
  79. }
  80. let [r, g, b] = arr;
  81. // rgb颜色
  82. // var color=`rgb(${r},${g},${b})`;
  83. // 16进制颜色
  84. var color = `#${r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)}${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)}`;
  85. return color;
  86. }
  87.  
  88. const baseConf = () => ({
  89. attr: {
  90. 'style': `background: ${srdmRgbColor()};
  91. width: fit-content;
  92. padding: 5px 7px;
  93. position: unset;
  94. margin-right: 10px;
  95. font-size: larger;
  96. height: fit-content;`,
  97. 'lay-on': `func_${(Math.random() + '').replace('0.', '')}`,
  98. },
  99. 'func': function () {
  100. // 跳转店铺逻辑
  101. if ($(this).data('url').length) {
  102. window.open($(this).data('url'), $(this).data('target'))
  103. }
  104. // 模糊匹配模块
  105. else {
  106. if (!$('#q').val().includes(('$OBJECT_KEY$').split('-')[0])) {
  107. const arr = $('#q').val().split(' ')
  108. $('#q').val($('#q').val().replace(` ${arr[arr.length - 1]}`, '') + ' ' + ('$OBJECT_KEY$').split('-')[0])
  109. }
  110. }
  111. $('#button').click()
  112. }
  113. })
  114.  
  115. let html_start = `<div style="display: flex; margin-top: 8px;">`;
  116. let html_content = ``;
  117. let html_end = `</div>`;
  118.  
  119. let funcs_res = {}, funcs = [];
  120. const storeConf = getConfig().storeConf;
  121. for (let storeName of Object.keys(storeConf)) {
  122. const entity = storeConf[storeName];
  123. // 取值
  124. const { attr, url } = entity;
  125. // 标签属性
  126. const attr_res = Object.keys(attr).map(a => `${a}="${attr[a]}"`).join(' ');
  127. // 生成淘宝店铺搜索的链接
  128. const storeSearchPath = url.length ? `${url}/search.htm?keyword=${$('#q').val().replace(/[\ \u4e00-\u9fa5]+/g, '')}` : '';
  129.  
  130. console.log(storeSearchPath)
  131. html_content += `<button class="btn-search" data-url="${storeSearchPath}" data-target="_blank" ${attr_res} type="button">${storeName}</button>`;
  132. // 只取function的正文
  133. const funcContent = entity['func'].toString().replace(/\$OBJECT_KEY\$/g, storeName).replace(/}$/g, '').replace(/(function|\(\) {|\(\){)/g, '')
  134. funcs.push({ [entity.attr['lay-on']]: new Function(funcContent) })
  135. }
  136.  
  137. funcs.forEach(item => {
  138. funcs_res = {
  139. ...funcs_res,
  140. ...item,
  141. }
  142. })
  143. $('#J_Search form').append(html_start + html_content + html_end)
  144.  
  145. layui.use(function () {
  146. layui.util.on('lay-on', funcs_res);
  147. });
  148. })();

QingJ © 2025

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