Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions src/assets/css/simpread.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,13 @@ sr-rd-footer a:active {
color: #787878;
text-decoration: underline;
}
sr-rd-markdown{
width: 100%;
display: none;
}
sr-rd-markdown textarea{
font-size: 16px;
min-width: 800px;
height: 650px;
border: 1px solid #ccc;
}
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
44 changes: 40 additions & 4 deletions src/read/read.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
console.log( "=== simpread read load ===" )

import toMarkdown from 'to-markdown';
import pangu from 'pangu';
import ProgressBar from 'schedule';
import ReadCtlbar from 'readctlbar';
Expand Down Expand Up @@ -36,11 +36,23 @@ const Footer = () => {
)
}

class Read extends React.Component {

class Read extends React.Component {
constructor(props) {
super(props);
this.state = {isShowMarkdown: false};
}
componentWillMount() {
$( "body" ).addClass( "simpread-hidden" );
th.Change( this.props.read.theme );
let {include} = this.props.wrapper;
try{
//转换为markdown
this.props.markdown = toMarkdown(include, { gfm: true });
}catch(e){
this.props.markdown = false;
}

}

async componentDidMount() {
Expand Down Expand Up @@ -69,7 +81,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 +118,25 @@ class Read extends React.Component {
storage.current[type]=value;
storage.Setcur( storage.current.mode );
break;
case "markdown":
if(this.props.markdown){
if(!this.state.isShowMarkdown){
this.setState({
isShowMarkdown: true
})
$('sr-rd-content,sr-rd-footer').hide();
$('sr-rd-markdown textarea').val(this.props.markdown).show();
}else{
this.setState({
isShowMarkdown: false
})
$('sr-rd-content,sr-rd-footer').show();
$('sr-rd-markdown textarea').hide();
}
}else{
new Notify().Render( 1, '转换markdown失败!' );
}
break;
}
}

Expand All @@ -116,6 +148,7 @@ class Read extends React.Component {
ReactDOM.unmountComponentAtNode( getReadRoot() );
}
}).addClass( "simpread-read-root-hide" );

}

render() {
Expand All @@ -125,6 +158,9 @@ class Read extends React.Component {
<sr-rd-title>{ this.props.wrapper.title }</sr-rd-title>
<sr-rd-desc>{ this.props.wrapper.desc }</sr-rd-desc>
<sr-rd-content dangerouslySetInnerHTML={{__html: this.props.wrapper.include }} ></sr-rd-content>
<sr-rd-markdown>
<textarea class="sr-rd-markdown"></textarea>
</sr-rd-markdown>
<Footer />
<ReadCtlbar site={{ title: this.props.wrapper.title, url: window.location.href }} onAction={ (t,v)=>this.onAction( t,v ) } />
</sr-read>
Expand Down Expand Up @@ -359,4 +395,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 @@ -66,6 +66,11 @@ const readItems = {
"name" : "关闭",
"icon" : ss.IconPath("exit_icon"),
},
"markdown" : {
"name" : "markdown",
"icon" : ss.IconPath("markdown_icon"),
"color": "#D4237A",
},
"setting" : {
"name" : "设定",
"icon" : ss.IconPath("setting_icon"),
Expand Down Expand Up @@ -372,4 +377,4 @@ export {
menuItem,

actionItems,
}
}
Loading