diff --git a/src/App.js b/src/App.js index 330fc9a..7bc072e 100644 --- a/src/App.js +++ b/src/App.js @@ -5,10 +5,23 @@ import {Sidebar} from './Sidebar'; import {PressureHelper} from './PressureHelper'; import {TokenCtx} from './UserAction'; -function TokenDeprecatedAlert(props) { - if(!props.token || !props.token.startsWith('isop_')) // noinspection JSConstructorReturnsPrimitive - return null; - else +function DeprecatedAlert(props) { + if(['pkuhelper.com','www.pkuhelper.com','webhole.xmcp.ml','127.0.0.1','localhost'].indexOf(document.domain)===-1) + return ( +
+
+

官宣了!

+
+

请访问官方树洞网页版

+

http://pkuhelper.com/hole

+

加载三倍速,访问不卡顿

+
+

当前域名将停止维护。

+

@xmcp

+
+
+ ); + if(props.token && props.token.startsWith('isop_')) return (
@@ -18,6 +31,7 @@ function TokenDeprecatedAlert(props) {
); + return null; } class App extends Component { @@ -79,7 +93,7 @@ class App extends Component { <TokenCtx.Consumer>{(token)=>( <div className="left-container"> - <TokenDeprecatedAlert token={token.value} /> + <DeprecatedAlert token={token.value} /> <Flow key={this.state.flow_render_key} show_sidebar={this.show_sidebar_bound} mode={this.state.mode} search_text={this.state.search_text} token={token.value} /> diff --git a/src/Common.js b/src/Common.js index 68c959f..303455c 100644 --- a/src/Common.js +++ b/src/Common.js @@ -1,4 +1,5 @@ import React, {Component, PureComponent} from 'react'; +import {PKUHELPER_ROOT} from './flows_api'; import TimeAgo from 'react-timeago'; import Linkify from 'react-linkify'; @@ -9,7 +10,7 @@ import './Common.css'; const chinese_format=buildFormatter(chineseStrings); -export const API_BASE=window.location.protocol==='https:' ? '/api_proxy' : 'http://www.pkuhelper.com:10301/services/pkuhole'; +export const API_BASE=PKUHELPER_ROOT+'services/pkuhole'; const PID_RE=/(^|[^\d])([1-9]\d{4,5})(?!\d)/g; const NICKNAME_RE=/(^|[^A-Za-z])((?:(?:Angry|Baby|Crazy|Diligent|Excited|Fat|Greedy|Hungry|Interesting|Japanese|Kind|Little|Magic|Naïve|Old|Powerful|Quiet|Rich|Superman|THU|Undefined|Valuable|Wifeless|Xiangbuchulai|Young|Zombie)\s)?(?:Alice|Bob|Carol|Dave|Eve|Francis|Grace|Hans|Isabella|Jason|Kate|Louis|Margaret|Nathan|Olivia|Paul|Queen|Richard|Susan|Thomas|Uma|Vivian|Winnie|Xander|Yasmine|Zach)|You Win(?: \d+)?|洞主)(?![A-Za-z])/gi; @@ -92,12 +93,10 @@ export class SafeTextarea extends Component { text: '', }); } - set_and_focus(text) { + set(text) { this.change_callback(text); this.setState({ text: text, - },()=>{ - this.area_ref.current.focus(); }); } get() { diff --git a/src/Flows.js b/src/Flows.js index 7bbd471..959d519 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -7,10 +7,10 @@ import LazyLoad from 'react-lazyload'; import {AudioWidget} from './AudioWidget'; import {TokenCtx, ReplyForm} from './UserAction'; -import {API} from './flows_api'; +import {API, PKUHELPER_ROOT} from './flows_api'; -const IMAGE_BASE='http://www.pkuhelper.com:10301/services/pkuhole/images/'; -const AUDIO_BASE='http://www.pkuhelper.com:10301/services/pkuhole/audios/'; +const IMAGE_BASE=PKUHELPER_ROOT+'services/pkuhole/images/'; +const AUDIO_BASE=PKUHELPER_ROOT+'services/pkuhole/audios/'; const SEARCH_PAGESIZE=50; const CLICKABLE_TAGS={a: true, audio: true}; @@ -253,11 +253,11 @@ class FlowSidebar extends PureComponent { } } - do_reply(name,event) { + show_reply_bar(name,event) { if(event.target.tagName.toLowerCase()!=='a') { let text=this.reply_ref.current.get(); if(/^\s*(Re (洞主|\b[A-Z][a-z]+){0,2}:)?\s*$/.test(text)) // text is nearly empty so we can replace it - this.reply_ref.current.set_and_focus('Re '+name+': '); + this.reply_ref.current.set('Re '+name+': '); } } @@ -296,7 +296,7 @@ class FlowSidebar extends PureComponent { </span> } </div> - <div onClick={(e)=>{this.do_reply('',e);}}> + <div onClick={(e)=>{this.show_reply_bar('',e);}}> <FlowItem info={this.state.info} attention={this.state.attention} img_clickable={true} color_picker={this.color_picker} show_pid={this.show_pid} replies={this.state.replies} set_variant={(variant)=>{this.set_variant(null,variant);}} @@ -309,7 +309,7 @@ class FlowSidebar extends PureComponent { } {this.state.replies.map((reply)=>( <LazyLoad key={reply.cid} offset={1500} height="5em" overflow={true} once={true}> - <div onClick={(e)=>{this.do_reply(reply.name,e);}}> + <div onClick={(e)=>{this.show_reply_bar(reply.name,e);}}> <Reply info={reply} color_picker={this.color_picker} show_pid={this.show_pid} set_variant={(variant)=>{this.set_variant(reply.cid,variant);}} diff --git a/src/UserAction.js b/src/UserAction.js index 893bd4b..f393e1f 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -1,12 +1,12 @@ import React, {Component, PureComponent} from 'react'; import {SafeTextarea} from './Common'; -import {API_VERSION_PARAM,API} from './flows_api' +import {API_VERSION_PARAM,PKUHELPER_ROOT,API} from './flows_api' import md5 from 'md5'; import './UserAction.css'; import {API_BASE} from './Common'; -const LOGIN_BASE=window.location.protocol==='https:' ? '/login_proxy' : 'http://www.pkuhelper.com:10301/services/login'; +const LOGIN_BASE=PKUHELPER_ROOT+'services/login'; const MAX_IMG_PX=2000; const MAX_IMG_FILESIZE=256000; diff --git a/src/flows_api.js b/src/flows_api.js index 2db8bee..6f2c598 100644 --- a/src/flows_api.js +++ b/src/flows_api.js @@ -1,6 +1,8 @@ import {API_BASE} from './Common'; export const API_VERSION_PARAM='&PKUHelperAPI=3.0'; +export const PKUHELPER_ROOT= // don't use :10301 if we are already in the same domain + (document.domain==='pkuhelper.com'||document.domain==='www.pkuhelper.com') ? '/' : 'http://pkuhelper.com:10301/'; function token_param(token) { return API_VERSION_PARAM + (token ? ('&user_token='+token) : '');