mobile01.com 键盘浏览

用方向键 [← / a] 切换前一页,[→ / d] 切换次一页,[↓ / s] 退回外层分类。右上角加入 [我的文章/我的市集] 连结。

目前为 2020-10-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name mobile01.com - navigate with keyboard
  3. // @name:zh-TW mobile01.com 鍵盤瀏覽
  4. // @name:zh-CN mobile01.com 键盘浏览
  5. // @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.
  6. // @description:zh-TW 用方向鍵 [← / a] 切換前一頁,[→ / d] 切換次一頁,[↓ / s] 退回外層分類。右上角加入 [我的文章/我的市集] 連結。
  7. // @description:zh-CN 用方向键 [← / a] 切换前一页,[→ / d] 切换次一页,[↓ / s] 退回外层分类。右上角加入 [我的文章/我的市集] 连结。
  8. // @namespace https://greasyfork.org/zh-TW/users/393133-evan-tseng
  9. // @author Evan Tseng
  10. // @version 1.07
  11. // @match *.mobile01.com/*
  12. // @run-at document-body
  13. // @grant none
  14. // @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.
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. var PageLoaded = false;
  20.  
  21. window.addEventListener("load", function() {
  22. PageLoaded = true;
  23. });
  24.  
  25. var myLink = (function(){
  26. var elm=null;
  27. if(document.querySelector(".l-header__main")){
  28. setTimeout(function(){
  29. if(elm=document.querySelector(".l-signedIn")){
  30. // 登入後,畫面右上角顯示[我的文章]連結
  31. var css=`._myLink{display:inline-block;white-space:nowrap;height:1em;font-size:calc(9pt + .25vw);text-align:center;padding:.3em;line-height:1;margin:calc(.6em - .4vw) 1mm 1px;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}
  32. ._myLink:hover{color:#f3f3f3;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}
  33. ._myLink:active{color:#fff;background:#23803d;margin:calc(.6em - .4vw + 1px) 1mm 0;box-shadow:inset 0 0 0 1px #3a5,inset 0 0 0 2px #ccc,inset 0 0 5px #000;transition:0s}`,
  34. cssStyle=document.createElement('style');
  35. if(cssStyle.styleSheet) cssStyle.styleSheet.cssText=css;
  36. else cssStyle.appendChild(document.createTextNode(css));
  37. document.querySelector('head').appendChild(cssStyle);
  38. var currPos = document.querySelector(".l-header .l-header__left>a").getAttribute("href"),
  39. myArticle=document.createElement('a');
  40. myArticle.setAttribute("class","_myLink");
  41. if(currPos == "/marketindex.php") {
  42. myArticle.appendChild(document.createTextNode("我的市集"));
  43. myArticle.setAttribute("href","/mypurchaselist.php");
  44. myArticle.setAttribute("title","我的市集");
  45. }
  46. else {
  47. myArticle.appendChild(document.createTextNode("我的文章"));
  48. myArticle.setAttribute("href","/participatetopics.php");
  49. myArticle.setAttribute("title","我的文章");
  50. }
  51. elm.appendChild(myArticle);
  52. // 移除指向本頁的連結
  53. elm=document.querySelectorAll(".l-pagination__page.is-active>a, .c-filter a.c-iconLink--gn");
  54. for(let i in elm) if(elm[i].tagName=="A") elm[i].removeAttribute("href");
  55. }}, 200);
  56. }
  57. else if(!PageLoaded) setTimeout(myLink, 1000);
  58. })();
  59.  
  60. document.addEventListener("keydown", async function(e) {
  61. if(document.querySelector("input:focus, textarea:focus") || (e.shiftKey | e.ctrlKey | e.altKey | e.metaKey | e.isComposing)) return;
  62. e = e || window.event;
  63. try{
  64. switch(e.key.toLowerCase()) {
  65. case 'arrowdown':
  66. case 's':
  67. if(window.location.href.match(/\/topicdetail\.php\?/i)) document.querySelector(".c-breadCrumb__item:last-child a").click();
  68. else document.querySelector(".c-breadCrumb__item:nth-last-of-type(-n+2) a").click();
  69. break;
  70. case 'arrowleft':
  71. case 'a':
  72. document.querySelector(".l-pagination__page.is-active").previousSibling.querySelector("a.c-pagination").click();
  73. break;
  74. case 'arrowright':
  75. case 'd':
  76. document.querySelector(".l-pagination__page.is-active").nextSibling.querySelector("a.c-pagination").click();
  77. break;
  78. }
  79. } catch(err){ console.log(err); }
  80. });
  81.  
  82. })();