Greasy Fork

Carousell fliter

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

目前为 2022-10-29 提交的版本。查看 最新版本

// ==UserScript==
// @name			Carousell fliter
// @namespace		[email protected]
// @description		用來按照您設定的關鍵字過濾隱藏掉旋轉拍賣商品列表内的特定商品
// @version			3.1
// @icon			https://hr4.com/careers/driveautogroup/images/path-parts.png
// @author			[email protected]
// @match			*://tw.carousell.com/*
// @match			*://tw.carousell.com/search/*
// @exclude			*://tw.carousell.com/p/*
// @exclude			*://tw.carousell.com/login/*
// @exclude			*://tw.carousell.com/inbox/*
// @exclude			*://tw.carousell.com/settings/*
// @exclude			*://*.exclude.com/live_chat*
// @grant			GM_getValue
// @grant			GM_setValue
// @require			https://code.jquery.com/jquery-2.2.4.min.js
// @supportURL		https://www.youtube.com/channel/UCFSN_dR_z4uJz2E8mByRERA
// @homepage		https://www.youtube.com/channel/UCFSN_dR_z4uJz2E8mByRERA
// @grant			GM_xmlhttpRequest
// @connect			*
// @run-at			document-end
// ==/UserScript==

//https://www.youtube.com/user/see7di/playlists?view=1
//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
(function() {
	"use strict";

	var cfg={
		n1:0,
		n2:0,
		n3:0,
		loop:15,
		debug:true,
		str_name:'doli8|go_89|yoya1985|hao8896|nikiwu3849|punkworld|usedphone8850|hukuohsiu|sally1623|girl_cat520|karen133233|hiphopup|vivianshe|_alice_chen|allen94530|stanfer0318|lochelseahaha|ioi_clothes|wuzi0721|summer4510|jianjielin|faith5868|pearl1113|paddystreet|summer4510|molienight|papago999|k11731|caroutest_711twseller1.android|kikiki0131|jenny58117|yuncang03|sobie9205|ava.yu|_box_|spring329|yangwendy|ok7433|angel262728|qiu161|gackyoyo|lover_arisa|candy4041720|appleshop111|b0987245|like0206|09lucky31|ivy1683344|a.w.__shop|andy3188|yeekea0714|papago999|hyl__accessories|loveyou0727|apple.0715|ok7433|kuroedaily|yun_02|r591011391|debbylee8686|kekemoot|jacky.wang2031|otu2kvao|413.043|tijou__|xiaoxiao9520',
	};

	window.setTimeout(function(){ //列表 no loop
		$("iframe").remove();
		//$("header",$("#root")).remove();
		$("footer",$("#main")).remove();
		//$('header[style^="margin-top"]').remove();
		$('p:contains("出售")').parent().parent().parent().remove();
		$("body").prepend("<div id='carousell_box' style='left:"+parseInt(screen.width-200)+"px;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><textarea id='carousell_keys' placeholder='要過濾的關鍵詞,用|分隔' style='height:400px;width:100%;background-color:#eee;padding:0;border:1px solid #ddd;display:none'></textarea><input type='hidden' id='carousell_user' value=''></div></div>");

		$("#carousell_btn").bind("click",function(){
			guoLv();
		});
		$("#carousell_ico").bind("click",function(){
			editKeys()
		});
		$("#carousell_keys").bind("blur",function(){
			saveKeys();
		});

		var str_list=$.trim(GM_getValue("black_list").toLowerCase());
		if(str_list==""){
			str_list='褲|帽|襪|裙|袖|恤|衫|鞋|恤|髮|童裝|足膜|長洋|大衣|上衣|香水|和服|男裝|女裝|短褲|秋裝|蜜粉|卸妝';
			GM_setValue("black_list",str_list);
		}
		$("#carousell_keys").val(str_list);
		$("#carousell_user").val(cfg.str_name);
		if(cfg.debug==true){
			console.log("str_list:"+str_list);
		}
		str_list=null;

		window.setTimeout(function(){ //no loop
			if(isPc()==false){
				cfg.loop=1; //手機版若一次連續多頁多次會導致n3計數器錯誤
				$("#carousell_box").css({"top":"10px","bottom":""});
			}
			$('button:contains("Show more results")').click();
		},500);
	},1500);

	var guoLv=function(){ //Fliter
		cfg.n1++;
		var arr_list=getArray($.trim($("#carousell_keys").val()).toLowerCase());
		//alert(isPc())

		if(cfg.debug==true){
			console.log("arr_list:"+arr_list);
			//$("div[data-testid]").attr("style","border:3px solid red;")
			//$("div[data-testid]").find("div:first").find("a:nth-of-type(2)").attr("style","border:3px solid red;")
			//$("#main div[data-testid]").find("div:first > a > p:nth-child(2)").attr("style","border:3px solid red;")
			//$("div[data-testid]").find("div:first").find("p:nth-of-type(1)").attr("style","border:3px solid red;")
			//$('div > a:eq(2)',$("div[data-testid]")).attr("style","border:3px solid orange;")
		}
		if(isPc()==true){
			var arrlist=$('p[style^="--max"]',$("div[data-testid]"));
		}else{
			var arrlist=$("#main div[data-testid]").find("div:first > a > p:nth-child(2)");
		}
		//console.log(arrlist)
		arrlist.attr("style","border:2px solid blue;--max-line:2;text-transform:lowercase;").each(function(i){
			cfg.n2++;
			var title=$.trim($(this).text()).toLowerCase();
			if(cfg.debug==true){
				console.log("title:"+title);
			}
			var user=$.trim($(this).parent().parent().parent().find('p[data-testid]').text()).toLowerCase();
			var arr_name=getArray($.trim($("#carousell_user").val()).toLowerCase());
			if(cfg.debug==true){
				//$(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid blue");
				console.log("user:"+user);
				console.log("arr_name:"+arr_name);
			}
			var in_user_list=false;
			for(var x in arr_name){
				if(user==arr_name[x].toLowerCase()){
					if(cfg.debug==true){
						$(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid orange");
					}
					cfg.n3++;
					in_user_list=true;
					$(this).parent().parent().parent().parent().remove();
					break;
				}
			}arr_name=null;
			if(in_user_list==false){
				for(var y in arr_list){
					//console.log("title:"+title+" | arr_list[y]:"+arr_list[y])
					if(title.indexOf(arr_list[y])!=-1){
						//$(this).parent().parent().parent().attr("style","border:3px solid blue");
						cfg.n3++;
						$(this).parent().parent().parent().parent().remove();
						break;
					}
				}user=title=arr_list=null;
			}in_user_list=null;
		});arrlist=null;
		$("#carousell_btn").prop("disabled",true);
		$("#carousell_memo").html("第"+cfg.n1+"次過濾,共找到"+cfg.n2+"個商品<br>其中"+cfg.n3+"個已被過濾掉!");

		if(cfg.n1 % cfg.loop == 0){
			$("#carousell_btn").prop("disabled",false);
		}else{
			window.setTimeout(function(){ //no loop
				$('button:contains("Show more results")').click();
				window.setTimeout(function(){
					guoLv();
				},2000);
			},1000);
		}
	}

	var editKeys=function(){
		if($("#carousell_ico").text()=="▼"){
			$("#carousell_ico").text("▲");
			$("#carousell_keys").css({"display":""});
		}else{
			$("#carousell_ico").text("▼");
			$("#carousell_keys").css({"display":"none"});
		}
	}

	var saveKeys=function(){ //Save the keywords
		var str_list=$.trim($("#carousell_keys").val().toLowerCase());
		GM_setValue("black_list",str_list);
		str_list=null;

		$("#carousell_ico").text("▼");
		$("#carousell_keys").css({"display":"none"});
	}

	var isPc=function (){ //pc返回true
		var userAgentInfo=navigator.userAgent;
		var Agents =new Array("Android","iPhone","SymbianOS","Windows Phone","iPad","iPod");
		var flag=true;
		for(var v=0;v<Agents.length;v++) {
			if(userAgentInfo.indexOf(Agents[v])>0) {
				flag=false;
				break;
			}
		}
		return flag;
	}

	var getArray=function(string){ //Get array from string
		if (!string) return [];
		return string.split("|").map(v => v.trim()).filter(v => v.length);
	}
})();