Carousell fliter

用來按照您設定的關鍵字過濾隱藏掉旋轉拍賣商品列表内的特定商品

  1. // ==UserScript==
  2. // @name Carousell fliter
  3. // @namespace see7di@gmail.com
  4. // @description 用來按照您設定的關鍵字過濾隱藏掉旋轉拍賣商品列表内的特定商品
  5. // @version 3.7
  6. // @icon https://hr4.com/careers/driveautogroup/images/path-parts.png
  7. // @author see7di@gmail.com
  8. // @match *://tw.carousell.com/*
  9. // @match *://tw.carousell.com/search/*
  10. // @exclude *://tw.carousell.com/p/*
  11. // @exclude *://tw.carousell.com/login/*
  12. // @exclude *://tw.carousell.com/inbox/*
  13. // @exclude *://tw.carousell.com/settings/*
  14. // @exclude *://*.exclude.com/live_chat*
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @require https://code.jquery.com/jquery-2.2.4.min.js
  18. // @supportURL https://www.youtube.com/channel/UCFSN_dR_z4uJz2E8mByRERA
  19. // @homepage http://7di.net
  20. // @grant GM_xmlhttpRequest
  21. // @connect *
  22. // @run-at document-end
  23. // ==/UserScript==
  24.  
  25. //https://www.youtube.com/user/see7di/playlists?view=1
  26. //https://tw.carousell.com/search/?addRecent=false&canChangeKeyword=false&includeSuggestions=false&price_end=222&price_start=1&sc=0a0208301a0408bce9652a210a05707269636522160a0909000000000000f03f1209090000000000c06b4078012a140a0b636f6c6c656374696f6e7312030a013078012a210a05707269636522160a0909000000000000f03f1209090000000000c06b4078013204080378013a02180742060801100118004a0620012801400150005a020801&searchId=wkcMW7&searchType=all&sort_by=3
  27. (function() {
  28. "use strict";
  29. var cfg={
  30. n1:0,
  31. n2:0,
  32. n3:0,
  33. loop:9,
  34. debug:false,
  35. };
  36.  
  37. console.clear();
  38. window.setTimeout(function(){ //no loop
  39. console.clear();
  40. $("div").each(function(i){
  41. //x++;
  42. $(this).addClass("_"+i);
  43. });
  44. //alert("ok")
  45. $("._6,._637,._658,._674,footer").css({"display":"none"});
  46. },3000);
  47.  
  48. window.setTimeout(function(){ //列表 no loop
  49. $("body").prepend("<div id='carousell_box' style='right:4px;bottom:1px;width:180px;color:white;font-size:12px;background-color:#2c2c2d;font:caption;padding:5px;border-radius:5px;box-shadow:2px 2px 4px #fff;z-index:9999;position:fixed'><div><input type='button' value='點擊此處開始過濾' id='carousell_btn' style='background-color:#ff2636;font-weight:bold;font-size:16px;border-radius:3px;border:1px solid #000;cursor:pointer;'><span id='carousell_ico' style='cursor:pointer;padding-left:7px'>▼</span><p id='carousell_memo' style='margin:9px 0;font-size:12px;'>Carousell fliter!</p><div id='carousell_setting' style='display:none'><textarea id='carousell_keys' placeholder='要過濾的關鍵詞,用|分隔' style='height:400px;width:100%;background-color:#eee;padding:0;border:1px solid #ddd'></textarea><!----></div></div></div>"); //<input type='text' id='carousell_user' value='' style='width:100%;letter-spacing:1px;background-color:#eee;padding:0;border:1px solid #ddd'>
  50.  
  51. $("#carousell_btn").bind("click",function(){
  52. //console.clear();
  53. //$("header",$("#root")).remove();
  54. //$("#main > div > div").find("h1").remove();
  55. //$("#main > div > div").find("ul").remove();
  56. //$("#main > div > div > section:first > div:last").remove();
  57. //$("#carousell_btn").prop("disabled",true);
  58.  
  59. $('button:contains("顯示更多結果")').click();
  60. //$('button:contains("瀏覽更多")').click();
  61.  
  62. window.setTimeout(function(){ //no loop
  63. guoLv();
  64. },2000);
  65. });
  66. $("#carousell_ico").bind("click",function(){
  67. doSetting()
  68. });
  69. $("#carousell_keys").bind("blur",function(){
  70. saveKeys();
  71. });
  72. //$("#carousell_user").bind("blur",function(){
  73. // saveUser();
  74. //});
  75.  
  76. var str_list=$.trim(GM_getValue("black_keys_list")).toLowerCase();
  77. if(str_list==''){
  78. str_list='褲|帽|襪|裙|袖|恤|衫|鞋|恤|髮|童裝|足膜|長洋|大衣|上衣|香水|和服|男裝|女裝|短褲|秋裝|蜜粉|卸妝';
  79. GM_setValue("black_keys_list",str_list);
  80. }
  81. $("#carousell_keys").val(str_list);
  82. if(cfg.debug==true){
  83. console.log("black_keys_list:"+str_list);
  84. }
  85. str_list='';
  86.  
  87. //str_list=$.trim(GM_getValue("black_user_list")).toLowerCase();
  88. //if(str_list==''){
  89. // str_list='vincent31|doli8|go_89|yoya1985';
  90. // GM_setValue("black_user_list",str_list);
  91. //}
  92. //$("#carousell_user").val(str_list);
  93. //if(cfg.debug==true){
  94. // console.log("black_user_list:"+str_list);
  95. //}
  96. str_list=null;
  97.  
  98. //window.setTimeout(function(){ //no loop
  99. //$('a[aria-label]').parent().parent().parent().parent().remove();
  100. //$("#root").find("div:first").attr("style","margin-top:0");
  101. // if(isPc()==false){
  102. // cfg.loop=1; //手機版若一次連續多頁多次會導致n3計數器錯誤
  103. // $("#carousell_box").css({"top":"10px","bottom":""});
  104. // }
  105. // $('button:contains("Show more results")').click();
  106.  
  107. //remove ad
  108. // $("#main div:first").remove();
  109. // $('div[id^="native-ad"]').remove();
  110. // console.clear();
  111. //},1000);
  112. },2000);
  113.  
  114. var guoLv=function(){ //Fliter
  115. cfg.n1++;
  116. var arr_list=getArray($.trim($("#carousell_keys").val()).toLowerCase());
  117. //alert(isPc())
  118.  
  119. if(cfg.debug==true){
  120. //console.log("arr_list:"+arr_list);
  121. //$("div[data-testid]").attr("style","border:3px solid red;")
  122. //$("div[data-testid]").find("div:first").find("a:nth-of-type(2)").attr("style","border:3px solid red;")
  123. //$("#main div[data-testid]").find("div:first > a > p:nth-child(2)").attr("style","border:3px solid red;")
  124. //$("div[data-testid]").find("div:first").find("p:nth-of-type(1)").attr("style","border:3px solid red;")
  125. //$('div > a:eq(2)',$("div[data-testid]")).attr("style","border:3px solid orange;")
  126. }
  127. if(isPc()==true){
  128. var arrlist=$('p[style^="--max"]',$("div[data-testid]"));
  129. }else{
  130. var arrlist=$("#main div[data-testid]").find("div:first > a > p:nth-child(2)");
  131. }
  132. //arrlist=arrlist.attr({"style":"--max-line:2;text-transform:lowercase;"});
  133. //console.log(arrlist)
  134. arrlist.each(function(i){
  135. cfg.n2++;
  136. var title=$.trim($(this).text()).toLowerCase();
  137. if(cfg.debug==true){
  138. console.log("title:"+title);
  139. }
  140. var in_user_list=false;
  141.  
  142. /*
  143. var user=$.trim($(this).parent().parent().parent().find('p[data-testid]').text()).toLowerCase();
  144. var arr_name=getArray($.trim($("#carousell_user").val()).toLowerCase());
  145. for(var x in arr_name){
  146. if(user==arr_name[x].toLowerCase()){
  147. if(cfg.debug==true){
  148. $(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid orange");
  149. }
  150. cfg.n3++;
  151. in_user_list=true;
  152. //$(this).parent().parent().parent().parent().remove();
  153.  
  154. $(this).parent().parent().parent().parent().css({"display":"none"});
  155. break;
  156. }
  157. }user=arr_name=null;
  158. */
  159.  
  160. if(in_user_list==false){
  161. for(var y in arr_list){
  162. //console.log("title:"+title+" | arr_list[y]:"+arr_list[y])
  163. if(title.indexOf(arr_list[y])!=-1){
  164. //$(this).parent().parent().parent().attr("style","border:3px solid blue");
  165. cfg.n3++;
  166.  
  167. var obj1=$(this).parent().parent().parent().parent();
  168. jQuery('*',obj1).add([obj1]).each(function(){
  169. jQuery.event.remove(this);jQuery.removeData(this)
  170. });
  171. obj1.innerHTML='';
  172. obj1.remove();
  173.  
  174. $(this).attr("style","");
  175. //$(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid orange");
  176. //$(this).parent().parent().parent().parent().css({"display":"none"});
  177. break;
  178. }
  179. }
  180. }title=in_user_list=null;
  181. });
  182. arr_list=arrlist=null;
  183. //$("#carousell_memo").html("第"+cfg.n1+"次過濾,共找到"+cfg.n2+"個商品<br>其中"+cfg.n3+"個已被過濾掉!");
  184. //$("#carousell_btn").prop("disabled",false);
  185.  
  186. if(cfg.n1 % cfg.loop == 0){
  187. //$("#carousell_btn").prop("disabled",false);
  188. $("#carousell_box").css({"display":""});
  189. }else{
  190. $("#carousell_box").css({"display":"none"});
  191. window.setTimeout(function(){ //no loop
  192. $('button:contains("顯示更多結果")').click();
  193. $('button:contains("瀏覽更多")').click();
  194. window.setTimeout(function(){
  195. guoLv();
  196. },2000);
  197. },1000);
  198. }
  199. }
  200.  
  201. var doSetting=function(){
  202. if($("#carousell_ico").text()=="▼"){
  203. $("#carousell_ico").text("▲");
  204. $("#carousell_setting").css({"display":""});
  205. }else{
  206. $("#carousell_ico").text("▼");
  207. $("#carousell_setting").css({"display":"none"});
  208. }
  209. }
  210.  
  211. var saveKeys=function(){ //Save the keywords
  212. var str_list=$.trim($("#carousell_keys").val().toLowerCase());
  213. GM_setValue("black_keys_list",str_list);
  214. str_list=null;
  215.  
  216. $("#carousell_ico").text("▼");
  217. $("#carousell_setting").css({"display":"none"});
  218. }
  219.  
  220. var saveUser=function(){ //Save user list
  221. var str_list=$.trim($("#carousell_user").val().toLowerCase());
  222. GM_setValue("black_user_list",str_list);
  223. str_list=null;
  224.  
  225. $("#carousell_ico").text("▼");
  226. $("#carousell_setting").css({"display":"none"});
  227. }
  228.  
  229. var isPc=function (){ //pc返回true
  230. var userAgentInfo=navigator.userAgent;
  231. var Agents =new Array("Android","iPhone","SymbianOS","Windows Phone","iPad","iPod");
  232. var flag=true;
  233. for(var v=0;v<Agents.length;v++) {
  234. if(userAgentInfo.indexOf(Agents[v])>0) {
  235. flag=false;
  236. break;
  237. }
  238. }
  239. return flag;
  240. }
  241.  
  242. var getArray=function(string){ //Get array from string
  243. if (!string) return [];
  244. return string.split("|").map(v => v.trim()).filter(v => v.length);
  245. }
  246. })();