Skip to content

Commit 7117a77

Browse files
committed
Fix conflicts.
2 parents a4f7364 + c380334 commit 7117a77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+7257
-2140
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<p align="center"><img src="http://ojec5ddd5.bkt.clouddn.com/logo%20bigger.png" /></p>
22
<h1 align="center">简悦 - SimpRead</h1>
33
<p align="center">让你瞬间进入沉浸式阅读的扩展,还原阅读的本质,提升你的阅读体验。</p>
4-
<p align="center">为了达到完美的阅读模式这个小目标 ,我适配了 <a target="_blank" href="https://github.com/kenshin/simpread/wiki/适配站点列表">240+</a> 个网站,因此诞生了简悦。</p>
4+
<p align="center">为了达到完美的阅读模式这个小目标 ,我适配了 <a target="_blank" href="https://github.com/kenshin/simpread/wiki/适配站点列表">数百种类型</a> 的网站,因此诞生了简悦。</p>
55
<p align="center">
6-
<a href="https://github.com/kenshin/simpread/releases"><img src="https://img.shields.io/badge/lastest_version-1.1.0-blue.svg"></a>
6+
<a href="https://github.com/kenshin/simpread/releases"><img src="https://img.shields.io/badge/lastest_version-1.1.1-blue.svg"></a>
77
<a target="_blank" href="http://ksria.com/simpread"><img src="https://img.shields.io/badge/website-_simpread.ksria.com-1DBA90.svg"></a>
88
</p>
99
<p align="center">
1010
<a target="_blank" href="https://chrome.google.com/webstore/detail/%E7%AE%80%E6%82%A6-simpread/ijllcpnolfcooahcekpamkbidhejabll"><img src="https://img.shields.io/badge/download-_chrome_webstore-brightgreen.svg"></a>
11-
<a href="http://ksria.com/simpread/crx/1.1.0/simpread.crx"><img src="https://img.shields.io/badge/download-_crx-brightgreen.svg"></a>
11+
<a href="http://ksria.com/simpread/crx/1.1.1/simpread.crx"><img src="https://img.shields.io/badge/download-_crx-brightgreen.svg"></a>
1212
<a target="_blank" href="https://addons.mozilla.org/zh-CN/firefox/addon/simpread"><img src="https://img.shields.io/badge/download-_firefox_addon-DD512A.svg"></a>
1313
<a target="_blank" href="https://greasyfork.org/zh-CN/scripts/39998"><img src="https://i.imgur.com/JFhxHeR.png"></a>
1414
<a target="_blank" href="https://xteko.com/redir?url=http://ojec5ddd5.bkt.clouddn.com/jsbox/simpread-1.0.0.box?201805251238&name=%E7%AE%80%E6%82%A6"><img src="https://i.imgur.com/zZeOllB.png"></a>
@@ -17,7 +17,7 @@
1717
***
1818

1919
#### 马上使用:
20-
* [Chrome 应用商店](https://chrome.google.com/webstore/detail/%E7%AE%80%E6%82%A6-simpread/ijllcpnolfcooahcekpamkbidhejabll) 或者 [离线下载](http://ksria.com/simpread/crx/1.1.0/simpread.crx)
20+
* [Chrome 应用商店](https://chrome.google.com/webstore/detail/%E7%AE%80%E6%82%A6-simpread/ijllcpnolfcooahcekpamkbidhejabll) 或者 [离线下载](http://ksria.com/simpread/crx/1.1.1/simpread.crx)
2121
* [Firefox 扩展中心](https://addons.mozilla.org/zh-CN/firefox/addon/simpread)
2222
* [支持 UserScript 的浏览器](https://greasyfork.org/zh-CN/scripts/39998) 如:Apple Safari · Microsoft Edge · Opera · Dolphin 详细 [请看这里](https://github.com/Kenshin/simpread-little)
2323
* [iOS( iPhone / iPad )版](https://xteko.com/redir?url=http://ojec5ddd5.bkt.clouddn.com/jsbox/simpread-1.0.0.box?201805251238&name=%E7%AE%80%E6%82%A6) 详细 [请看这里](https://github.com/Kenshin/simpread/wiki/JSBox)
@@ -30,7 +30,7 @@
3030
不改变当前页面的结构,仅仅高亮需要阅读的部分,不分散用户的注意力;适合 `临时阅读` 或者 `未适配阅读模式` 的网站
3131

3232
- [阅读模式](https://github.com/Kenshin/simpread/wiki/%E9%98%85%E8%AF%BB%E6%A8%A1%E5%BC%8F/)
33-
简悦 `原创` 功能,逐一适配了 [240+](https://github.com/kenshin/simpread/wiki/适配站点列表) 个网站,自动提取 `标题` `描述` `正文` `媒体资源( 图片/ 视频 )` 等,生成 `符合中文阅读` 的页面
33+
简悦 `原创` 功能,逐一适配了 [数百种类型](https://github.com/kenshin/simpread/wiki/适配站点列表) 的网站,自动提取 `标题` `描述` `正文` `媒体资源( 图片/ 视频 )` 等,生成 `符合中文阅读` 的页面
3434

3535
* 支持 `自动生成目录` [TXT 阅读器](https://github.com/Kenshin/simpread/wiki/txt-%E9%98%85%E8%AF%BB%E5%99%A8) [论坛类页面及分页](https://github.com/Kenshin/simpread/wiki/%E8%AE%BA%E5%9D%9B%E7%B1%BB%E9%A1%B5%E9%9D%A2%E5%8F%8A%E5%88%86%E9%A1%B5) 如:知乎 · 百度贴吧等
3636

@@ -42,6 +42,9 @@
4242
- 主动适配:
4343
通过简单的一个步骤,就可以让 `非适配页面` 支持阅读模式,详细请看 [主动适配](https://github.com/kenshin/simpread/wiki/主动适配阅读模式) 以及 [操作](http://ksria.com/simpread/welcome/version_1.0.5.html#mate-read-mode)
4444

45+
- 智能适配:
46+
自动识别出 Wordpress · Hexo · Ghost · Discuz 等博客 / 论坛的页面以及只要是结构良好的页面,(无需适配)自动生成阅读模式,详细请看 [智能适配](https://github.com/kenshin/simpread/wiki/智能适配模式)
47+
4548
- 站点适配源:
4649
包括:`官方(主)适配源` `官方(次)适配源以及第三方适配源` `本地适配源` 并支持导入第三方适配源,详细请看 [站点适配源](https://github.com/Kenshin/simpread/wiki/站点适配源)
4750

@@ -56,7 +59,7 @@
5659

5760
- 丰富的导出功能,包括:
5861

59-
- 导出 [Markdown](https://github.com/Kenshin/simpread#感谢) · `PNG` · `PDF` · [epub](https://github.com/Kenshin/simpread/wiki/发送到-epub)
62+
- 导出 [Markdown](https://github.com/Kenshin/simpread#感谢) · `HTML` · `PNG` · `PDF` · [epub](https://github.com/Kenshin/simpread/wiki/发送到-epub)
6063

6164
- 发送阅读模式优化后的页面到 `Kindle`,详细配置 [请看这里](https://github.com/Kenshin/simpread/wiki/发送到-Kindle)
6265

@@ -66,21 +69,22 @@
6669

6770
- 同步 · 上传/下载 配置 · 同步适配列表 · [快捷键支持](https://github.com/kenshin/simpread/wiki/快捷键) 等;
6871

69-
- 高级定制,包括:`右键菜单` `控制栏可隐藏` `阅读进度可隐藏` `自动进入阅读模式` [白名单](https://github.com/kenshin/simpread/wiki/faq#白名单) 以及 [黑名单(排除列表](https://github.com/kenshin/simpread/wiki/faq#排除列表)
72+
- 高级定制,包括:`右键菜单` `控制栏可隐藏` `阅读进度可隐藏` `自动进入阅读模式` [白名单](https://github.com/kenshin/simpread/wiki/faq#白名单) 以及 [排除列表](https://github.com/kenshin/simpread/wiki/faq#排除列表)
7073

7174
- 稍后读
7275

7376
#### 截图:
74-
![简单阅读,愉悦心情!](http://ojec5ddd5.bkt.clouddn.com/visual%20effect.jpg)
75-
![简悦 - 阅读模式](http://ojec5ddd5.bkt.clouddn.com/read%20mode.png)
77+
![简单阅读,愉悦心情!](http://ojec5ddd5.bkt.clouddn.com/welcome-readme-1.png)
78+
![多种导出方式](http://ojec5ddd5.bkt.clouddn.com/welcome-readme-3.png)
79+
![定制化,可编程](http://ojec5ddd5.bkt.clouddn.com/welcome-readme-4.png)
7680

7781
#### 照片集:
7882
> 包含了 `稍后读` `阅读模式 · 设置界面` `导出到生产力工具` `发送到 Kindle` `自定义样式` `同步配置` `论坛类页面 · 分页` 等功能的截图(动图)
7983
8084
* <http://ksria.com/simpread/gallery/>
8185

8286
#### 全部功能:
83-
![功能一览](http://ojec5ddd5.bkt.clouddn.com/feature%201.1.0.png)
87+
![功能一览](http://ojec5ddd5.bkt.clouddn.com/feature%201.1.1.png)
8488

8589
#### 如何使用(阅读模式):
8690

@@ -172,11 +176,11 @@ _如发现下图显示不全,请直接访问 http://ojec5ddd5.bkt.clouddn.com/
172176
<!-- Link -->
173177
[www-badge]: https://img.shields.io/badge/website-_simpread.ksria.com-1DBA90.svg
174178
[www-link]: http://ksria.com/simpread
175-
[version-badge]: https://img.shields.io/badge/lastest_version-1.1.0-blue.svg
179+
[version-badge]: https://img.shields.io/badge/lastest_version-1.1.1-blue.svg
176180
[version-link]: https://github.com/kenshin/simpread/releases
177181
[chrome-badge]: https://img.shields.io/badge/download-_chrome_webstore-brightgreen.svg
178182
[chrome-link]: https://chrome.google.com/webstore/detail/%E7%AE%80%E6%82%A6-simpread/ijllcpnolfcooahcekpamkbidhejabll
179183
[offline-badge]: https://img.shields.io/badge/download-_crx-brightgreen.svg
180-
[offline-link]: http://ksria.com/simpread/crx/1.1.0/simpread.crx
184+
[offline-link]: http://ksria.com/simpread/crx/1.1.1/simpread.crx
181185
[license-badge]: https://img.shields.io/github/license/mashape/apistatus.svg
182186
[license-link]: https://opensource.org/licenses/MIT

ext/background.js

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
console.log( "=== simpread background load ===" )
2+
3+
import local from 'local';
4+
import { storage } from 'storage';
5+
import * as msg from 'message';
6+
import {browser} from 'browser';
7+
import * as ver from 'version';
8+
import * as menu from 'menu';
9+
import * as watch from 'watch';
10+
11+
import PureRead from 'puread';
12+
13+
/**
14+
* Sevice: storage Get data form chrome storage
15+
*/
16+
storage.Read( () => {
17+
storage.puread = new PureRead( storage.sites );
18+
if ( local.Firstload() ) {
19+
local.Version( ver.version );
20+
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#firstload?ver=" + ver.version ) });
21+
}
22+
else {
23+
!local.Count() && storage.GetRemote( "remote", ( result, error ) => {
24+
if ( !error ) {
25+
storage.pr.Addsites( result );
26+
storage.Writesite( storage.pr.sites, getNewsitesHandler );
27+
}
28+
});
29+
ver.version != storage.version && storage.GetRemote( "local", ( result, error ) => {
30+
storage.pr.Addsites( result );
31+
storage.Writesite( storage.pr.sites, () => {
32+
ver.version != storage.version &&
33+
storage.Fix( storage.read.sites, storage.version, ver.version, storage.focus.sites );
34+
ver.version != storage.version && storage.Write( () => {
35+
local.Version( ver.version );
36+
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#update?ver=" + ver.version ) });
37+
}, ver.Verify( storage.version, storage.simpread ) );
38+
getNewsitesHandler( result );
39+
});
40+
});
41+
// only firefox and only usage 1.1.0.3024
42+
//if ( ver.version == storage.version && ver.sub_ver == "3024" && !localStorage["bg-3024"] ) {
43+
// browser.tabs.create({ url: browser.extension.getURL( "options/options.html#firstload?ver=" + ver.version ) });
44+
// localStorage["bg-3024"] = ver.sub_ver;
45+
//}
46+
}
47+
menu.CreateAll();
48+
});
49+
50+
/**
51+
* Get newsites handler
52+
* @param {object} count: update site cou
53+
*/
54+
function getNewsitesHandler( result ) {
55+
watch.Push( "site", true );
56+
}
57+
58+
/**
59+
* Listen menu event handler
60+
*/
61+
menu.OnClicked( ( info, tab ) => {
62+
console.log( "background contentmenu Listener", info, tab );
63+
if ( info.menuItemId == "link" ) {
64+
info.linkUrl && browser.tabs.create({ url: info.linkUrl + "?simpread_mode=read" });
65+
} else if ( info.menuItemId == "list" ) {
66+
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#later" ) });
67+
} else {
68+
if ( !tab.url.startsWith( "moz-extension://" ) ) browser.tabs.sendMessage( tab.id, msg.Add(info.menuItemId));
69+
}
70+
});
71+
72+
/**
73+
* Listen runtime message, include: `shortcuts` `browser_action`
74+
*/
75+
browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) {
76+
console.log( "background runtime Listener", request );
77+
switch ( request.type ) {
78+
case msg.MESSAGE_ACTION.shortcuts:
79+
getCurTab( { url: request.value.url }, tabs => {
80+
browser.tabs.sendMessage( tabs[0].id, msg.Add( msg.MESSAGE_ACTION.shortcuts ));
81+
});
82+
break;
83+
case msg.MESSAGE_ACTION.browser_action:
84+
getCurTab( { url: request.value.url }, tabs => {
85+
if ( tabs && tabs.length > 0 && tabs[0].url == request.value.url ) {
86+
setMenuAndIcon( tabs[0].id, request.value.code );
87+
} else console.error( request );
88+
});
89+
break;
90+
case msg.MESSAGE_ACTION.new_tab:
91+
browser.tabs.create({ url: request.value.url });
92+
break;
93+
case msg.MESSAGE_ACTION.menu:
94+
const { id, value } = request.value;
95+
// hack code refresh options menu changed, and not saved storage
96+
storage.option.menu[id] = value;
97+
value === true ? menu.Create( id ) : menu.Remove( id );
98+
break;
99+
case msg.MESSAGE_ACTION.updated:
100+
watch.Push( request.value.type, request.value.value );
101+
break;
102+
case msg.MESSAGE_ACTION.save_verify:
103+
sendResponse( watch.Lock( request.value.url ));
104+
break;
105+
case msg.MESSAGE_ACTION.auth:
106+
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#labs?auth=" + request.value.name.toLowerCase() ) });
107+
break;
108+
case msg.MESSAGE_ACTION.auth_success:
109+
getCurTab( { url: request.value.url }, tabs => {
110+
if ( tabs && tabs.length > 0 ) {
111+
browser.tabs.remove( tabs[0].id );
112+
getCurTab( { "active": true }, tabs => {
113+
tabs.forEach( tab => browser.tabs.sendMessage( tab.id, msg.Add( msg.MESSAGE_ACTION.export, {type: request.value.name.toLowerCase()} )) );
114+
});
115+
}
116+
});
117+
break;
118+
case msg.MESSAGE_ACTION.track:
119+
tracked( request.value );
120+
break;
121+
}
122+
});
123+
124+
/**
125+
* Listen chrome tab active message, include: `tab_selected`
126+
*/
127+
browser.tabs.onActivated.addListener( function( active ) {
128+
getCurTab( { "active": true, "currentWindow": true }, tabs => {
129+
if ( tabs && tabs.length > 0 && tabs[0].status == "complete" ) {
130+
console.log( "background tabs Listener:active", active );
131+
if ( tabs && tabs.length > 0 && !tabs[0].url.startsWith( "moz-extension://" ) ) {
132+
browser.tabs.sendMessage( tabs[0].id, msg.Add( msg.MESSAGE_ACTION.tab_selected, { is_update: false } ));
133+
} else {
134+
setMenuAndIcon( tabs[0].id, -1 );
135+
}
136+
} else console.error( "onActivated.addListener error" );
137+
});
138+
});
139+
140+
/**
141+
* Listen chrome tab update message, include: `tab_selected`
142+
*/
143+
browser.tabs.onUpdated.addListener( function( tabId, changeInfo, tab ) {
144+
watch.Pull( tabId );
145+
if ( changeInfo.status == "complete" ) {
146+
console.log( "background tabs Listener:update", tabId, changeInfo, tab );
147+
148+
if ( tab.url.startsWith( "http://ksria.com/simpread/auth.html" )) {
149+
const url = tab.url.replace( "http://ksria.com/simpread/auth.html?id=", "" ),
150+
id = url.includes( "#" ) || url.includes( "&" ) ? url.substr( 0, url.search( /\S(#|&)/ ) + 1 ) : url ;
151+
browser.tabs.query( {}, tabs => {
152+
const opts = tabs.find( tab => tab.url.includes( browser.extension.getURL( "options/options.html" ) ));
153+
if ( opts ) {
154+
browser.tabs.sendMessage( opts.id, msg.Add( msg.MESSAGE_ACTION.redirect_uri, { uri: tab.url, id } ));
155+
browser.tabs.remove( tabId );
156+
}
157+
});
158+
}
159+
160+
if ( !tab.url.startsWith( "moz-extension://" ) ) {
161+
browser.tabs.sendMessage( tabId, msg.Add( msg.MESSAGE_ACTION.tab_selected, { is_update: true } ));
162+
storage.ReadAsync( ( simpread, secret ) => {
163+
browser.tabs.sendMessage( tabId, msg.Add( msg.MESSAGE_ACTION.storage, { simpread, secret } ));
164+
});
165+
} else {
166+
setMenuAndIcon( tab.id, -1 );
167+
}
168+
}
169+
});
170+
171+
/**
172+
* Listen chrome tab remove message
173+
*/
174+
browser.tabs.onRemoved.addListener( tabId => watch.Pull( tabId ));
175+
176+
/**
177+
* Listen chrome page, include: `read`
178+
*/
179+
browser.pageAction.onClicked.addListener( function( tab ) {
180+
browser.tabs.sendMessage( tab.id, msg.Add( msg.MESSAGE_ACTION.browser_click ));
181+
});
182+
183+
/**
184+
* Get current tab object
185+
*
186+
* @param {object} query
187+
* @param {function} callback
188+
*/
189+
function getCurTab( query, callback ) {
190+
if ( query.url && query.url.includes( "#" ) ) {
191+
browser.tabs.query( {}, tabs => callback( tabs.filter( tab => tab.url == query.url && tab.active ) ) );
192+
} else browser.tabs.query( query, function( tabs ) { callback( tabs ); });
193+
}
194+
195+
/**
196+
* Set page action icon and context menu
197+
*
198+
* @param {int} tab.id
199+
* @param {int} -1: disable icon;
200+
*/
201+
function setMenuAndIcon( id, code ) {
202+
let icon = "";
203+
if ( code == -1 ) {
204+
menu.Update( "tempread" );
205+
browser.pageAction.setTitle({ tabId: id, title: "简悦 - 当前页面未适配阅读模式,点击进入临时阅读模式"});
206+
} else {
207+
icon = "-enable";
208+
storage.option.menu.read === true && menu.Create( "read" );
209+
menu.Update( "read" );
210+
browser.pageAction.setTitle({ tabId: id, title: "简悦 - 当前页面已适配阅读模式"});
211+
}
212+
browser.pageAction.show( id );
213+
browser.pageAction.setIcon({ tabId: id, path: browser.extension.getURL( `assets/images/icon16${icon}.png` ) });
214+
}
215+
216+
/**
217+
* Listen browser page action
218+
*/
219+
browser.browserAction.onClicked.addListener( () => browser.runtime.openOptionsPage() );
220+
221+
/**
222+
* Track
223+
*
224+
* @param {object} google analytics track object
225+
*/
226+
function tracked({ eventCategory, eventAction, eventLabel }) {
227+
console.log( "current track is", eventCategory, eventAction, eventLabel )
228+
ga( 'send', {
229+
hitType : 'event',
230+
eventCategory,
231+
eventAction,
232+
eventLabel
233+
});
234+
}
235+
236+
/**
237+
* Google analytics
238+
*/
239+
analytics();
240+
function analytics() {
241+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
242+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
243+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
244+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
245+
ga('create', 'UA-405976-12', 'auto');
246+
ga('send', 'pageview');
247+
}

0 commit comments

Comments
 (0)