Merge lp:~nathandyer/midori/midori-extension-instapaper into lp:midori
- midori-extension-instapaper
- Merge into trunk
Proposed by
Nathan Dyer
Status: | Needs review |
---|---|
Proposed branch: | lp:~nathandyer/midori/midori-extension-instapaper |
Merge into: | lp:midori |
Diff against target: |
310 lines (+292/-0) 3 files modified
extensions/instapaper.vala (+70/-0) icons/CMakeLists.txt (+2/-0) icons/scalable/status/instapaper.svg (+220/-0) |
To merge this branch: | bzr merge lp:~nathandyer/midori/midori-extension-instapaper |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
gue5t gue5t | Needs Fixing | ||
Review via email: mp+282179@code.launchpad.net |
Commit message
Description of the change
A new extension that allows users to save a web page to their Instapaper account (https:/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'extensions/instapaper.vala' |
2 | --- extensions/instapaper.vala 1970-01-01 00:00:00 +0000 |
3 | +++ extensions/instapaper.vala 2016-01-11 14:42:45 +0000 |
4 | @@ -0,0 +1,70 @@ |
5 | +/* |
6 | + BEGIN LICENSE |
7 | + |
8 | + Copyright (C) 2015-2016 Nathan Dyer <mail@nathandyer.me> |
9 | + |
10 | + This library is free software; you can redistribute it and/or |
11 | + modify it under the terms of the GNU Lesser General Public |
12 | + License as published by the Free Software Foundation; either |
13 | + version 2.1 of the License, or (at your option) any later version. |
14 | + |
15 | + See the file COPYING for the full license text. |
16 | +*/ |
17 | + |
18 | +namespace Instapaper { |
19 | + private class Manager : Midori.Extension { |
20 | + |
21 | + public InstapaperAction instapaper_action; |
22 | + |
23 | + internal Manager () { |
24 | + GLib.Object (name: _("Instapaper"), |
25 | + description: _("Save any web page to Instapaper"), |
26 | + version: "0.1" + Midori.VERSION_SUFFIX, |
27 | + authors: "Nathan Dyer <mail@nathandyer.me>"); |
28 | + |
29 | + activate.connect (this.activated); |
30 | + deactivate.connect (this.deactivated); |
31 | + instapaper_action = new InstapaperAction(); |
32 | + } |
33 | + |
34 | + void browser_added (Midori.Browser browser) { |
35 | + browser.add_action (instapaper_action); |
36 | + |
37 | + // When the button is clicked, activate the javascript function provided directly by Instapaper |
38 | + instapaper_action.activate.connect(() => { |
39 | + string uri = """javascript:function iprl5(){var d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;try{if(!b)throw(0);d.title='(Saving...) '+d.title;z.setAttribute('src',l.protocol+'//www.instapaper.com/j/FJrr4qodg8U1?a=read-later&u='+encodeURIComponent(l.href)+'&t='+(new%20Date().getTime()));b.appendChild(z);}catch(e){alert('Please%20wait%20until%20the%20page%20has%20loaded.');}}iprl5();void(0)"""; |
40 | + browser.uri = uri; |
41 | + }); |
42 | + } |
43 | + |
44 | + void browser_removed(Midori.Browser browser) { |
45 | + browser.remove_action (instapaper_action); |
46 | + } |
47 | + |
48 | + void activated (Midori.App app) { |
49 | + foreach (var browser in app.get_browsers ()) |
50 | + browser_added (browser); |
51 | + app.add_browser.connect (browser_added); |
52 | + } |
53 | + |
54 | + void deactivated () { |
55 | + var app = get_app (); |
56 | + foreach (var browser in app.get_browsers ()) |
57 | + browser_removed(browser); |
58 | + app.add_browser.disconnect (browser_added); |
59 | + } |
60 | + } |
61 | + |
62 | + public class InstapaperAction : Gtk.Action { |
63 | + |
64 | + public InstapaperAction () { |
65 | + GLib.Object (name: "InstapaperStatusMenu"); |
66 | + tooltip = _("Add to Instapaper"); |
67 | + gicon = new GLib.ThemedIcon ("instapaper"); |
68 | + } |
69 | + } |
70 | +} |
71 | + |
72 | +public Midori.Extension extension_init () { |
73 | + return new Instapaper.Manager (); |
74 | +} |
75 | \ No newline at end of file |
76 | |
77 | === modified file 'icons/CMakeLists.txt' |
78 | --- icons/CMakeLists.txt 2015-08-25 21:19:54 +0000 |
79 | +++ icons/CMakeLists.txt 2016-01-11 14:42:45 +0000 |
80 | @@ -18,3 +18,5 @@ |
81 | install_icon(adblock-disabled status ${SIZE}) |
82 | endforeach() |
83 | |
84 | +install_icon(instapaper status scalable) |
85 | + |
86 | |
87 | === added file 'icons/scalable/status/instapaper.svg' |
88 | --- icons/scalable/status/instapaper.svg 1970-01-01 00:00:00 +0000 |
89 | +++ icons/scalable/status/instapaper.svg 2016-01-11 14:42:45 +0000 |
90 | @@ -0,0 +1,220 @@ |
91 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
92 | +<!-- Created with Inkscape (http://www.inkscape.org/) --> |
93 | + |
94 | +<svg |
95 | + xmlns:dc="http://purl.org/dc/elements/1.1/" |
96 | + xmlns:cc="http://creativecommons.org/ns#" |
97 | + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
98 | + xmlns:svg="http://www.w3.org/2000/svg" |
99 | + xmlns="http://www.w3.org/2000/svg" |
100 | + xmlns:xlink="http://www.w3.org/1999/xlink" |
101 | + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" |
102 | + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" |
103 | + version="1.1" |
104 | + width="24" |
105 | + height="24" |
106 | + id="svg4524" |
107 | + inkscape:version="0.91+devel+osxmenu r12898" |
108 | + sodipodi:docname="instapaper.svg"> |
109 | + <sodipodi:namedview |
110 | + pagecolor="#c6c6c6" |
111 | + bordercolor="#666666" |
112 | + borderopacity="1" |
113 | + objecttolerance="10" |
114 | + gridtolerance="10" |
115 | + guidetolerance="10" |
116 | + inkscape:pageopacity="0" |
117 | + inkscape:pageshadow="2" |
118 | + inkscape:window-width="1920" |
119 | + inkscape:window-height="971" |
120 | + id="namedview4575" |
121 | + showgrid="false" |
122 | + showborder="true" |
123 | + inkscape:zoom="1" |
124 | + inkscape:cx="19.932504" |
125 | + inkscape:cy="4.8563179" |
126 | + inkscape:window-x="0" |
127 | + inkscape:window-y="23" |
128 | + inkscape:window-maximized="0" |
129 | + inkscape:current-layer="svg4524" |
130 | + inkscape:object-paths="true" |
131 | + inkscape:snap-intersection-paths="true" |
132 | + inkscape:object-nodes="true" |
133 | + inkscape:snap-smooth-nodes="true" |
134 | + inkscape:snap-midpoints="true"> |
135 | + <inkscape:grid |
136 | + type="xygrid" |
137 | + id="grid5120" |
138 | + empspacing="4" /> |
139 | + </sodipodi:namedview> |
140 | + <defs |
141 | + id="defs4526"> |
142 | + <linearGradient |
143 | + id="linearGradient5964"> |
144 | + <stop |
145 | + offset="0" |
146 | + style="stop-color:#737373;stop-opacity:1" |
147 | + id="stop5966" /> |
148 | + <stop |
149 | + offset="0.26238" |
150 | + style="stop-color:#636363;stop-opacity:1" |
151 | + id="stop5968" /> |
152 | + <stop |
153 | + offset="0.704952" |
154 | + style="stop-color:#4b4b4b;stop-opacity:1" |
155 | + id="stop5970" /> |
156 | + <stop |
157 | + offset="1" |
158 | + style="stop-color:#3f3f3f;stop-opacity:1" |
159 | + id="stop5972" /> |
160 | + </linearGradient> |
161 | + <linearGradient |
162 | + id="linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-641-289-620-227-114-444-680-744-4-1"> |
163 | + <stop |
164 | + id="stop5430-5-0" |
165 | + style="stop-color:#737373;stop-opacity:1" |
166 | + offset="0" /> |
167 | + <stop |
168 | + id="stop5432-2-0" |
169 | + style="stop-color:#636363;stop-opacity:1" |
170 | + offset="0.26238" /> |
171 | + <stop |
172 | + id="stop5434-9-6" |
173 | + style="stop-color:#4b4b4b;stop-opacity:1" |
174 | + offset="0.704952" /> |
175 | + <stop |
176 | + id="stop5436-2-7" |
177 | + style="stop-color:#3f3f3f;stop-opacity:1" |
178 | + offset="1" /> |
179 | + </linearGradient> |
180 | + <radialGradient |
181 | + cx="16.202444" |
182 | + cy="-19.005346" |
183 | + r="19.99999" |
184 | + fx="16.202444" |
185 | + fy="-19.005346" |
186 | + id="radialGradient3896-0" |
187 | + xlink:href="#linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-641-289-620-227-114-444-680-744-4-1-5" |
188 | + gradientUnits="userSpaceOnUse" |
189 | + gradientTransform="matrix(0,1.5000006,-1.5241254,0,-37.218168,-23.077676)" /> |
190 | + <linearGradient |
191 | + id="linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-641-289-620-227-114-444-680-744-4-1-5"> |
192 | + <stop |
193 | + id="stop5430-5-0-9" |
194 | + style="stop-color:#737373;stop-opacity:1" |
195 | + offset="0" /> |
196 | + <stop |
197 | + id="stop5432-2-0-0" |
198 | + style="stop-color:#636363;stop-opacity:1" |
199 | + offset="0.26238" /> |
200 | + <stop |
201 | + id="stop5434-9-6-8" |
202 | + style="stop-color:#4b4b4b;stop-opacity:1" |
203 | + offset="0.704952" /> |
204 | + <stop |
205 | + id="stop5436-2-7-0" |
206 | + style="stop-color:#3f3f3f;stop-opacity:1" |
207 | + offset="1" /> |
208 | + </linearGradient> |
209 | + <linearGradient |
210 | + id="linearGradient9192"> |
211 | + <stop |
212 | + id="stop9196" |
213 | + offset="0" |
214 | + style="stop-color:#ee4056;stop-opacity:1;" /> |
215 | + <stop |
216 | + id="stop9194" |
217 | + offset="1" |
218 | + style="stop-color:#d6394c;stop-opacity:1;" /> |
219 | + </linearGradient> |
220 | + <clipPath |
221 | + clipPathUnits="userSpaceOnUse" |
222 | + id="clipPath4599"> |
223 | + <path |
224 | + inkscape:connector-curvature="0" |
225 | + id="path4601" |
226 | + d="M 81.454545,86.999998 C 71.789011,86.999998 64,94.889003 64,104.68408 c 0,72.55382 13.099571,122.04909 80,122.31487 66.90044,0.26579 80,-49.69947 80,-122.31487 -1e-5,-9.795077 -7.78901,-17.684082 -17.45455,-17.684082 l -125.090905,0 z m 99.371905,39.822672 c 2.74532,0 5.49546,1.07973 7.6033,3.21529 4.21567,4.27113 4.21567,11.20244 0,15.47357 l -36,36.4734 c -2.31516,2.34561 -5.41517,3.31202 -8.42975,3.08132 -3.01458,0.23069 -6.11459,-0.73571 -8.42976,-3.08132 l -35.999988,-36.4734 c -4.215688,-4.27113 -4.215688,-11.20244 0,-15.47357 2.107828,-2.13556 4.885498,-3.18179 7.636348,-3.18179 2.75087,0 5.46242,1.04623 7.57025,3.18179 L 144,159.64539 173.22314,130.03796 c 2.10785,-2.13556 4.85796,-3.21529 7.60331,-3.21529 z" |
227 | + style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient4603);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.5;marker:none;enable-background:accumulate" /> |
228 | + </clipPath> |
229 | + <clipPath |
230 | + clipPathUnits="userSpaceOnUse" |
231 | + id="clipPath5864"> |
232 | + <path |
233 | + inkscape:connector-curvature="0" |
234 | + id="path5866" |
235 | + d="M 81.454545,86.999998 C 71.789011,86.999998 64,94.889003 64,104.68408 c 0,72.55382 13.099571,122.04909 80,122.31487 66.90044,0.26579 80,-49.69947 80,-122.31487 -1e-5,-9.795077 -7.78901,-17.684082 -17.45455,-17.684082 l -125.090905,0 z m 99.371905,39.822672 c 2.74532,0 5.49546,1.07973 7.6033,3.21529 4.21567,4.27113 4.21567,11.20244 0,15.47357 l -36,36.4734 c -2.31516,2.34561 -5.41517,3.31202 -8.42975,3.08132 -3.01458,0.23069 -6.11459,-0.73571 -8.42976,-3.08132 l -35.999988,-36.4734 c -4.215688,-4.27113 -4.215688,-11.20244 0,-15.47357 2.107828,-2.13556 4.885498,-3.18179 7.636348,-3.18179 2.75087,0 5.46242,1.04623 7.57025,3.18179 L 144,159.64539 173.22314,130.03796 c 2.10785,-2.13556 4.85796,-3.21529 7.60331,-3.21529 z" |
236 | + style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient4603);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.5;marker:none;enable-background:accumulate" /> |
237 | + </clipPath> |
238 | + <clipPath |
239 | + clipPathUnits="userSpaceOnUse" |
240 | + id="clipPath6010"> |
241 | + <path |
242 | + inkscape:connector-curvature="0" |
243 | + id="path6012" |
244 | + d="m 5.7454546,3.9799601 c -0.9665543,0 -1.7454548,0.7889004 -1.7454548,1.7684081 0,7.2553808 1.3099577,12.2070898 7.9999992,12.2336678 6.690044,0.02658 8,-4.972128 8,-12.2336678 -10e-7,-0.9795077 -0.7789,-1.7684081 -1.745455,-1.7684081 z m 9.9371894,3.8079331 c 0.274532,0 0.549546,0.1079725 0.76033,0.321529 0.421567,0.4271127 0.421568,1.1202453 0,1.5473572 l -3.6,3.6473386 c -0.231516,0.234561 -0.541516,0.331203 -0.842975,0.308133 -0.301458,0.02306 -0.611463,-0.07358 -0.842975,-0.308133 L 7.5570248,9.6567794 c -0.4215693,-0.427113 -0.4215691,-1.1202445 0,-1.5473572 0.2107828,-0.213556 0.4885497,-0.318179 0.7636343,-0.318179 0.2750879,0 0.5462414,0.1046237 0.7570249,0.318179 l 2.922315,2.9607428 2.922315,-2.9607428 c 0.210785,-0.2135564 0.485795,-0.321529 0.76033,-0.321529 z" |
245 | + style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#3465a4;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.65624976;marker:none;enable-background:accumulate" |
246 | + sodipodi:nodetypes="sssssssssscssssscss" /> |
247 | + </clipPath> |
248 | + <radialGradient |
249 | + inkscape:collect="always" |
250 | + xlink:href="#linearGradient5964" |
251 | + id="radialGradient6054" |
252 | + cx="12" |
253 | + cy="7.5588236" |
254 | + fx="12" |
255 | + fy="7.5588236" |
256 | + r="4" |
257 | + gradientTransform="matrix(7,-7.6454169e-8,7.0993149e-8,6.5,-72.000001,-47.132352)" |
258 | + gradientUnits="userSpaceOnUse" /> |
259 | + <clipPath |
260 | + clipPathUnits="userSpaceOnUse" |
261 | + id="clipPath6781"> |
262 | + <path |
263 | + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" |
264 | + d="m 8,4 0,2 1,0 c 0,0 1,0 1,1 l 0,11 c 0,0 0,1 -1,1 l -1,0 0,2 8,0 0,-2 -1,0 c -1,0 -1,-1 -1,-1 L 14,7 c 0,-1 1,-1 1,-1 l 1,0 0,-2 z" |
265 | + id="path6783" |
266 | + inkscape:connector-curvature="0" |
267 | + sodipodi:nodetypes="ccccccccccccccccc" |
268 | + clip-path="none" /> |
269 | + </clipPath> |
270 | + </defs> |
271 | + <metadata |
272 | + id="metadata4529"> |
273 | + <rdf:RDF> |
274 | + <cc:Work |
275 | + rdf:about=""> |
276 | + <dc:format>image/svg+xml</dc:format> |
277 | + <dc:type |
278 | + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> |
279 | + <dc:title></dc:title> |
280 | + </cc:Work> |
281 | + </rdf:RDF> |
282 | + </metadata> |
283 | + <path |
284 | + style="opacity:0.35;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" |
285 | + d="m 8,6 0,1 1,0 c 0,0 1,0 1,1 l 0,11 c 0,0 0,2 -1,2 l -1,0 0,1 8,0 0,-1 -1,0 c -1,0 -1,-2 -1,-2 L 14,8 c 0,-1 1,-1 1,-1 l 1,0 0,-1 z" |
286 | + id="path6068" |
287 | + inkscape:connector-curvature="0" |
288 | + sodipodi:nodetypes="ccccccccccccccccc" /> |
289 | + <path |
290 | + style="opacity:1;fill:url(#radialGradient6054);fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" |
291 | + d="m 8,4 0,2 1,0 c 0,0 1,0 1,1 l 0,11 c 0,0 0,1 -1,1 l -1,0 0,2 8,0 0,-2 -1,0 c -1,0 -1,-1 -1,-1 L 14,7 c 0,-1 1,-1 1,-1 l 1,0 0,-2 z" |
292 | + id="rect6041" |
293 | + inkscape:connector-curvature="0" |
294 | + sodipodi:nodetypes="ccccccccccccccccc" |
295 | + clip-path="none" /> |
296 | + <path |
297 | + clip-path="url(#clipPath6781)" |
298 | + sodipodi:nodetypes="ccccccccccccccccc" |
299 | + inkscape:connector-curvature="0" |
300 | + id="path6777" |
301 | + d="m 8,4 0,2 1,0 c 0,0 1,0 1,1 l 0,11 c 0,0 0,1 -1,1 l -1,0 0,2 8,0 0,-2 -1,0 c -1,0 -1,-1 -1,-1 L 14,7 c 0,-1 1,-1 1,-1 l 1,0 0,-2 z" |
302 | + style="opacity:0.1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> |
303 | + <path |
304 | + style="opacity:0.03;fill:none;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" |
305 | + d="m 8,4 0,2 1,0 c 0,0 1,0 1,1 l 0,11 c 0,0 0,1 -1,1 l -1,0 0,2 8,0 0,-2 -1,0 c -1,0 -1,-1 -1,-1 L 14,7 c 0,-1 1,-1 1,-1 l 1,0 0,-2 z" |
306 | + id="path6785" |
307 | + inkscape:connector-curvature="0" |
308 | + sodipodi:nodetypes="ccccccccccccccccc" |
309 | + clip-path="url(#clipPath6781)" /> |
310 | +</svg> |
Rather than setting the browser's URI property, JavaScript should be run in the context of the current tab. Under WK1 this context should be available via something like `view.get_ main_frame( ).get_global_ context( )` and via `view.get_ global_ context( )` under WK2. Setting the URI may have undesirable side-effects on history or the locationbar.
That said, it might be even better if we could do this with native code rather than any Javascript. What does the JS string do, is it actually your own work licensed under the LGPL, and how do we know the script it downloads from www.instapaper.com isn't going to change suddenly, breaking released versions of Midori? If Instapaper has an RPC API, it would be better to directly make an HTTP request against that.