购物网 (亞馬遜, 露天, 虾皮, 淘宝, 天猫, 京东, PChome 24h) - 键盘导览

[a / ←]前一页,[d / →]下一页。包含产品列表、照片库、评价页...

目前为 2022-04-20 提交的版本。查看 最新版本

// ==UserScript==
// @name				Shopping website (amazon, jd, ruten, shopee, taobao, tmall) -  keyboard navigation
// @name:zh-TW			購物網 (亞馬遜, 露天, 蝦皮, 淘寶, 天貓, 京東, PChome 24h) - 鍵盤導覽
// @name:zh-CN			购物网 (亞馬遜, 露天, 虾皮, 淘宝, 天猫, 京东, PChome 24h) - 键盘导览
// @description			[a / ←] prev page, [d / →] next page. [s / ↓] parent . Used for the product-list, image-gallery, rate-page...
// @description:zh-TW	[a / ←]前一頁,[d / →]下一頁。包含產品列表、照片庫、評價頁...
// @description:zh-CN	[a / ←]前一页,[d / →]下一页。包含产品列表、照片库、评价页...
// @author				Evan Tseng
// @version				0.5.19
// @namespace			https://gf.qytechs.cn/zh-TW/users/393133-evan-tseng
// @match				*://*24h.pchome.com.tw/*
// @match				*://*.aliexpress.com/*
// @include				*://*.amazon.co*
// @match				*://*.jd.com/*
// @match				*://*.taobao.com/*
// @match				*://*.tmall.com/*
// @match				*://*.momomall.com.tw/*
// @match				*://*.momoshop.com.tw/*
// @match				*://*.ruten.com.tw/*
// @match				*://shopee.tw/*
// @run-at				document-start
// @grant				none
// @license				MIT
// ==/UserScript==

(async function() {
	'use strict';
	var host = window.location.hostname.replace(/(?:\w+\.)*(aliexpress|amazon|jd|momoshop|momomall|pchome|ruten|shopee|taobao|tmall)(?:\.\w+){1,2}$/, "$1").toLowerCase();

	// 按鍵對應元素
	const elmPatt = {
		'aliexpress': {
			enter: [],
			esc: [],
			w: [],
			s: [],
			a: ['.next-pagination-pages button.next-prev'],
			d: ['.next-pagination-pages button.next-next'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: ['.next-pagination-pages button.next-prev'],
			arrowRight: ['.next-pagination-pages button.next-next']
		},
		'amazon': {
			enter: [],
			esc: ['.a-popover-modal .a-button-top-right'],
			w: [],
			s: ['#leftNav .s-ref-indent-neg-micro:nth-last-of-type(2) a', '#departments .a-spacing-micro:nth-last-of-type(2) a', '.a-breadcrumb li:last-of-type a'],
			a: ['ul.a-pagination li:first-of-type>a', '#ivThumbs .ivThumb.selected', '#pagnPrevLink', '.s-pagination-item.s-pagination-previous'],
			d: ['ul.a-pagination li:last-of-type>a', '#ivThumbs .ivThumb.selected', '#pagnNextLink', '.s-pagination-item.s-pagination-next'],
			arrowUp: [],
			arrowDown: ['#leftNav .s-ref-indent-neg-micro:nth-last-of-type(2) a', '#departments .a-spacing-micro:nth-last-of-type(2) a', '.a-breadcrumb li:last-of-type a'],
			arrowLeft: ['ul.a-pagination li:first-of-type>a', '#ivThumbs .ivThumb.selected', '#pagnPrevLink', '.s-pagination-item.s-pagination-previous'],
			arrowRight: ['ul.a-pagination li:last-of-type>a', '#ivThumbs .ivThumb.selected', '#pagnNextLink', '.s-pagination-item.s-pagination-next']
		},
		'jd': {
			enter: [],
			esc: [],
			w: [],
			s: [],
			a: ['.f-pager a.fp-prev:not(.disabled)', '.ui-page a.ui-page-prev', '.preview .arrow-prev:not(.disabled)', '.comments-list .ui-pager-prev'],
			d: ['.f-pager a.fp-next:not(.disabled)', '.ui-page a.ui-page-next', '.preview .arrow-next:not(.disabled)', '.comments-list .ui-pager-next'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: ['.f-pager a.fp-prev:not(.disabled)', '.ui-page a.ui-page-prev', '.preview .arrow-prev:not(.disabled)', '.comments-list .ui-pager-prev'],
			arrowRight: ['.f-pager a.fp-next:not(.disabled)', '.ui-page a.ui-page-next', '.preview .arrow-next:not(.disabled)', '.comments-list .ui-pager-next']
		},
		'momoshop':{
			enter: [],
			esc: [],
			w: [],
			s: [".navlist dd:nth-last-child(2) a"],
			a: [".pageArea .selected"],
			d: [".pageArea .selected"],
			arrowUp: [],
			arrowDown: [".navlist dd:nth-last-child(2) a"],
			arrowLeft: [".pageArea .selected"],
			arrowRight: [".pageArea .selected"]
		},
		'momomall':{
			enter: [],
			esc: [],
			w: [],
			s: [".navlist dd:nth-last-child(2) a"],
			a: [".pageArea .selected"],
			d: [".pageArea .selected"],
			arrowUp: [],
			arrowDown: [".navlist dd:nth-last-child(2) a"],
			arrowLeft: [".pageArea .selected"],
			arrowRight: [".pageArea .selected"]
		},
		'pchome': {
			enter: [],
			esc: [],
			w: [".category dl li.actived"],
			s: [".category dl li.actived"],
			a: ["#PaginationContainer li.sp:first-of-type>a"],
			d: ["#PaginationContainer li.sp:last-of-type>a"],
			arrowUp: [".category dl li.actived"],
			arrowDown: [".category dl li.actived"],
			arrowLeft: ["#PaginationContainer li.sp:first-of-type>a"],
			arrowRight: ["#PaginationContainer li.sp:last-of-type>a"]
		},
		'ruten': {
			enter: [".rt-jqmodal-jqmClose"],
			esc: [".rt-jqmodal-jqmClose"],
			w: [".item-gallery-main-image img.js-main-img"],
			s: [],
			a: ['.sort-section-body .pager-prev:not(.is-disabled)', '.item-gallery .img-popup[style="z-index: 9999; display: block;"] .rti-chevron-left-default', '.pagination .prev', '.rt-pagination li.prev a', '.rt-store-pagination li.prev>a'],
			d: ['.sort-section-body .pager-next:not(.is-disabled)', '.item-gallery .img-popup[style="z-index: 9999; display: block;"] .rti-chevron-right-default', '.pagination .next', '.rt-pagination li.next a', '.rt-store-pagination li.next>a'],
			arrowUp: [".item-gallery-main-image img.js-main-img"],
			arrowDown: [],
			arrowLeft: ['.sort-section-body .pager-prev:not(.is-disabled)', '.item-gallery .img-popup[style="z-index: 9999; display: block;"] .rti-chevron-left-default', '.pagination .prev', '.rt-pagination li.prev a', '.rt-store-pagination li.prev>a'],
			arrowRight: ['.sort-section-body .pager-next:not(.is-disabled)', '.item-gallery .img-popup[style="z-index: 9999; display: block;"] .rti-chevron-right-default', '.pagination .next', '.rt-pagination li.next a', '.rt-store-pagination li.next>a']
		},
		'shopee': {
			enter: [".shopee-alert-popup__button-horizontal-layout>button.shopee-alert-popup__btn:first-child"],
			esc: [],
			w: [".product-briefing .flex-column>div:first-child>div>div:last-child"],
			s: [],
			a: ["#modal .flex>div:first-child>div:nth-last-child(2)", ".shopee-mini-page-controller__prev-btn", ".rating-media-list__zoomed-image--active .rating-media-list-carousel-arrow--prev", ".product-ratings__page-controller .shopee-icon-button.shopee-icon-button--left", ".shopee-page-controller .shopee-icon-button--left", ".shopee-icon-button._1mHKHL", ".product-variation.product-variation--selected"],
			d: ["#modal .flex>div:first-child>div:last-child", ".shopee-mini-page-controller__next-btn", ".rating-media-list__zoomed-image--active .rating-media-list-carousel-arrow--next", ".product-ratings__page-controller .shopee-icon-button.shopee-icon-button--right", ".shopee-page-controller .shopee-icon-button--right", ".shopee-icon-button._2H6_oQ", ".product-variation.product-variation--selected"],
			arrowUp: [".product-briefing .flex-column>div:first-child>div>div:last-child"],
			arrowDown: [],
			arrowLeft: ["#modal .flex", ".shopee-mini-page-controller__prev-btn", ".rating-media-list__zoomed-image--active .rating-media-list-carousel-arrow--prev", ".product-ratings__page-controller .shopee-icon-button.shopee-icon-button--left", ".shopee-page-controller .shopee-icon-button--left", ".shopee-icon-button._1mHKHL", ".product-variation.product-variation--selected"],
			arrowRight: ["#modal .flex", ".shopee-mini-page-controller__next-btn", ".rating-media-list__zoomed-image--active .rating-media-list-carousel-arrow--next", ".product-ratings__page-controller .shopee-icon-button.shopee-icon-button--right", ".shopee-page-controller .shopee-icon-button--right", ".shopee-icon-button._2H6_oQ", ".product-variation.product-variation--selected"]
		},
		'taobao': {
			enter: [],
			esc: ["#J_ViewerClose"],
			w: [],
			s: [],
			a: ['#J_ViewerPrev', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:first-child a.link', '.m-page li.prev a', '.pagination a.prev', '.rate-page a[data-page]:first-child', ".rate-paginator a:first-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerPrev', '.ui-page-prev', '.pagination li.pagination-prev>a'],
			d: ['#J_ViewerNext', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:last-child a.link', '.m-page li.next a', '.pagination a.next', '.rate-page a[data-page]:last-child', ".rate-paginator a:last-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerNext', '.ui-page-next', '.pagination li.pagination-next>a'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: ['#J_ViewerPrev', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:first-child a.link', '.m-page li.prev a', '.pagination a.prev', '.rate-page a[data-page]:first-child', ".rate-paginator a:first-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerPrev', '.ui-page-prev', '.pagination li.pagination-prev>a'],
			arrowRight: ['#J_ViewerNext', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:last-child a.link', '.m-page li.next a', '.pagination a.next', '.rate-page a[data-page]:last-child', ".rate-paginator a:last-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerNext', '.ui-page-next', '.pagination li.pagination-next>a']
		},
		'tmall': {
			enter: [],
			esc: ["#J_ViewerClose"],
			w: [],
			s: [],
			a: ['#J_ViewerPrev', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:first-child a.link', '.m-page li.prev a', '.pagination a.prev', '.rate-page a[data-page]:first-child', ".rate-paginator a:first-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerPrev', '.ui-page-prev', '.pagination li.pagination-prev>a'],
			d: ['#J_ViewerNext', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:last-child a.link', '.m-page li.next a', '.pagination a.next', '.rate-page a[data-page]:last-child', ".rate-paginator a:last-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerNext', '.ui-page-next', '.pagination li.pagination-next>a'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: ['#J_ViewerPrev', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:first-child a.link', '.m-page li.prev a', '.pagination a.prev', '.rate-page a[data-page]:first-child', ".rate-paginator a:first-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerPrev', '.ui-page-prev', '.pagination li.pagination-prev>a'],
			arrowRight: ['#J_ViewerNext', '.tm-m-photos-thumb .tm-current', '#detail .tb-key .tb-prop li.tb-selected', '.m-sortbar .pager li.item:last-child a.link', '.m-page li.next a', '.pagination a.next', '.rate-page a[data-page]:last-child', ".rate-paginator a:last-child", 'div.ks-overlay:not(.ks-overlay-hidden) #J_ViewerNext', '.ui-page-next', '.pagination li.pagination-next>a']
		}
	};

	switch(host) { // 按鍵以外的功能
		case "ruten":
			if(window.location.href.indexOf('ruten.com.tw/find/?') > 0) {
				var watchElm = null;
				const watchOpt = { 'attributes': true },
					  redir = function(){
						  if(window.location.href.search(/(area=|platform=)/) == -1){
							  window.location.href = window.location.href + "&platform=ruten";
						  }
					  },
					  observer = new MutationObserver(redir);
				redir();
				let waitt = window.setInterval(function(){
					if(watchElm = document.querySelector("#ProdGridContainer")){
						observer.observe(watchElm, watchOpt);
						clearInterval(waitt);
					}
				}, 500);
			}
			break;
		case "jd":
			window.scrollTo = function(){};
			break;
	}

	document.addEventListener("keydown", async function(e) {
		if((e.shiftKey | e.ctrlKey | e.altKey | e.metaKey) || document.querySelector("input:focus, textarea:focus, [contenteditable='true']:focus")) return;
		e = e || window.event;
		var elm=null, i;
		try {
			switch(e.key.toLowerCase()) {
				case 'enter':
					for(i in elmPatt[host].enter) if(elm = document.querySelector(elmPatt[host].enter[i])) break;
					break;
				case 'escape':
					for(i in elmPatt[host].esc) if(elm = document.querySelector(elmPatt[host].esc[i])) break;
					break;
				case 'arrowup':
					for(i in elmPatt[host].arrowUp) if(elm = document.querySelector(elmPatt[host].arrowUp[i])) break;
					if( host == 'pchome' && i == 0) elm=elm.previousElementSibling.querySelector("a");
					break;
				case 'arrowdown':
					for(i in elmPatt[host].arrowDown) if(elm = document.querySelector(elmPatt[host].arrowDown[i])) break;
					if( host == 'pchome' && i == 0) elm=elm.nextElementSibling.querySelector("a");
					break;
				case 'arrowleft':
					for(i in elmPatt[host].arrowLeft) if(elm = document.querySelector(elmPatt[host].arrowLeft[i])) break;
					if(host == 'amazon' && i == 1){
						let thumbsTotal = document.querySelectorAll('#ivThumbs .ivRow>.ivThumb').length;
						let picNo = parseInt(elm.getAttribute("id").replace("ivImage_",""));
						elm = document.getElementById("ivImage_"+ (picNo > 0 ? picNo-1 : thumbsTotal-1));
					}
					if((host == 'taobao' || host == 'tmall') && i == 0)	elm=elm.previousElementSibling;
					if((host == 'taobao' || host == 'tmall') && i == 1)	elm=elm.previousElementSibling.querySelector("a");
					if((host == 'momoshop' || host == 'momomall') && i == 0) elm=elm.parentNode.previousElementSibling.querySelector("a");
					if( host == 'shopee' && i == 6) elm=elm.previousElementSibling;
					break;
				case 'arrowright':
					for(i in elmPatt[host].arrowRight) if(elm = document.querySelector(elmPatt[host].arrowRight[i])) break;
					if(host == 'amazon' && i == 1){
						let thumbsTotal = document.querySelectorAll('#ivThumbs .ivRow>.ivThumb').length;
						let picNo = parseInt(elm.getAttribute("id").replace("ivImage_",""));
						elm = document.getElementById("ivImage_"+ (picNo == thumbsTotal-1 ? 0 : picNo+1));
					}
					if((host == 'taobao' || host == 'tmall') && i == 0)	elm=elm.nextElementSibling;
					if((host == 'taobao' || host == 'tmall') && i == 1)	elm=elm.nextElementSibling.querySelector("a");
					if((host == 'momoshop' || host == 'momomall') && i == 0) elm=elm.parentNode.nextElementSibling.querySelector("a");
					if( host == 'shopee' && i == 6) elm=elm.nextElementSibling;
					break;
				case 'w':
					for(i in elmPatt[host].w) if(elm = document.querySelector(elmPatt[host].w[i])) break;
					if( host == 'pchome' && i == 0) elm=elm.previousElementSibling.querySelector("a");
					break;
				case 's':
					for(i in elmPatt[host].s) if(elm = document.querySelector(elmPatt[host].s[i])) break;
					if( host == 'pchome' && i == 0) elm=elm.nextElementSibling.querySelector("a");
					break;
				case 'a':
					for(i in elmPatt[host].a) if(elm = document.querySelector(elmPatt[host].a[i])) break;
					if(host == 'amazon' && i == 1){
						let thumbsTotal = document.querySelectorAll('#ivThumbs .ivRow>.ivThumb').length;
						let picNo = parseInt(elm.getAttribute("id").replace("ivImage_",""));
						elm = document.getElementById("ivImage_"+ (picNo > 0 ? picNo-1 : thumbsTotal-1));
					}
					if((host == 'taobao' || host == 'tmall') && i == 0)	elm = elm.previousElementSibling;
					if((host == 'taobao' || host == 'tmall') && i == 1)	elm = elm.previousElementSibling.querySelector("a");
					if((host == 'momoshop' || host == 'momomall') && i == 0) elm = elm.parentNode.previousElementSibling.querySelector("a");
					if( host == 'shopee' && i == 6) elm = elm.previousElementSibling;
					break;
				case 'd':
					for(i in elmPatt[host].d) if(elm = document.querySelector(elmPatt[host].d[i])) break;
					if(host == 'amazon' && i == 1){
						let thumbsTotal = document.querySelectorAll('#ivThumbs .ivRow>.ivThumb').length;
						let picNo = parseInt(elm.getAttribute("id").replace("ivImage_",""));
						elm = document.getElementById("ivImage_"+ (picNo == thumbsTotal-1 ? 0 : picNo+1));
					}
					if((host == 'taobao' || host == 'tmall') && i == 0)	elm=elm.nextElementSibling;
					if((host == 'taobao' || host == 'tmall') && i == 1)	elm=elm.nextElementSibling.querySelector("a");
					if((host == 'momoshop' || host == 'momomall') && i == 0) elm=elm.parentNode.nextElementSibling.querySelector("a");
					if( host == 'shopee' && i == 6) elm = elm.nextElementSibling;
					break;
			}
			if(elm) elm.click();
		} catch(err){ console.log(err); }
	});

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址