Greasy Fork

Carousell fliter

用來過濾隱藏掉旋轉拍賣商品列表内的特定商品

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

// ==UserScript==
// @name			Carousell fliter
// @namespace		[email protected]
// @description		用來過濾隱藏掉旋轉拍賣商品列表内的特定商品
// @version			1.1
// @icon			https://hr4.com/careers/driveautogroup/images/path-parts.png
// @author			[email protected]
// @create			2020-06-05
// @lastmodified	2020-06-08
// @match			*://tw.carousell.com/
// @match			*://tw.carousell.com/*
// @exclude			*://tw.carousell.com/p/*
// @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		http://mailto:[email protected]
// @grant			GM_xmlhttpRequest
// @connect			*
// @run-at			document-end
// ==/UserScript==

//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={
		i1:0,
		i2:0,
		str_list:"",
		arr_list:[],
		_this:{},
		debug:false,
	};

	window.setTimeout(function(){ //列表 no loop
		$("footer",$("#main")).remove();
		$("iframe").remove();
		$("body").prepend("<div style='left:"+parseInt(screen.width-180)+"px;bottom:30px;font-size:12px;background-color:#ff2636;color:yellow;font-weight:bold;text-align:center;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='width:75px;margin-right:5px;color:#fff;font-weight:bold;font-size:16px;background-color:transparent;border:0 solid;cursor:pointer'><p id='carousell_memo'>請點擊開始過濾!</p><textarea id='carousell_keys' placeholder='要過濾的關鍵詞,用|分隔' style='height:20px;width:100%;background-color:#ff2636;border:0 solid'></textarea></div></div>");

		$("#carousell_btn").bind("click",function(){
			guoLv();
		});
		$("#carousell_keys").bind("focus",function(){
			$("#carousell_keys").css({"height":"400px","background-color":"white"});
		});
		$("#carousell_keys").bind("blur",function(){
			saveKeys();
		});

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

		//console.log(cfg.arr_list);
	},1500);

	HTMLElement.prototype.pressKey=function(code){
		var evt=document.createEvent("UIEvents");
		evt.keyCode=code;
		evt.initEvent("keydown",true,true);
		this.dispatchEvent(evt);
	}

	//$("body").keypress(function(e){
	//	//if(e.keyCode == 13){$("#test-ok").click();}
	//	console.log(e);
	//});

	var guoLv=function(){ //執行過濾
		console.log(65);
		cfg.i1=0;
		cfg.i2=0;
		cfg.arr_list=getArray(cfg.str_list);

		console.log(75);
		console.log(cfg.arr_list);
		$('p[style^="--max"]',$("div[data-testid]")).attr("style","border:2px solid blue;--max-line:2;").each(function(i){
			cfg.i1++;
			var title=$(this).text();
			for(var i2 in cfg.arr_list){
				//console.log(cfg.arr_list[i2])
				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;
				}
			}
		});
		//GM_notification(cfg.i2+"Line 已啟動!","注意:","",function(){})
		$("#carousell_memo").text("共有"+cfg.i1+"個,其中"+cfg.i2+"個已移除");

        //console.log($('button:contains("Show more results")').text())
        $('button:contains("Show more results")').click();

		//window.setTimeout(function(){ //no loop
		//	$("#carousell_memo").text("");
		//},10000);
	}

	var saveKeys=function(){ //存儲關鍵字
		cfg.str_list=$.trim($("#carousell_keys").val());
		GM_setValue("black_list",cfg.str_list);
		$("#carousell_keys").css({"height":"20px","background-color":"#ff2636"});
		//cfg.arr_list=getArray(cfg.str_list);
		//console.log(97);
		//console.log(cfg.arr_list);
		//alert("Done!");
	}

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