mobile01.com 簡易鍵盤瀏覽

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

目前為 2020-01-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name mobile01.com - navigate with keyboard
  3. // @name:zh-TW mobile01.com 簡易鍵盤瀏覽
  4. // @name:zh-CN mobile01.com 简易键盘浏览
  5. // @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.
  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.01
  11. // @match www.mobile01.com/*
  12. // @run-at document-start
  13. // @grant none
  14. // @description [← / a] prev page,[→ / d] next page,[↓ / s] parent classification。"my post" link at top right corner.
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. var elm=null;
  21.  
  22. document.addEventListener("keydown", async function(e) {
  23. if(document.querySelector(":focus")) return;
  24. e = e || window.event;
  25. try{
  26. switch(e.which || e.keyCode) {
  27. case 40: // down
  28. case 83: // 's'
  29. if(window.location.href.match(/\/topicdetail\.php\?/i))
  30. document.querySelector(".c-breadCrumb__item:last-child a").click();
  31. else
  32. document.querySelector(".c-breadCrumb__item:nth-last-of-type(-n+2) a").click();
  33. break;
  34. case 65: // 'a'
  35. case 37: // left
  36. document.querySelector(".l-pagination__page.is-active").previousSibling.firstChild.click();
  37. break;
  38. case 68: // 'd'
  39. case 39: // right
  40. document.querySelector(".l-pagination__page.is-active").nextSibling.firstChild.click();
  41. break;
  42. }
  43. } catch(e){}
  44. });
  45.  
  46. document.addEventListener("DOMContentLoaded", function() {
  47. // 登入後,畫面右上角顯示[我的文章]連結
  48. if(elm=document.querySelector(".l-signedIn")){
  49. 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) 0 0 1mm;color:#f3f3f3;background:#30a04c;border-radius:5pt;box-shadow:inset 0 0 0 1px #394,inset 0 0 0 2px #ebeae7;transition:.3s}'+
  50. '._myArticle:hover{margin:calc(.6em - .38vw - 1px) 0 1px 1mm;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:.1s}'+
  51. '._myArticle:active{color:#ddd;background:#23803d;box-shadow:inset 0 0 0 1px #3a5,inset 0 0 0 2px #ddd;transition:.1s}',
  52. cssStyle=document.createElement('style');
  53. if(cssStyle.styleSheet) cssStyle.styleSheet.cssText=css;
  54. else cssStyle.appendChild(document.createTextNode(css));
  55. document.querySelector('head').appendChild(cssStyle);
  56.  
  57. var myArticle=document.createElement('a');
  58. myArticle.setAttribute("href","/participatetopics.php");
  59. myArticle.setAttribute("class","_myArticle");
  60. myArticle.setAttribute("title","我的文章");
  61. myArticle.innerText="我的文章";
  62. elm.appendChild(myArticle);
  63. }
  64.  
  65. // 移除指向本頁的連結
  66. elm=document.querySelectorAll(".l-pagination__page.is-active>a, .c-filter a.c-iconLink--gn");
  67. for(let i in elm) if(elm[i].tagName=="A") elm[i].removeAttribute("href");
  68. }, false);
  69.  
  70. })();