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 (
+
+ );
+ 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 {
{(token)=>(
-
+
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 {
}
- {this.do_reply('',e);}}>
+
{this.show_reply_bar('',e);}}>
{this.set_variant(null,variant);}}
@@ -309,7 +309,7 @@ class FlowSidebar extends PureComponent {
}
{this.state.replies.map((reply)=>(
- {this.do_reply(reply.name,e);}}>
+
{this.show_reply_bar(reply.name,e);}}>
{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) : '');