Skip to content

Commit 2a8dc67

Browse files
committed
Initial commit.
0 parents  commit 2a8dc67

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## pentareader
2+
3+
pentareader: a [Pentadactyl][pdlink] plugin interfacing Firefox's [reader
4+
view][rview].
5+
6+
7+
### Usage
8+
9+
* `:reader` or `:unreader`: enable/disable reader view, if applicable.
10+
* `:togglereader`, `:tr`: toggle reader view mode.
11+
* The optional `.penta` file adds a keyboard mapping
12+
<kbd>&lt;Leader&gt;</kbd><kbd>r</kbd> for the `:togglereader` command.
13+
The <kbd>&lt;Leader&gt;</kbd> key is the back-solidus <kbd>&bsol;</kbd> by
14+
default, but can be configured in your `.pentadactylrc` file.
15+
16+
17+
### Installation
18+
19+
Copy the files `pentaread.js` and `pentaread.penta` to your
20+
`~/.pentadactyl/plugins/` directory. After that you may need to rehash
21+
Pentadactyl (`:rehash`) or restart Firefox.
22+
23+
24+
### Copyright
25+
26+
Copyright (c) 2017, Cong Ma
27+
All rights reserved.
28+
29+
30+
Redistribution and use in source and binary forms, with or without
31+
modification, are permitted provided that the following conditions are met:
32+
33+
* Redistributions of source code must retain the above copyright notice,
34+
this list of conditions and the following disclaimer.
35+
* Redistributions in binary form must reproduce the above copyright notice,
36+
this list of conditions and the following disclaimer in the documentation
37+
and/or other materials provided with the distribution.
38+
39+
40+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
41+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
42+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
44+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50+
51+
52+
53+
[pdlink]: https://github.com/5digits/dactyl/
54+
[rview]: https://support.mozilla.org/t5/Basic-Browsing/Firefox-Reader-View-for-clutter-free-web-pages/ta-p/38466

pentaread.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* pentaread -- Pentadactyl plugin interfacing Firefox's reader view. See
2+
* embedded documentation.
3+
*
4+
* Installation:
5+
* Copy the .js and .penta (optional) files to ~/.pentadactyl/plugins/
6+
* The JavaScript file implements the :reader and :unreader commands,
7+
* and the command :togglereader to swith between the modes.
8+
* The .penta file creates key mappings in normal mode.
9+
*
10+
* Copyright:
11+
* Copyright (c) 2017, Cong Ma <cma@pmo.ac.cn>
12+
* All rights reserved.
13+
*
14+
* License:
15+
* BSD license <http://opensource.org/licenses/BSD-2-Clause>
16+
*/
17+
18+
"use strict";
19+
20+
21+
var readerhead = "about:reader?url=";
22+
23+
24+
/* Return boolean: are we in reader mode? */
25+
var reader_mode_p = function ()
26+
{
27+
return buffer.documentURI.spec.startsWith(readerhead);
28+
};
29+
30+
/* Go to reader view of current buffer (web page) */
31+
var to_reader = function ()
32+
{
33+
if ( buffer.documentURI.schemeIs("http") ||
34+
buffer.documentURI.schemeIs("https") )
35+
{
36+
return dactyl.open("".concat(readerhead,
37+
encodeURIComponent(buffer.documentURI.spec)));
38+
} else {
39+
return dactyl.echoerr("pentaread: error: URI scheme not applicable.");
40+
};
41+
};
42+
43+
/* Go from reader view to normal web page view */
44+
var from_reader = function ()
45+
{
46+
if ( reader_mode_p() )
47+
{
48+
return dactyl.open(decodeURIComponent(
49+
buffer.documentURI.spec.replace(readerhead, "")));
50+
} else {
51+
return dactyl.echoerr("pentaread: error: buffer not in reader mode.");
52+
};
53+
};
54+
55+
/* Toggle reader mode */
56+
var toggle_reader = function ()
57+
{
58+
if ( reader_mode_p() )
59+
return from_reader();
60+
else
61+
return to_reader();
62+
};
63+
64+
65+
/* Pentadactyl commands */
66+
group.commands.add(["reader"],
67+
"Go to reader view of current page.",
68+
to_reader,
69+
{"argcount": 0},
70+
true)
71+
72+
group.commands.add(["unreader"],
73+
"Go from reader view to web page.",
74+
from_reader,
75+
{"argcount": 0},
76+
true)
77+
78+
group.commands.add(["togglereader", "tr"],
79+
"Toggle reader view.",
80+
toggle_reader,
81+
{"argcount": 0},
82+
true)
83+
84+
/* Plugin manifest */
85+
var INFO =
86+
["plugin", {
87+
name: "pentaread",
88+
version: "0.1",
89+
href: "https://github.com/congma/pentaread/",
90+
summary: "pentaread - access Firefox reader mode from Pentadactyl",
91+
xmlns: "dactyl"},
92+
93+
["author", {
94+
email: "cma@pmo.ac.cn",
95+
href: "https://cma.lamost.org/"}, "Cong Ma"],
96+
97+
["license", {href: "http://opensource.org/licenses/BSD-2-Clause"},
98+
"BSD License"],
99+
100+
["project", {name: "Pentadactyl", "min-version": "1.0" }],
101+
102+
["p", {},
103+
"The plugin ", ["str", {}, "pentaread"], " interfaes Firefox's ",
104+
" Reader View feature."],
105+
106+
["item", {},
107+
["tags", {}, ":reader"],
108+
["strut", {}],
109+
["spec", {}, ":reader"],
110+
["description", {},
111+
["p", {}, "Go to reader view of current web page."]]],
112+
113+
["item", {},
114+
["tags", {}, ":unreader"],
115+
["strut", {}],
116+
["spec", {}, ":unreader"],
117+
["description", {},
118+
["p", {}, "Go from reader view to web page."]]],
119+
120+
["item", {},
121+
["tags", {}, ":tr :togglereader"],
122+
["strut", {}],
123+
["spec", {}, ":togglereader"],
124+
["description", {},
125+
["p", {}, "Toggle reader view."],
126+
["p", {},
127+
"By default, this command is mapped to",
128+
" the key combo ", ["str", {}, ["k", {name: "Leader"}], "r"],
129+
":"],
130+
["code", {},
131+
["ex", {}, ":nmap"], " ", ["k", {name: "Leader"}],
132+
"r ", ["ex", {}, ":togglereader"], ["k", {name: "CR"}]]]]];

pentaread.penta

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Use the <Leader>r key combo to access the :togglereader command.
2+
nmap <Leader>r :togglereader<CR>
3+
4+
5+
" vim: set ft=pentadactyl

0 commit comments

Comments
 (0)