露天, 虾皮, 淘宝, 天猫, 京东 - 键盘导览

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

目前为 2020-08-09 提交的版本。查看 最新版本

// ==UserScript==
// @name				ruten.com, shopee.tw, taobao.com, tmall.com, jd.com -  keyboard navigation
// @name:zh-TW			露天, 蝦皮, 淘寶, 天貓, 京東 - 鍵盤導覽
// @name:zh-CN			露天, 虾皮, 淘宝, 天猫, 京东 - 键盘导览
// @description			[a / ←] prev page, [d / →] next page. 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
// @namespace			https://gf.qytechs.cn/zh-TW/users/393133-evan-tseng
// @match				*shopee.tw/*
// @match				*ruten.com.tw/*
// @match				*taobao.com/*
// @match				*tmall.com/*
// @match				*jd.com/*
// @grant				none
// ==/UserScript==
(function() {
	'use strict';

	// 對象元素
	const elementPattern = {
		'ruten': {
			enter: [".rt-jqmodal-jqmClose"],
			esc: [".rt-jqmodal-jqmClose"],
			w: [".item-gallery-main-image img.js-main-img"],
			s: [],
			a: ['.pagination .prev', '.rt-pagination li.prev a', '.rt-store-pagination li.prev>a', '.rt-jqmodal-panel .img-popup-content .rti-chevron-left-default'],
			d: ['.pagination .next', '.rt-pagination li.next a', '.rt-store-pagination li.next>a', '.rt-jqmodal-panel .img-popup-content .rti-chevron-right-default'],
			arrowUp: [".item-gallery-main-image img.js-main-img"],
			arrowDown: [],
			arrowLeft: ['.pagination .prev', '.rt-pagination li.prev a', '.rt-store-pagination li.prev>a', '.rt-jqmodal-panel .img-popup-content .rti-chevron-left-default'],
			arrowRight: ['.pagination .next', '.rt-pagination li.next a', '.rt-store-pagination li.next>a', '.rt-jqmodal-panel .img-popup-content .rti-chevron-right-default']
		},
		'shopee': {
			enter: [".shopee-alert-popup__button-horizontal-layout>button.shopee-alert-popup__btn:first-child"],
			esc: [],
			w: ["._2JMB9h"],
			s: [],
			a: ["._3FzHnX .rv7fwm", ".shopee-mini-page-controller__prev-btn", ".shopee-icon-button.shopee-icon-button--left", ".shopee-icon-button._1mHKHL"],
			d: ["._3FzHnX .HhAy2u", ".shopee-mini-page-controller__next-btn", ".shopee-icon-button.shopee-icon-button--right", ".shopee-icon-button._2H6_oQ"],
			arrowUp: ["._2JMB9h"],
			arrowDown: [],
			arrowLeft: [".shopee-mini-page-controller__prev-btn", ".shopee-icon-button.shopee-icon-button--left", ".shopee-icon-button._1mHKHL"],
			arrowRight: [".shopee-mini-page-controller__next-btn", ".shopee-icon-button.shopee-icon-button--right", ".shopee-icon-button._2H6_oQ"]
		},
		'taobao': {
			enter: [],
			esc: [],
			w: [],
			s: [],
			a: ['.m-sortbar .pager a[trace="srp_select_pageup"]', '.m-page .prev>a', '.pagination a.prev', '.rate-page a[data-page]:first-child', '.ui-page-prev'],
			d: ['.m-sortbar .pager a[trace="srp_select_pagedown"]', '.m-page .next>a', '.pagination a.next', '.rate-page a[data-page]:last-child', '.ui-page-next'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: ['.m-sortbar .pager a[trace="srp_select_pageup"]', '.m-page .prev>a', '.pagination a.prev', '.rate-page a[data-page]:first-child', '.ui-page-prev'],
			arrowRight: ['.m-sortbar .pager a[trace="srp_select_pagedown"]', '.m-page .next>a', '.pagination a.next', '.rate-page a[data-page]:last-child', '.ui-page-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)'],
			d: ['.f-pager a.fp-next:not(.disabled)', '.ui-page a.ui-page-next', '.preview .arrow-next:not(.disabled)'],
			arrowUp: [],
			arrowDown: [],
			arrowLeft: [],
			arrowRight: []

		}
	};

	var host = location.hostname;
	if(host.indexOf('ruten.com')>=0) host = 'ruten';
	else if(host.indexOf('shopee.tw')>=0) host = 'shopee';
	else if(host.indexOf('taobao.com')>=0) host = 'taobao';
	else if(host.indexOf('tmall.com')>=0) host = 'taobao';
	else if(host.indexOf('jd.com')>=0) {
		host = 'jd';
		window.scrollTo = function(){}
	}
	var fnKey = { shift: false, ctrl:false, alt:false, meta:false };

	window.onfocus = function() { fnKey.shift = fnKey.ctrl = fnKey.alt = fnKey.meta = false; }

	document.addEventListener("keydown", function(e) {
		e = e || window.event;
		switch(e.which || e.keyCode) {
			case 16: // shift
				fnKey.shift = true;
				break;
			case 17: // ctrl
				fnKey.ctrl = true;
				break;
			case 18: // alt
				fnKey.alt = true;
				break;
			case 91: // left Meta
			case 93: // right Meta
				fnKey.meta = true;
				break;
		}
	});

	document.addEventListener("keyup", function(e) {
		e = e || window.event;
		switch(e.which || e.keyCode) {
			case 16: // shift
				fnKey.shift = false;
				break;
			case 17: // ctrl
				fnKey.ctrl = false;
				break;
			case 18: // alt
				fnKey.alt = false;
				break;
			case 91: // left Meta
			case 93: // right Meta
				fnKey.meta = false;
				break;
		}
	});

	document.addEventListener("keydown", async function(e) {
		if(document.querySelector("input:focus, textarea:focus") || (fnKey.shift | fnKey.ctrl | fnKey.alt | fnKey.meta)) return;
		e = e || window.event;
		var elm=null, i;
		try {
			switch(e.which || e.keyCode) {
				case 13: // enter
					for(i=0; i<elementPattern[host].enter.length; i++) if(elm=document.querySelector(elementPattern[host].enter[i])) break;
					break;
				case 27: // esc
					for(i=0; i<elementPattern[host].esc.length; i++) if(elm=document.querySelector(elementPattern[host].esc[i])) break;
					break;
				case 38: // up
					for(i=0; i<elementPattern[host].arrowUp.length; i++) if(elm=document.querySelector(elementPattern[host].arrowUp[i])) break;
					break;
				case 37: // left
					for(i=0; i<elementPattern[host].arrowLeft.length; i++) if(elm=document.querySelector(elementPattern[host].arrowLeft[i])) break;
					break;
				case 39: // right
					for(i=0; i<elementPattern[host].arrowRight.length; i++) if(elm=document.querySelector(elementPattern[host].arrowRight[i])) break;
					break;
				case 40: // down
					for(i=0; i<elementPattern[host].arrowDown.length; i++) if(elm=document.querySelector(elementPattern[host].arrowDown[i])) break;
					break;
				case 65: // 'a'
					for(i=0; i<elementPattern[host].a.length; i++) if(elm=document.querySelector(elementPattern[host].a[i])) break;
					break;
				case 68: // 'd'
					for(i=0; i<elementPattern[host].d.length; i++) if(elm=document.querySelector(elementPattern[host].d[i])) break;
					break;
				case 83: // 's'
					for(i=0; i<elementPattern[host].s.length; i++) if(elm=document.querySelector(elementPattern[host].s[i])) break;
					break;
				case 87: // 'w'
					for(i=0; i<elementPattern[host].w.length; i++) if(elm=document.querySelector(elementPattern[host].w[i])) break;
					break;
			}
			if(elm) elm.click();
		}
		catch(e) { console.log(e); }
	});

})();

QingJ © 2025

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