Browse Source

update

- add cr_version_test
- remove track config
- remove comment_cache and horizontal_scroll config
dev
xmcp 6 years ago
parent
commit
67e37973e2
  1. 5
      public/index.html
  2. 11
      src/Config.js
  3. 3
      src/Flows.css
  4. 2
      src/Flows.js
  5. 38
      src/cache.js

5
public/index.html

@ -33,6 +33,10 @@
_czc.push(["_setCustomVar","has_token",localStorage['TOKEN']?'yes':'no',1]);
_czc.push(["_setCustomVar","standalone",((window.matchMedia('(display-mode: standalone)').matches) || (window.navigator.standalone))?'yes':'no',1]);
_czc.push(["_setCustomVar","build_info","%REACT_APP_BUILD_INFO%"||'---']);
var cr_version=/Chrome\/(\d+)/.exec(navigator.userAgent);
_czc.push(["_setCustomVar","cr_version_test",cr_version?cr_version[1]:'[null]',2]);
/*
// track config
try {
var config=JSON.parse(localStorage['hole_config']||'{}');
for(var key in config)
@ -42,6 +46,7 @@
} catch(e) {
console.trace(e);
}
*/
var cnzz_s_tag = document.createElement('script');
cnzz_s_tag.type = 'text/javascript';
cnzz_s_tag.async = true;

11
src/Config.js

@ -14,9 +14,7 @@ const DEFAULT_CONFIG={
background_img: 'static/bg/gbp.jpg',
background_color: '#113366',
pressure: false,
horizontal_scroll: true,
easter_egg: true,
comment_cache: false,
color_scheme: 'default',
};
@ -223,7 +221,6 @@ export class ConfigUI extends PureComponent {
<div>
<div className="box config-ui-header">
<p>这些功能仍在测试可能不稳定<a onClick={this.reset_settings.bind(this)}>全部重置</a></p>
<p>我们会收集你的设置以用于改进产品</p>
<p><b>修改设置后 <a onClick={()=>{window.location.reload()}}>刷新页面</a> </b></p>
</div>
<div className="box">
@ -235,14 +232,6 @@ export class ConfigUI extends PureComponent {
description="短暂按住 Esc 键或重压屏幕(3D Touch)可以快速返回或者刷新树洞"
/>
<hr />
<ConfigSwitch callback={this.save_changes_bound} id="horizontal_scroll" name="横向滚动"
description="在树洞列表里横向滚动浏览回复,如果经常误触可以把它关掉"
/>
<hr />
<ConfigSwitch callback={this.save_changes_bound} id="comment_cache" name="评论缓存"
description="缓存已读树洞的评论(加载更快,但可能有bug)"
/>
<hr />
<ConfigSwitch callback={this.save_changes_bound} id="easter_egg" name="允许彩蛋"
description="在某些情况下显示彩蛋"
/>

3
src/Flows.css

@ -53,9 +53,6 @@
padding-left: 18px;
overflow-x: auto;
}
.flow-reply-row.config-no-scroll {
overflow-x: hidden !important;
}
.flow-reply-row::-webkit-scrollbar {
display: none;

2
src/Flows.js

@ -532,7 +532,7 @@ class FlowItemRow extends PureComponent {
}}>
<FlowItem parts={parts} info={this.state.info} attention={this.state.attention} img_clickable={false} is_quote={this.props.is_quote}
color_picker={this.color_picker} show_pid={show_pid} replies={this.state.replies} />
<div className={'flow-reply-row'+(window.config.horizontal_scroll ? '' : ' config-no-scroll')}>
<div className="flow-reply-row">
{this.state.reply_status==='loading' && <div className="box box-tip">加载中</div>}
{this.state.reply_status==='failed' &&
<div className="box box-tip"><a onClick={()=>{this.load_replies()}}>重新加载</a></div>

38
src/cache.js

@ -6,23 +6,21 @@ class Cache {
constructor() {
this.db=null;
this.added_items_since_maintenance=0;
if(window.config.comment_cache) {
const open_req=indexedDB.open('hole_cache_db',CACHE_DB_VER);
open_req.onerror=console.error.bind(console);
open_req.onupgradeneeded=(event)=>{
console.log('comment cache db upgrade');
const db=event.target.result;
const store=db.createObjectStore('comment',{
keyPath: 'pid',
});
store.createIndex('last_access','last_access',{unique: false});
};
open_req.onsuccess=(event)=>{
console.log('comment cache db loaded');
this.db=event.target.result;
setTimeout(this.maintenance.bind(this),1);
};
}
const open_req=indexedDB.open('hole_cache_db',CACHE_DB_VER);
open_req.onerror=console.error.bind(console);
open_req.onupgradeneeded=(event)=>{
console.log('comment cache db upgrade');
const db=event.target.result;
const store=db.createObjectStore('comment',{
keyPath: 'pid',
});
store.createIndex('last_access','last_access',{unique: false});
};
open_req.onsuccess=(event)=>{
console.log('comment cache db loaded');
this.db=event.target.result;
setTimeout(this.maintenance.bind(this),1);
};
}
get(pid,target_version) {
@ -35,15 +33,15 @@ class Cache {
get_req.onsuccess=()=>{
let res=get_req.result;
if(!res) {
console.log('cache miss');
//console.log('comment cache miss '+pid);
resolve(null);
} else if(target_version===res.version) { // hit
console.log('cache hit');
console.log('comment cache hit '+pid);
res.last_access=(+new Date());
store.put(res);
resolve(res.data);
} else { // expired
console.log('cache expired: ver',res.version,'target',target_version);
console.log('comment cache expired '+pid+': ver',res.version,'target',target_version);
store.delete(pid);
resolve(null);
}

Loading…
Cancel
Save