Hotkey for Random Pocket article

Go to random Pocket article with a keypress.

目前为 2021-12-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hotkey for Random Pocket article
  3. // @namespace rafaelc.org
  4. // @version 0.1.6
  5. // @description Go to random Pocket article with a keypress.
  6. // @author Rafael Cavalcanti <https://rafaelc.org/dev>
  7. // @license Apache License 2.0
  8. // @homepageURL https://rafaelc.org/posts/reading-random-pocket-articles-with-a-hotkey/
  9. // @include *
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // jshint esversion: 6
  14.  
  15.  
  16. const onKeyDown = (e) => {
  17. const keyAlt = e.altKey;
  18. const keyCtrl = e.ctrlKey;
  19. const keyShift = e.shiftKey;
  20.  
  21. const keyCode = e.which === 0 ? e.charCode : e.keyCode;
  22.  
  23. if (keyAlt && !keyCtrl && keyShift) {
  24. switch(keyCode){
  25. case 82: // match 'r' key
  26. goToRandomArticle();
  27. break;
  28. case 69: // match 'e' key
  29. searchPageOnPocket();
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. const goToRandomArticle = () => {
  36. document.location = 'https://getpocket.com/random';
  37. }
  38.  
  39. const searchPageOnPocket = () => {
  40. const query = escape(document.title.substr(0, 20));
  41. const url = 'https://getpocket.com/my-list/search?query=' + query;
  42. document.location = url;
  43. }
  44.  
  45.  
  46. (function() {
  47. 'use strict';
  48. document.addEventListener('keydown', onKeyDown);
  49. })();