mobile01.com - navigate with keyboard

press keyboard [← / a] to the previous page, [→ / d] to the next page, [↓ / s] back to parent classification. Add "My Article" to the top right corner.

Per 29-02-2020. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         mobile01.com - navigate with keyboard
// @name:zh-TW   mobile01.com 鍵盤瀏覽
// @name:zh-CN   mobile01.com 键盘浏览
// @description:en    press keyboard [← / a] to the previous page, [→ / d] to the next page, [↓ / s] back to parent classification. Add "My Article" to the top right corner.
// @description:zh-TW 用方向鍵 [← / a] 切換前一頁,[→ / d] 切換次一頁,[↓ / s] 退回外層分類。右上角加入 [我的文章] 連結。
// @description:zh-CN 用方向键 [← / a] 切换前一页,[→ / d] 切换次一页,[↓ / s] 退回外层分类。右上角加入 [我的文章] 连结。
// @namespace    https://greasyfork.org/zh-TW/users/393133-evan-tseng
// @author       Evan Tseng
// @version      1.02
// @match        *://www.mobile01.com/*
// @run-at       document-start
// @grant        none
// @description press keyboard [← / a] to the previous page, [→ / d] to the next page, [↓ / s] back to parent classification. Add "My Article" to the top right corner.
// ==/UserScript==

(function() {
	'use strict';

	document.addEventListener("DOMContentLoaded", function() {
		setTimeout(
			function(){
				// 登入後,畫面右上角顯示[我的文章]連結
				var	elm=null;
				if(elm=document.querySelector(".l-signedIn")){
					var css=`._myArticle{display:inline-block;white-space:nowrap;height:1em;font-size:calc(9pt + .25vw);text-align:center;padding:.3em;line-height:1;margin:calc(.6em - .38vw - 1px) 0 1px 1mm;color:#f3f3f3;background:#30A651;border-radius:5pt;text-shadow:0 0 1px #000;box-shadow:inset 0 0 0 1px #30A651,inset 0 0 0 2px #ebeae7;transition:.2s}
						._myArticle:hover{color:#fff;background:#23803d;box-shadow:inset 0 0 0 1px #3a5,inset 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.4);transition:60ms}
						._myArticle:active{color:#ddd;background:#23803d;margin:calc(.6em - .38vw) 0 0 1mm;box-shadow:inset 0 0 0 1px #3a5,inset 0 0 0 2px #ccc,inset 0 0 5px #000;transition:0s}`,
						cssStyle=document.createElement('style');
					if(cssStyle.styleSheet) cssStyle.styleSheet.cssText=css;
					else cssStyle.appendChild(document.createTextNode(css));
					document.querySelector('head').appendChild(cssStyle);
					var myArticle=document.createElement('a');
					myArticle.appendChild(document.createTextNode("我的文章"));
					myArticle.setAttribute("href","/participatetopics.php");
					myArticle.setAttribute("class","_myArticle");
					myArticle.setAttribute("title","我的文章");
					elm.appendChild(myArticle);
				}

				// 移除指向本頁的連結
				elm=document.querySelectorAll(".l-pagination__page.is-active>a, .c-filter a.c-iconLink--gn");
				for(let i in elm) if(elm[i].tagName=="A") elm[i].removeAttribute("href");
			}
			, 300);
	}, false);

	document.addEventListener("keydown", async function(e) {
		if(document.querySelector("input:focus, textarea:focus")) return;
		e = e || window.event;
		try{
			switch(e.which || e.keyCode) {
				case 40: // down
				case 83: // 's'
					if(window.location.href.match(/\/topicdetail\.php\?/i))
						document.querySelector(".c-breadCrumb__item:last-child a").click();
					else
						document.querySelector(".c-breadCrumb__item:nth-last-of-type(-n+2) a").click();
					break;
				case 65: // 'a'
				case 37: // left
					document.querySelector(".l-pagination__page.is-active").previousSibling.querySelector("a.c-pagination").click();
					break;
				case 68: // 'd'
				case 39: // right
					document.querySelector(".l-pagination__page.is-active").nextSibling.querySelector("a.c-pagination").click();
					break;
			}
		} catch(e){
			console.log(e);
		}
	});

})();