// ==UserScript== // @name ruten.com.tw // @name:zh-TW 露天拍賣 // @description change page using keyboard arrow key. search products in Ruten as default (exclude ebay, Rakuten). // @description:zh-TW 搜尋結果用鍵盤方向鍵翻頁,搜尋時預設只找露天站內商品(排除 ebay, 樂天) // @namespace https://greasyfork.org/zh-TW/users/393133-evan-tseng // @version 0.1 // @author Evan Tseng // @match *://*.ruten.com.tw/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; document.addEventListener("keydown", function(e) { if(document.querySelector("input:focus, textarea:focus")) return; e = e || window.event; try{ switch(e.which || e.keyCode) { case 39: // right case 68: // 'd' document.querySelector(".ui-search .Ct .pagination .next, .ui-seller .Ct .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(".ui-search .Ct .pagination .prev, .ui-seller .Ct .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; var watchOpt = { 'childList': true }, redir = function(){ if(window.location.href.indexOf("platform=")==-1 && window.location.href.indexOf("area=")==-1){ window.location.href=window.location.href+"&platform=ruten"; } } const observer = new MutationObserver(redir); redir(); var waitt=window.setInterval(function(){ if(watchElm=document.querySelector("#ProdTopPgContainer .info")){ observer.observe(watchElm, watchOpt); clearInterval(waitt); } },300); } })();