Skip to content

Commit

Permalink
Merge pull requests #16 and add download markdown and enhanch url.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenshin committed Jun 16, 2017
1 parent d9a4f73 commit b6edd95
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 14 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"css-loader": "^0.26.1",
"expose-loader": "^0.7.1",
"file-loader": "^0.9.0",
"minimatch": "^3.0.4",
"postcss-cssnext": "^2.10.0",
"postcss-loader": "^1.3.3",
"react": "^0.14.8",
"react-dom": "^0.14.8",
"style-loader": "^0.13.1",
"to-markdown": "^3.0.4",
"url-loader": "^0.5.7",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
Expand Down
Binary file added src/assets/images/markdown_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions src/contentscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse )
console.log( "contentscripts runtime Listener", request );
switch ( request.type ) {
case msg.MESSAGE_ACTION.focus_mode:
focuseMode();
focusMode();
break;
case msg.MESSAGE_ACTION.read_mode:
readMode();
Expand All @@ -49,14 +49,14 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse )
* Keyboard event handler
*/
function bindShortcuts() {
Mousetrap.bind( [ storage.focus.shortcuts.toLowerCase() ], focuseMode );
Mousetrap.bind( [ storage.focus.shortcuts.toLowerCase() ], focusMode );
Mousetrap.bind( [ storage.read.shortcuts.toLowerCase() ], readMode );
}

/**
* Focus mode
*/
function focuseMode() {
function focusMode() {
console.log( "=== simpread focus mode active ===" )

if ( !entry( focus, read, "阅读", "聚焦" )) return;
Expand All @@ -79,7 +79,6 @@ function readMode() {

if ( !entry( read, focus, "聚焦", "阅读" )) return;
getCurrent( mode.read );

switch ( st.Verify( storage.current.site.name ) ) {
case 0:
storage.Statistics( mode.read );
Expand Down Expand Up @@ -142,6 +141,8 @@ function entry( current, other, ...str ) {
* @param {boolean} when true, push message
*/
function getCurrent( mode = undefined, upicon = true ) {
if ( mode && storage.VerifyCur( mode ) ) storage.Getcur( mode );
if ( mode && storage.VerifyCur( mode ) ) {
storage.Getcur( mode );
}
if ( upicon ) browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.browser_action, { code: storage.rdstcode, url: window.location.href } ));
}
}
2 changes: 1 addition & 1 deletion src/module/common/exclude.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Exclude extends React.Component {
rows={ this.props.rows }
placeholder="默认为空,每行一个,支持: Html标签, {}, '', //, [] 等,详细请看站点编辑器。"
floatingtext="隐藏列表"
value={ this.props.exclude.join( "\n" ) }
value={ (this.props.exclude||[]).join( "\n" ) }
errortext={ this.state.error }
onChange={ ()=>this.changeExclude() }
/>
Expand Down
2 changes: 1 addition & 1 deletion src/read/controlbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class ReadCtlbar extends React.Component {
}
browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.new_tab, { url }));
break;
case [ "exit", "setting", "save" ].includes( type ):
case [ "exit", "setting", "save", "markdown" ].includes( type ):
this.props.onAction && this.props.onAction( type );
break;
case [ "up", "down" ].includes( type ):
Expand Down
20 changes: 18 additions & 2 deletions src/read/read.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
console.log( "=== simpread read load ===" )

import toMarkdown from 'to-markdown';
import pangu from 'pangu';

import ProgressBar from 'schedule';
import ReadCtlbar from 'readctlbar';
import * as modals from 'modals';
Expand Down Expand Up @@ -69,7 +71,8 @@ class Read extends React.Component {
}

componentWillUnmount() {
$root.removeClass( theme );
$root.removeClass( theme )
.removeClass( "simpread-font" );
$( "body" ).removeClass( "simpread-hidden" );
$( rdclsjq ).remove();
tooltip.Exit( rdclsjq );
Expand Down Expand Up @@ -105,6 +108,19 @@ class Read extends React.Component {
storage.current[type]=value;
storage.Setcur( storage.current.mode );
break;
case "markdown":
new Notify().Render( "请注意,这是一个实验性功能,不一定能导出成功。" );
const { include } = this.props.wrapper;
try {
const md = toMarkdown( include, { gfm: true }),
data = "data:text/plain;charset=utf-8," + encodeURIComponent( md ),
$a = $( `<a style="display:none" href=${data} download="simpread-${ this.props.wrapper.title.trim() }.md"></a>` ).appendTo( "body" );
$a[0].click();
$a.remove();
} catch( e ) {
new Notify().Render( 1, "转换 Markdown 格式失败!" );
}
break;
}
}

Expand Down Expand Up @@ -359,4 +375,4 @@ async function commbeautify( $target ) {
$target.find( "a" ).removeAttr( "style" );
}

export { Render, Exist };
export { Render, Exist };
7 changes: 6 additions & 1 deletion src/service/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const readItems = {
"icon" : ss.IconPath("save_icon"),
"color": "#FF5722",
},
"markdown" : {
"name" : "导出为 MD",
"icon" : ss.IconPath("markdown_icon"),
"color": "#D4237A",
},
/*"download" : {
"name" : "导出",
"icon" : ss.IconPath("download_icon"),
Expand Down Expand Up @@ -372,4 +377,4 @@ export {
menuItem,

actionItems,
}
}
8 changes: 6 additions & 2 deletions src/service/site.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
console.log( "=== simpread site load ===" )

import minimatch from 'minimatch';

/**
* Get URI
*
Expand Down Expand Up @@ -47,13 +49,15 @@ function findSitebyURL( sites, url ) {
} else if ( !isroot() && !cur.endsWith( "*" ) && cur.replace( /^http[s]?:/, "" ) == url.replace( /^http[s]?:/, "" ) ) {
found = cur;
break;
}
else if ( !isroot() && cur.endsWith( "*" ) && uri.includes( sufname ) && hostname == sufname && url.includes( name ) ) {
} else if ( !isroot() && cur.endsWith( "*" ) && uri.includes( sufname ) && hostname == sufname && url.includes( name ) ) {
//if ( /\/[a-zA-Z0-9]+\/\*/g.test( cur )) {
// if ( suffix != url ) return undefined;
//} else if ( suffix == url ) return undefined;
found = cur;
break;
} else if ( minimatch( window.location.origin + window.location.pathname, cur ) ) {
found = cur;
break;
}
}
if ( found ) {
Expand Down
19 changes: 19 additions & 0 deletions src/website_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -1417,5 +1417,24 @@
"exclude" : [
"<i class='pstatus'>"
]
},{
"name" : "issue.github.com",
"url" : "https://github.com/*/*/issues/*",
"title" : "[[{$('h1.gh-header-title .js-issue-title').text()}]]",
"desc" : "",
"include" : "[[{$('#discussion_bucket table td.js-comment-body').html()}]]",
"exclude" : [
""
]
},{
"name" : "readme.github.com",
"override": true,
"url" : "https://github.com/**/*/README.md",
"title" : "[[{$('title').text()}]]",
"desc" : "",
"include" : "<article class='markdown-body'>",
"exclude" : [
"<a class='anchor'>"
]
}]
}
9 changes: 8 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ const webpack = require( 'webpack' ),
'./node_modules/react/dist/react.min.js',
'./node_modules/react-dom/dist/react-dom.min.js',

//minimatch
'./node_modules/minimatch/minimatch.js',
//to markdown
'./node_modules/to-markdown/dist/to-markdown.js',

// vendors
'pangu',
'mousetrap',
Expand Down Expand Up @@ -187,6 +192,8 @@ const webpack = require( 'webpack' ),

resolve: {
alias : {
minimatch : __dirname + '/node_modules/minimatch/minimatch.js',
'to-markdown' : __dirname + '/node_modules/to-markdown/dist/to-markdown.js',
jquery : __dirname + '/src/vender/jquery-2.1.1.min.js',
mousetrap : __dirname + '/src/vender/mousetrap.min.js',
pangu : __dirname + '/src/vender/pangu.min.js',
Expand Down Expand Up @@ -246,4 +253,4 @@ const webpack = require( 'webpack' ),

};

module.exports = config;
module.exports = config;

0 comments on commit b6edd95

Please sign in to comment.