mirror of
https://github.com/Kenshin/simpread.git
synced 2026-01-25 14:28:34 +00:00
Add submit temp site logic.
This commit is contained in:
parent
563df10981
commit
02ea5a48db
@ -112,6 +112,9 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse )
|
||||
case msg.MESSAGE_ACTION.save_site:
|
||||
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#sites?pending=" + encodeURI( JSON.stringify( request.value ))) });
|
||||
break;
|
||||
case msg.MESSAGE_ACTION.temp_site:
|
||||
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#sites?temp=" + encodeURI( JSON.stringify( request.value ))) });
|
||||
break;
|
||||
case msg.MESSAGE_ACTION.auth_success:
|
||||
getCurTab( { url: request.value.url }, tabs => {
|
||||
if ( tabs && tabs.length > 0 ) {
|
||||
|
||||
@ -2,6 +2,8 @@ console.log( "=== simpread option siteeditor ===" )
|
||||
|
||||
import { storage } from 'storage';
|
||||
import * as watch from 'watch';
|
||||
import {browser} from 'browser';
|
||||
import * as msg from 'message';
|
||||
|
||||
import Editor from 'editor';
|
||||
|
||||
@ -86,6 +88,12 @@ class SiteEditor extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
submit() {
|
||||
const news = { ...site };
|
||||
delete news.html;
|
||||
browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.temp_site, { url: location.href, site: news, uid: storage.user.uid, type: "temp" }));
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
waves.Render({ root: rootjq });
|
||||
tooltip.Render( rootjq );
|
||||
@ -93,6 +101,9 @@ class SiteEditor extends React.Component {
|
||||
|
||||
render() {
|
||||
site = { ...storage.pr.current.site };
|
||||
if ( storage.pr.state == "temp" ) {
|
||||
storage.pr.dom && ( site.include = storage.pr.dom.outerHTML.replace( storage.pr.dom.innerHTML, "" ).replace( /<\/\S+>$/i, "" ));
|
||||
}
|
||||
return (
|
||||
<dia.Dialog>
|
||||
<dia.Content>
|
||||
@ -100,7 +111,9 @@ class SiteEditor extends React.Component {
|
||||
</dia.Content>
|
||||
<dia.Footer>
|
||||
<Button text="删 除" waves="md-waves-effect" color="#fff" backgroundColor="#F44336" onClick={ ()=>this.action( "delete" ) } />
|
||||
<div style={{ width: "100%" }}></div>
|
||||
{ storage.pr.state == "temp" ?
|
||||
<Button text="提交临时阅读模式" waves="md-waves-effect" color="#fff" backgroundColor="#4CAF50" width="100%" onClick={ ()=>this.submit() } /> :
|
||||
<div style={{ width: "100%" }}></div> }
|
||||
<Button text="退 出" mode="secondary" waves="md-waves-effect" onClick={ ()=>this.close() } />
|
||||
<Button text="保 存" waves="md-waves-effect" onClick={ ()=>this.action( "save" ) } />
|
||||
</dia.Footer>
|
||||
|
||||
@ -280,10 +280,26 @@ export default class SitesOpts extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
temp() {
|
||||
const url = decodeURIComponent( location.hash ).replace( "#sites?temp=", "" ),
|
||||
data = JSON.parse( url );
|
||||
$.ajax({
|
||||
url : storage.service + "/sites/service/pending",
|
||||
method: "POST",
|
||||
data,
|
||||
}).done( ( result, textStatus, jqXHR ) => {
|
||||
new Notify().Render( "提交成功,谢谢对简悦作出的贡献,2 秒后页面将会关闭!" );
|
||||
setTimeout( ()=>location.href = location.protocol + location.pathname + "#sites?update=complete", 2000 );
|
||||
}).fail( error => {
|
||||
new Notify().Render( 2, "自动更新出现错误,请稍后再试!" );
|
||||
});
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
decodeURIComponent( location.href ).includes( "#sites?install=" ) && this.install();
|
||||
decodeURIComponent( location.href ).includes( "#sites?update=" ) && this.update();
|
||||
decodeURIComponent( location.href ).includes( "#sites?pending=" ) && this.pending();
|
||||
decodeURIComponent( location.href ).includes( "#sites?temp=" ) && this.temp();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -26,6 +26,7 @@ const action = {
|
||||
update_site : "update_site",
|
||||
pending_site : "pending_site",
|
||||
save_site : "save_site",
|
||||
temp_site : "temp_site",
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user