add balance shower and remove quote,color_picker config
This commit is contained in:
19
src/BalanceShower.css
Normal file
19
src/BalanceShower.css
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
.balance-popover {
|
||||||
|
position: absolute;
|
||||||
|
top: 2em;
|
||||||
|
margin: auto;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.balance-value {
|
||||||
|
opacity: 0;
|
||||||
|
animation: balance-disappear 2s ease-in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes balance-disappear {
|
||||||
|
from {opacity: 1;}
|
||||||
|
75% {opacity: 1;}
|
||||||
|
to {opacity: 0;}
|
||||||
|
}
|
||||||
81
src/BalanceShower.js
Normal file
81
src/BalanceShower.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import React, {Component, PureComponent} from 'react';
|
||||||
|
import {PKUHELPER_ROOT} from './infrastructure/const';
|
||||||
|
import {API_VERSION_PARAM, get_json} from './flows_api';
|
||||||
|
import {TokenCtx} from './UserAction';
|
||||||
|
|
||||||
|
import './BalanceShower.css';
|
||||||
|
|
||||||
|
export class BalanceShower extends PureComponent {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state={
|
||||||
|
loading_status: 'idle',
|
||||||
|
error: null,
|
||||||
|
balance: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
do_load(token) {
|
||||||
|
if(this.state.loading_status==='loading')
|
||||||
|
return;
|
||||||
|
if(!token || !window.config.easter_egg) {
|
||||||
|
this.setState({
|
||||||
|
loading_status: 'idle',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loading_status: 'loading',
|
||||||
|
},()=>{
|
||||||
|
fetch(
|
||||||
|
PKUHELPER_ROOT+'api_xmcp/isop/card_balance'
|
||||||
|
+'?user_token='+encodeURIComponent(token)
|
||||||
|
+API_VERSION_PARAM()
|
||||||
|
)
|
||||||
|
.then(get_json)
|
||||||
|
.then((json)=>{
|
||||||
|
console.log(json);
|
||||||
|
if(!json.success)
|
||||||
|
throw new Error(JSON.stringify(json));
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loading_status: 'done',
|
||||||
|
error: null,
|
||||||
|
balance: json.balance,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((e)=>{
|
||||||
|
console.error(e);
|
||||||
|
this.setState({
|
||||||
|
loading_status: 'error',
|
||||||
|
error: ''+e,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render_popover() {
|
||||||
|
if(this.state.loading_status==='idle') // no token or disabled
|
||||||
|
return null;
|
||||||
|
else if(this.state.loading_status==='loading')
|
||||||
|
return (<div className="box box-tip">……</div>);
|
||||||
|
else if(this.state.loading_status==='error')
|
||||||
|
return (<div className="box box-tip balance-value"><a onClick={()=>{alert(this.state.error)}}>无法查询余额</a></div>);
|
||||||
|
else if(this.state.loading_status==='done')
|
||||||
|
return (<div className="box box-tip balance-value">校园卡 ¥{this.state.balance}</div>);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<TokenCtx.Consumer>{(token)=>(
|
||||||
|
<div onClick={()=>this.do_load(token.value)}>
|
||||||
|
<div className="balance-popover">{this.render_popover()}</div>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
)}</TokenCtx.Consumer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,9 +14,7 @@ const DEFAULT_CONFIG={
|
|||||||
background_img: 'static/bg/gbp.jpg',
|
background_img: 'static/bg/gbp.jpg',
|
||||||
background_color: '#113366',
|
background_color: '#113366',
|
||||||
pressure: false,
|
pressure: false,
|
||||||
quote: true,
|
|
||||||
horizontal_scroll: true,
|
horizontal_scroll: true,
|
||||||
color_picker: true,
|
|
||||||
easter_egg: true,
|
easter_egg: true,
|
||||||
comment_cache: false,
|
comment_cache: false,
|
||||||
color_scheme: 'default',
|
color_scheme: 'default',
|
||||||
@@ -235,20 +233,12 @@ export class ConfigUI extends PureComponent {
|
|||||||
<hr />
|
<hr />
|
||||||
<ConfigSwitch callback={this.save_changes_bound} id="pressure" name="快速返回"
|
<ConfigSwitch callback={this.save_changes_bound} id="pressure" name="快速返回"
|
||||||
description="短暂按住 Esc 键或重压屏幕(3D Touch)可以快速返回或者刷新树洞"
|
description="短暂按住 Esc 键或重压屏幕(3D Touch)可以快速返回或者刷新树洞"
|
||||||
/>
|
/>y
|
||||||
<hr />
|
|
||||||
<ConfigSwitch callback={this.save_changes_bound} id="quote" name="自动显示引文"
|
|
||||||
description="当树洞正文提到另一个树洞的编号时,在下方自动显示引文"
|
|
||||||
/>
|
|
||||||
<hr />
|
<hr />
|
||||||
<ConfigSwitch callback={this.save_changes_bound} id="horizontal_scroll" name="横向滚动"
|
<ConfigSwitch callback={this.save_changes_bound} id="horizontal_scroll" name="横向滚动"
|
||||||
description="在树洞列表里横向滚动浏览回复,如果经常误触可以把它关掉"
|
description="在树洞列表里横向滚动浏览回复,如果经常误触可以把它关掉"
|
||||||
/>
|
/>
|
||||||
<hr />
|
<hr />
|
||||||
<ConfigSwitch callback={this.save_changes_bound} id="color_picker" name="回复颜色标记"
|
|
||||||
description="为不同人的回复分配不同颜色"
|
|
||||||
/>
|
|
||||||
<hr />
|
|
||||||
<ConfigSwitch callback={this.save_changes_bound} id="comment_cache" name="评论缓存"
|
<ConfigSwitch callback={this.save_changes_bound} id="comment_cache" name="评论缓存"
|
||||||
description="缓存已读树洞的评论(加载更快,但可能有bug)"
|
description="缓存已读树洞的评论(加载更快,但可能有bug)"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ class FlowItemRow extends PureComponent {
|
|||||||
let parts=split_text(this.state.info.text,hl_rules);
|
let parts=split_text(this.state.info.text,hl_rules);
|
||||||
|
|
||||||
let quote_id=null;
|
let quote_id=null;
|
||||||
if(!this.props.is_quote && window.config.quote)
|
if(!this.props.is_quote)
|
||||||
for(let [mode,content] of parts)
|
for(let [mode,content] of parts)
|
||||||
if(mode==='pid' && QUOTE_BLACKLIST.indexOf(content)===-1 && parseInt(content)<parseInt(this.state.info.pid))
|
if(mode==='pid' && QUOTE_BLACKLIST.indexOf(content)===-1 && parseInt(content)<parseInt(this.state.info.pid))
|
||||||
if(quote_id===null)
|
if(quote_id===null)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {PromotionBar} from './Common';
|
|||||||
import {ConfigUI} from './Config';
|
import {ConfigUI} from './Config';
|
||||||
|
|
||||||
import './Title.css';
|
import './Title.css';
|
||||||
|
import {BalanceShower} from './BalanceShower';
|
||||||
|
|
||||||
const flag_re=/^\/\/setflag ([a-zA-Z0-9_]+)=(.*)$/;
|
const flag_re=/^\/\/setflag ([a-zA-Z0-9_]+)=(.*)$/;
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ const HELP_TEXT=(
|
|||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
},200);
|
},200);
|
||||||
}}>强制检查更新</a>
|
}}>强制检查更新</a>
|
||||||
([{process.env.REACT_APP_BUILD_INFO||'---'}] {process.env.NODE_ENV})
|
({process.env.REACT_APP_BUILD_INFO||'---'} {process.env.NODE_ENV})
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -186,11 +187,13 @@ export function Title(props) {
|
|||||||
<div className="title-bar">
|
<div className="title-bar">
|
||||||
<AppSwitcher appid="hole" />
|
<AppSwitcher appid="hole" />
|
||||||
<div className="aux-margin">
|
<div className="aux-margin">
|
||||||
|
<BalanceShower>
|
||||||
<div className="title">
|
<div className="title">
|
||||||
<p className="centered-line">
|
<p className="centered-line">
|
||||||
P大树洞
|
P大树洞
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
</BalanceShower>
|
||||||
<ControlBar show_sidebar={props.show_sidebar} set_mode={props.set_mode} />
|
<ControlBar show_sidebar={props.show_sidebar} set_mode={props.set_mode} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ export class ColorPicker {
|
|||||||
name=name.toLowerCase();
|
name=name.toLowerCase();
|
||||||
if(name==='洞主')
|
if(name==='洞主')
|
||||||
return ['hsl(0,0%,97%)','hsl(0,0%,25%)'];
|
return ['hsl(0,0%,97%)','hsl(0,0%,25%)'];
|
||||||
if(!window.config.color_picker)
|
|
||||||
return ['hsl(0,0%,87%)','hsl(0,0%,13%)'];
|
|
||||||
|
|
||||||
if(!this.names[name]) {
|
if(!this.names[name]) {
|
||||||
this.current_h+=golden_ratio_conjugate;
|
this.current_h+=golden_ratio_conjugate;
|
||||||
|
|||||||
Reference in New Issue
Block a user