PGDoc Keyboard Guide

用 TamperMonkey 的插件支持 PG 文档的 left/right 翻页

 1 // ==UserScript==
 2 // @name       PGDoc Keyword Guide
 3 // @namespace  http://weibo.com/otcooper
 4 // @version    0.1
 5 // @description  enter something useful
 6 // @match      http://www.postgresql.org/docs/*.html
 7 // @noframes
 8 // @run-at document-end
 9 // @copyright  2014+, Cooper
10 // ==/UserScript==
11 
12 // 加载 jQuery / keymaster 两个 JS 文件
13 var srcs = [
14     'http://cdn.staticfile.org/jquery/2.1.0/jquery.min.js',
15     'http://cdn.staticfile.org/keymaster/1.6.1/keymaster.min.js'
16 ];
17 for (var i = srcs.length - 1; i >= 0; i--) {
18     var tag = document.createElement("script");
19     tag.type = "text/javascript";
20     tag.src = srcs[i];
21     document.body.appendChild(tag);
22 };
23 
24 // 轮循直到 JS 对象加载完成
25 var intv_check = setInterval(check_load, 250);
26 
27 function check_load() {
28     console.log('check js loading');
29     if(typeof jQuery !== 'undefined' && typeof key !== undefined) {
30         console.log('loading finished');
31         bind();
32         clearInterval(intv_check);
33     }
34 }
35 
36 function bind() {
37     key('left', function() {
38         console.log('preview page');
39         $("a[accesskey|='P']")[0].click();
40     });
41     key('right', function() {
42         console.log('next page');
43         $("a[accesskey|='N']")[0].click();
44     });
45 }

Published: February 08 2014

blog comments powered by Disqus