diff --git a/src/contentscripts.js b/src/contentscripts.js
index 26fad2b3..c96d2e03 100644
--- a/src/contentscripts.js
+++ b/src/contentscripts.js
@@ -18,6 +18,9 @@ import * as msg from 'message';
import {browser} from 'browser';
import * as watch from 'watch';
+import PureRead from 'pureread';
+
+let pr; // pure read object
let current_url = location.href; // current page url ( when changed page changed )
/**
@@ -26,6 +29,7 @@ let current_url = location.href; // current page url ( when changed page changed
storage.Read( () => {
bindShortcuts();
autoOpen();
+ pRead();
});
/**
@@ -127,9 +131,10 @@ function readMode() {
break;
case -1:
new Notify().Render( "当前并未适配阅读模式,请移动鼠标手动生成 临时阅读模式。" );
- read.Highlight().done( () => {
+ read.Highlight().done( dom => {
+ pr.TempMode( dom );
storage.Statistics( mode.read );
- read.Render();
+ read.Render( pr );
});
break;
}
@@ -207,4 +212,13 @@ function browserAction( is_update ) {
autoOpen();
}
browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.browser_action, { code: storage.current.site.name == "" ? -1 : 0 , url: window.location.href } ));
+}
+
+/**
+ * Pure Read
+*/
+function pRead() {
+ pr = new PureRead( window.location.href, storage.sites );
+ pr.Getsites();
+ console.log( "current pureread object is ", pr )
}
\ No newline at end of file
diff --git a/src/read/read.jsx b/src/read/read.jsx
index 3a0b500b..fdaac5c1 100644
--- a/src/read/read.jsx
+++ b/src/read/read.jsx
@@ -169,7 +169,8 @@ class Read extends React.Component {
* Render entry
*
*/
-function Render() {
+function Render( pr ) {
+ console.log( "current pureread object is ", pr )
ReactDOM.render(
",
+ auto : false,
+ exclude: [],
+ };
+ if ( type == "remote" ) {
+ meta.include = "";
+ meta.html = $( "body pre" ).html().replace( /\n/ig, "
" );
+ }
+ !$( "title" ).html() && $( "head" ).append( `${ decodeURI(title.replace( ".txt", "" )) } ` );
+ return meta;
+}
+
+/**
+ * Safe site, add all site props
+ *
+ * @param {object} modify site
+ * @param {string} target include: global custom local
+ * @param {string} url
+ * @returns {object} site
+ */
+function safesite( site, target, url ) {
+ site.url = url;
+ site.target = target;
+ site.name == "" && ( site.name = "tempread::" );
+ ( !site.avatar || site.avatar.length == 0 ) && ( site.avatar = [{ name: "" }, { url: "" }]);
+ ( !site.paging || site.paging.length == 0 ) && ( site.paging = [{ prev: "" }, { next: "" }]);
+ return site;
+}
+
+/**
+ * Find site by url from sites
+ *
+ * @param {string} type, include: global, local, custom
+ * @param {map} sites
+ * @param {string} url
+ * @param {array} matching sites
+ *
+ * @return {array} 0: current site; 1: current url, 2: type
+ */
+function getsite( type, sites, url, matching = [] ) {
+ const domain = (names)=>{
+ const arr = names.replace( "www.", "" ).match( /\.\S+\.\S+/g );
+ if ( arr ) {
+ return arr[0].substr(1);
+ } else {
+ return names.replace( "www.", "" );
+ }
+ },
+ urls = [ ...sites.keys() ],
+ arr = url.match( /[.a-zA-z0-9-_]+/g ),
+ uri = arr[1].replace( "www.", "" ),
+ hostname = domain( window.location.hostname ),
+ isroot = ()=>window.location.pathname == "/" || /\/(default|index|portal).[0-9a-zA-Z]+$/.test(window.location.pathname);
+ for ( const cur of urls ) {
+ const name = sites.get(cur).name,
+ sufname= domain( name );
+ if ( !isroot() && !cur.endsWith( "*" ) && cur.replace( /^http[s]?:/, "" ) == url.replace( /^http[s]?:/, "" ) ) {
+ matching.push( [ cur, clone( sites.get( cur )), type ] );
+ } else if ( cur.match( /\*/g ) && cur.match( /\*/g ).length == 1 && !isroot() && cur.endsWith( "*" ) && uri.includes( sufname ) && hostname == sufname && url.includes( name ) ) {
+ // e.g. https://www.douban.com/* http://mp.weixin.qq.com/*
+ matching.push( [ cur, clone( sites.get( cur )), type ] );
+ } else if ( minimatch( window.location.origin + window.location.pathname, cur ) ) {
+ matching.push( [ cur, clone( sites.get( cur )), type ] );
+ }
+ }
+}
diff --git a/webpack.config.js b/webpack.config.js
index 5d2f6fd8..5179fe76 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -294,6 +294,8 @@ const webpack = require( 'webpack' ),
tooltip : __dirname + '/src/vender/mduikit/tooltip.jsx',
waves : __dirname + '/src/vender/mduikit/waves.js',
+ pureread : __dirname + '/src/service/pureread.js',
+
}
}