Pocket Random Hotkey

Go to random Pocket article with a keypress.

目前为 2020-12-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         Pocket Random Hotkey
// @namespace    rafaelc.org
// @version      0.1.1
// @description  Go to random Pocket article with a keypress.
// @author       Rafael Cavalcanti - rafaelc.org
// @license      Apache License 2.0
// @include      *
// @grant        none
// ==/UserScript==

// jshint esversion: 6


const onKeyDown = (e) => {
  const keyAlt = e.altKey;
  const keyCtrl = e.ctrlKey;
  const keyShift = e.shiftKey;

  const keyCode = e.which === 0 ? e.charCode : e.keyCode;

  if (keyAlt && !keyCtrl && keyShift) {
    switch(keyCode){
      case 82: // match 'r' key
        goToRandomArticle();
        break;
            
      case 69: // match 'e' key
        searchPageOnPocket();
        break;
    }
  }
}

const goToRandomArticle = () => {
  document.location = 'https://getpocket.com/random';
}

const searchPageOnPocket = () => {
  const query = document.title.substr(0, 20).replaceAll(' ','%20');
  const url = 'https://app.getpocket.com/search/' + query;
  document.location = url;
}


(function() {
  'use strict';
  document.addEventListener('keydown', onKeyDown);
})();