Greasy Fork

Greasy Fork is available in English.

Ruten - navigate by keyboard

In search result, change page by keyboard. [a / ←]:prev page, [d / →]:next page. Search products in Ruten as default (exclude ebay, Rakuten).

当前为 2020-07-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name		Ruten - navigate by keyboard
// @name:zh-TW	露天拍賣 鍵盤導覽
// @description			In search result, change page by keyboard. [a / ←]:prev page, [d / →]:next page. Search products in Ruten as default (exclude ebay, Rakuten).
// @description:zh-TW	搜尋結果用鍵盤翻頁,[a / ←]前一頁,[d / →]下一頁。搜尋時預設只找露天站內商品(排除 ebay, 樂天)
// @namespace	http://greasyfork.icu/zh-TW/users/393133-evan-tseng
// @version		0.4
// @author		Evan Tseng
// @match		*.ruten.com.tw/*
// @grant		none
// ==/UserScript==

(function() {
	'use strict';

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

	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;
		try{
			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;
				case 39: // right
				case 68: // 'd'
					document.querySelector(".pagination .next, .rt-pagination li.next a, .rt-store-pagination li.next>a, .rt-jqmodal-panel .img-popup-content .rti-chevron-right-default").click();
					break;
				case 37: // left
				case 65: // 'a'
					document.querySelector(".pagination .prev, .rt-pagination li.prev a, .rt-store-pagination li.prev>a, .rt-jqmodal-panel .img-popup-content .rti-chevron-left-default").click();
					break;
				case 38: // up
				case 87: // 'w'
					document.querySelector(".item-gallery-main-image img.js-main-img").click();
					break;
				case 13: // enter
				case 27: // esc
					document.querySelector(".rt-jqmodal-jqmClose").click();
			}
		} catch(e){}
	});

	if(window.location.href.indexOf('//find.ruten.com.tw/s/?')>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);
	}

})();