Greasy Fork

Carousell fliter

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

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

// ==UserScript==
// @name			Carousell fliter
// @namespace		[email protected]
// @description		用來按照您設定的關鍵字過濾隱藏掉旋轉拍賣商品列表内的特定商品
// @version			2.0
// @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			http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.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={
		i0:0,
		i1:0,
		i2:0,
		version:"2.0",
		str_list:"",
		arr_list:[],
		debug:false,
		str_demo:"褲|帽|襪|裙|袖|恤|衫|鞋|恤|髮|童裝|足膜|長洋|大衣|上衣|香水|和服|男裝|女裝|短褲|秋裝|蜜粉|卸妝",
		arr_name:["doli8"],
	};

	window.setTimeout(function(){ //列表 no loop
		$("iframe").remove();
		$("footer",$("#main")).remove();
		$("body").prepend("<div 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 Ver: "+cfg.version+"</p><textarea id='carousell_keys' placeholder='要過濾的關鍵詞,用|分隔' style='height:400px;width:100%;background-color:#eee;padding:0;border:1px solid #ddd;display:none'></textarea></div></div>");

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

		cfg.str_list=$.trim(GM_getValue("black_list").toLowerCase());
		if(cfg.str_list==""){
			cfg.str_list=cfg.str_demo.toLowerCase();
			GM_setValue("black_list",cfg.str_list);
		}
		$("#carousell_keys").val(cfg.str_list);
		if(cfg.debug==true){
			console.log(cfg.str_list);
		}
		window.setTimeout(function(){ //no loop
			$('button:contains("Show more results")').click();
		},500);
	},1500);

	var guoLv=function(){ //Fliter
		cfg.i0++;
		cfg.i1=0;
		cfg.i2=0;
		cfg.arr_list=getArray(cfg.str_list);

		if(cfg.debug==true){
			console.log(cfg.arr_list);
		}
		$('p[style^="--max"]',$("div[data-testid]")).attr("style","border:2px solid blue;--max-line:2;text-transform:lowercase;").each(function(i){
			cfg.i1++;
			var title=$(this).text().toLowerCase();
			//$(this).text(title);
			//$(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid blue");
			var user=$.trim($(this).parent().parent().parent().find('p[data-testid]').text().toLowerCase());
			//console.log(user);
			for(var i3 in cfg.arr_name){
				if(user==cfg.arr_name[i3].toLowerCase()){
					//$(this).parent().parent().parent().find('p[data-testid]').attr("style","border:3px solid blue");
					cfg.i2++;
					$(this).parent().parent().parent().parent().remove();
					break;
				}
			}
			for(var i2 in cfg.arr_list){
				if(title.indexOf(cfg.arr_list[i2])!=-1){
					//$(this).parent().parent().parent().attr("style","border:3px solid blue");
					cfg.i2++;
					$(this).parent().parent().parent().parent().remove();
					break;
				}
			}
		});
		$("#carousell_btn").prop("disabled",true);
		$("#carousell_memo").html("第"+cfg.i0+"次過濾,此次找到"+cfg.i1+"個商品<br>其中"+cfg.i2+"個已被過濾掉!");

		if(cfg.i0 % 10 == 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
		cfg.str_list=$.trim($("#carousell_keys").val().toLowerCase());
		GM_setValue("black_list",cfg.str_list);
		cfg.arr_list=getArray(cfg.str_list);
		$("#carousell_ico").text("▼");
		$("#carousell_keys").css({"display":"none"});
	}

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