Greasy Fork 还支持 简体中文。

mobile01.com 鍵盤瀏覽

用方向鍵 [← / a] 切換前一頁,[→ / d] 切換次一頁,[↓ / s] 退回外層分類。右上角加入 [我的文章/我的市集] 連結。

目前為 2020-09-07 提交的版本,檢視 最新版本

  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/My Market] 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.06
  11. // @match *.mobile01.com/*
  12. // @grant none
  13. // @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.
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var myLink = (function(){
  19. var elm=null;
  20. if(document.querySelector(".l-header__main")){
  21. setTimeout(function(){
  22. if(elm=document.querySelector(".l-signedIn")){
  23. // 登入後,畫面右上角顯示[我的文章]連結
  24. 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}
  25. ._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}
  26. ._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}`,
  27. cssStyle=document.createElement('style');
  28. if(cssStyle.styleSheet) cssStyle.styleSheet.cssText=css;
  29. else cssStyle.appendChild(document.createTextNode(css));
  30. document.querySelector('head').appendChild(cssStyle);
  31. var currPos = document.querySelector(".l-header .l-header__left>a").getAttribute("href"),
  32. myArticle=document.createElement('a');
  33. myArticle.setAttribute("class","_myLink");
  34. if(currPos == "/marketindex.php") {
  35. myArticle.appendChild(document.createTextNode("我的市集"));
  36. myArticle.setAttribute("href","/mypurchaselist.php");
  37. myArticle.setAttribute("title","我的市集");
  38. }
  39. else {
  40. myArticle.appendChild(document.createTextNode("我的文章"));
  41. myArticle.setAttribute("href","/participatetopics.php");
  42. myArticle.setAttribute("title","我的文章");
  43. }
  44. elm.appendChild(myArticle);
  45. // 移除指向本頁的連結
  46. elm=document.querySelectorAll(".l-pagination__page.is-active>a, .c-filter a.c-iconLink--gn");
  47. for(let i in elm) if(elm[i].tagName=="A") elm[i].removeAttribute("href");
  48. }}, 200);
  49. }
  50. else setTimeout(myLink, 1000);
  51. })();
  52.  
  53. var fnKey = { shift: false, ctrl:false, alt:false, meta:false };
  54. window.onfocus = function() { fnKey.shift = fnKey.ctrl = fnKey.alt = fnKey.meta = false; }
  55.  
  56. document.addEventListener("keyup", function(e) {
  57. e = e || window.event;
  58. switch(e.which || e.keyCode) {
  59. case 16: // shift
  60. fnKey.shift = false;
  61. break;
  62. case 17: // ctrl
  63. fnKey.ctrl = false;
  64. break;
  65. case 18: // alt
  66. fnKey.alt = false;
  67. break;
  68. case 91: // left Meta
  69. case 93: // right Meta
  70. fnKey.meta = false;
  71. break;
  72. }
  73. });
  74.  
  75. document.addEventListener("keydown", async function(e) {
  76. if(document.querySelector("input:focus, textarea:focus") || (fnKey.shift | fnKey.ctrl | fnKey.alt | fnKey.meta)) return;
  77. e = e || window.event;
  78. try{
  79. switch(e.which || e.keyCode) {
  80. case 16: // shift
  81. fnKey.shift = true;
  82. break;
  83. case 17: // ctrl
  84. fnKey.ctrl = true;
  85. break;
  86. case 18: // alt
  87. fnKey.alt = true;
  88. break;
  89. case 91: // left Meta
  90. case 93: // right Meta
  91. fnKey.meta = true;
  92. break;
  93. case 40: // down
  94. case 83: // 's'
  95. if(window.location.href.match(/\/topicdetail\.php\?/i)) document.querySelector(".c-breadCrumb__item:last-child a").click();
  96. else document.querySelector(".c-breadCrumb__item:nth-last-of-type(-n+2) a").click();
  97. break;
  98. case 65: // 'a'
  99. case 37: // ArrowLeft
  100. document.querySelector(".l-pagination__page.is-active").previousSibling.querySelector("a.c-pagination").click();
  101. break;
  102. case 68: // 'd'
  103. case 39: // ArrowRight
  104. document.querySelector(".l-pagination__page.is-active").nextSibling.querySelector("a.c-pagination").click();
  105. break;
  106. }
  107. } catch(e){ console.log(e); }
  108. });
  109.  
  110. })();