Greasy Fork is available in English.

闲鱼搜索框

适配新版闲鱼首页,恢复导航栏的大搜索框,移除页面广告,显示列表页过滤栏的小搜索框,显示当前登录用户的出售/已售商品列表,显示商品下面的收藏按钮

  1. // ==UserScript==
  2. // @name 闲鱼搜索框
  3. // @version 1.9.8
  4. // @description 适配新版闲鱼首页,恢复导航栏的大搜索框,移除页面广告,显示列表页过滤栏的小搜索框,显示当前登录用户的出售/已售商品列表,显示商品下面的收藏按钮
  5. // @author yougg
  6. // @match https://www.taobao.com/favicon.ico
  7. // @match http*://2.taobao.com/*
  8. // @match http*://s.2.taobao.com/*
  9. // @match http*://trade.2.taobao.com/*
  10. // @grant none
  11. // @namespace https://yougg.github.io/
  12. // @icon https://gtms02.alicdn.com/tps/i2/TB1VqSxHVXXXXb.XVXXqw4SJXXX-79-60.png
  13. // ==/UserScript==
  14.  
  15. function escapeRegExp(str) {
  16. return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  17. }
  18.  
  19. function replaceAll(str, find, replace) {
  20. return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
  21. }
  22.  
  23. function showFavorite() {
  24. var goods = document.getElementsByClassName('item-other-info');
  25. if (goods.length > 0) {
  26. for (var i = 0; i < goods.length; i++) {
  27. var v = goods[i];
  28. v.innerHTML = replaceAll(replaceAll(v.innerHTML, '<!--<a', '<a'), '</a>-->', '</a>');
  29. }
  30. }
  31. }
  32.  
  33. function showSale() {
  34. var myls = document.getElementsByClassName('my-list');
  35. if (myls.length > 0) {
  36. var ls = myls[0];
  37. if (ls.childElementCount != 4) {
  38. return
  39. }
  40. var nls = ls.cloneNode(true);
  41. ls.parentNode.replaceChild(nls, ls);
  42.  
  43. var onsale = nls.childNodes[0];
  44. var sold = nls.childNodes[1];
  45. onsale.addEventListener("click", function(){window.open('https://trade.2.taobao.com/index.htm?onSale=true')});
  46. sold.addEventListener("click", function(){window.open('https://trade.2.taobao.com/order_list.htm?src=')})
  47. }
  48.  
  49. var sublist = document.getElementsByClassName('sublist');
  50. if (sublist.length <= 0) {
  51. return
  52. }
  53.  
  54. var sl = sublist[0];
  55. if (sl.childElementCount != 4) {
  56. return
  57. }
  58. var nsl = sl.cloneNode(true);
  59. sl.parentNode.replaceChild(nsl, sl);
  60.  
  61. onsale = nsl.childNodes[0];
  62. sold = nsl.childNodes[1];
  63. onsale.addEventListener("click", function(){window.open('https://trade.2.taobao.com/index.htm?onSale=true')});
  64. sold.addEventListener("click", function(){window.open('https://trade.2.taobao.com/order_list.htm?src=')})
  65. }
  66.  
  67. function replaceListUrl() {
  68. // 替换商品瀑布流中的url
  69. var container = document.getElementById('J_ItemListsContainer');
  70. if (container !== null) {
  71. container.innerHTML = replaceAll(container.innerHTML, "list/list.htm", "list/list");
  72. }
  73. }
  74.  
  75. function removeAds() {
  76. // 移除App下载提示
  77. var d = document.getElementsByClassName('download-layer');
  78. if (d.length > 0) {
  79. d[0].parentElement.remove();
  80. }
  81. var d1 = document.getElementsByClassName('pop-wrap');
  82. if (d1.length > 0) {
  83. d1[0].innerHTML = '';
  84. d1[0].className = '';
  85. }
  86. var d2 = document.getElementsByClassName('bottom-wrap');
  87. if (d2.length > 0) {
  88. d2[0].parentElement.innerHTML = '';
  89. }
  90. var m = document.getElementsByClassName('mau-guide');
  91. if (m.length >0) {
  92. m[0].parentNode.removeChild(m[0]);
  93. }
  94. var g = document.getElementsByClassName('xy-guide');
  95. if (g.length > 0) {
  96. g[0].remove();
  97. }
  98. var j = document.getElementById('J_Message');
  99. if (j !== null && j.childElementCount > 0) {
  100. j.firstElementChild.remove();
  101. }
  102. var t = document.getElementById('guarantee');
  103. if (t !== null) {
  104. t.remove();
  105. }
  106. var f = document.getElementById('J_IdleFooter');
  107. if (f !== null) {
  108. f.remove();
  109. }
  110. var b = document.getElementById('J_SideBar');
  111. if (b !== null) {
  112. b.remove();
  113. }
  114. }
  115.  
  116. (function(){
  117. 'use strict';
  118.  
  119. var style = document.createElement('style');
  120. style.type = 'text/css';
  121. style.innerHTML = '.idle-search { position: absolute; right: 65px; top: 27px; width: 222px; height: 36px; background-color: #333; }' +
  122. '.input-search { width: 164px; height: 32px; padding: 0 10px; margin: 0; border: 0; outline: 0; position: absolute; left: 2px; top: 2px; font-size: 13px; }' +
  123. '.btn-search { display: block; width: 36px; height: 36px; position: absolute; top: 0; right: 0; color: #fff; background-color: #333; border: 0; margin: 0; padding: 0; cursor: pointer; outline: 0; }' +
  124. '@font-face{font-family:xy-iconfont;src:url(//at.alicdn.com/t/font_1432608908_2844584.eot);src:url(//at.alicdn.com/t/font_1432608908_2844584.eot?#iefix) format(\'embedded-opentype\'),url(//at.alicdn.com/t/font_1432608908_2844584.woff) format(\'woff\'),url(//at.alicdn.com/t/font_1432608908_2844584.ttf) format(\'truetype\'),url(//at.alicdn.com/t/font_1432608908_2844584.svg#iconfont) format(\'svg\')}' +
  125. '.iconfont { font-family: xy-iconfont; font-size: 18px; font-style: normal; }' +
  126. '.search-img { position: absolute; right: -65px; top: -13px; display: block; width: 79px; height: 60px; background: url(//gtms02.alicdn.com/tps/i2/TB1VqSxHVXXXXb.XVXXqw4SJXXX-79-60.png) no-repeat 0 0; _background: 0 0; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/\', sizingMethod=\'scale\'); zoom: 1; }';
  127. document.getElementsByTagName('head')[0].appendChild(style);
  128. //document.getElementById('xxxElementId').className = 'xxxClass';
  129.  
  130. // 设置首页导航标题偏移,显示被遮挡的“我的闲置”菜单
  131. var tws = document.getElementsByClassName('tab-wrap');
  132. if (tws.length > 0) {
  133. tws[0].style.marginRight='400px';
  134. }
  135.  
  136. // 添加顶部导航栏的大搜索框
  137. var S = document.createElement("div");
  138. S.className = "idle-search";
  139. S.innerHTML = ' <form method="get" action="//s.2.taobao.com/list/list" name="search" target="_top">' +
  140. ' <input class="input-search" id="J_HeaderSearchQuery" name="q" type="text" value="" placeholder="搜闲鱼" />' +
  141. ' <input type="hidden" name="search_type" value="item" autocomplete="off" />' +
  142. ' <input type="hidden" name="app" value="shopsearch" autocomplete="off" />' +
  143. ' <input type="hidden" name="ist" value=0 autocomplete="off" />' +
  144. ' <button class="btn-search" type="submit"><i class="iconfont">&#xe602;</i><span class="search-img"></span></button>' +
  145. ' </form>';
  146. var s0 = document.getElementById("J_IdleHeader");
  147. if (s0 !== null) {
  148. s0.appendChild(S);
  149. }
  150. var s1 = document.getElementsByClassName('navbar-wrap');
  151. if (s1.length > 0) {
  152. s1[0].appendChild(S);
  153. }
  154.  
  155. // 显示列表页过滤栏的小搜索框
  156. var s = document.getElementsByClassName('search-filters-block search-filters');
  157. if (s.length > 0) {
  158. s[0].style.display = "initial";
  159. var action = s[0].parentNode.action;
  160. s[0].parentNode.action = action.replace("list/list.htm", "list/list");
  161. }
  162.  
  163. // 替换分类过滤的url
  164. var category = document.getElementsByClassName('J_HiddenAreaContent sub-category-list clearfix');
  165. if (category.length > 0) {
  166. category[0].innerHTML = replaceAll(category[0].innerHTML, "list/list.htm", "list/list");
  167. }
  168.  
  169. // 替换过滤操作按钮的url
  170. var filters = document.getElementsByClassName('search-filters-block click-filters');
  171. if (filters.length > 0) {
  172. filters[0].innerHTML = replaceAll(filters[0].innerHTML, "list/list.htm", "list/list");
  173. }
  174. var filterpopup = document.getElementsByClassName('search-filters-popup');
  175. if (filterpopup.length > 0) {
  176. filterpopup[0].innerHTML = replaceAll(filterpopup[0].innerHTML, "list/list.htm", "list/list");
  177. }
  178. var filtertoggle = document.getElementsByClassName('search-filters-block toggle-style cur-style-waterfall');
  179. if (filtertoggle.length > 0) {
  180. filtertoggle[0].innerHTML = replaceAll(filtertoggle[0].innerHTML, "list/list.htm", "list/list");
  181. }
  182. var styletoggle = document.getElementsByClassName('search-filters-block toggle-style cur-style-list');
  183. if (styletoggle.length > 0) {
  184. styletoggle[0].innerHTML = replaceAll(styletoggle[0].innerHTML, "list/list.htm", "list/list");
  185. }
  186.  
  187. replaceListUrl();
  188.  
  189. // 替换商品列表分页按钮的url
  190. var paginator = document.getElementById('J_Pages');
  191. if (paginator !== null) {
  192. paginator.innerHTML = replaceAll(paginator.innerHTML, "list/list.htm", "list/list");
  193. }
  194.  
  195. // 备份小搜索框源码,防删
  196. // '<div class="search-filters-block search-filters">' +
  197. // ' <label for="J_SearchFilterInput">搜索</label>' +
  198. // ' <div class="search-input-wrapper">' +
  199. // ' <input id="J_SearchFilterInput" type="text" name="q" value="Pixel XL">' +
  200. // ' </div>' +
  201. // ' <button type="submit">确定</button>' +
  202. // '</div>'
  203.  
  204. document.body.addEventListener("DOMNodeInserted", function (ev) {
  205. // 移除广告
  206. removeAds();
  207. }, false);
  208. document.body.onload = function() {
  209. // 移除广告
  210. removeAds();
  211.  
  212. // 显示当前登录用户的出售/已售商品列表
  213. showSale();
  214.  
  215. // 显示商品下面的收藏按钮
  216. showFavorite();
  217. };
  218. })();