html2dynamic.js
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
[Discuz!] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: html2dynamic.js 32720 2013-03-04 10:21:58Z zhangguosheng $
*/
function htmlGetUserStatus () {
var x = new Ajax();
var type = '', typeid = 0, arr = [];
if(DYNAMICURL.indexOf('mod=topic') > -1) {
type = 'topic';
arr = DYNAMICURL.match(/topicid=(\d+)/);
typeid = arr ? arr[1] : 0;
} else if(DYNAMICURL.indexOf('mod=view') > -1) {
type = 'article';
arr = DYNAMICURL.match(/aid=(\d+)/);
typeid = arr ? arr[1] : 0;
}
x.getJSON('misc.php?mod=userstatus&r='+(+(new Date())+'&type='+type+'&typeid='+typeid), function (s) {
if(s) {
for(var key in s) {
switch(key) {
case 'userstatus' :
initUserstatus(s[key]);
break;
case 'qmenu' :
initQmenu(s[key]);
break;
case 'diynav' :
initDiynav(s[key]);
break;
case 'commentnum' :
case 'viewnum' :
initNum(key, s[key]);
break;
}
}
}
});
function initNum(name, val) {
var obj = null;
if(val > 0 && (obj = $('_'+name))) {
obj.innerHTML = parseInt(val);
}
}
function initUserstatus (code) {
try{
var lsform = $('lsform');
if(lsform) {
var i = 0, l = 0;
var parent = lsform.parentNode;
var dom = document.createElement('div');
dom.innerHTML = code;
var allNodes = dom.childNodes;
parent.removeChild(lsform);
for(i = 0,l = allNodes.length; i < l; i++) {
parent.appendChild(allNodes[0]);
}
evalscript(code);
}
} catch (e) {
debug('initUserstatus', e);
}
}
function initQmenu(code) {
try {
var qmenu = $('qmenu_menu');
if(qmenu) {
var dom = document.createElement('div');
dom.innerHTML = code;
qmenu.parentNode.replaceChild(dom.childNodes[0], qmenu);
evalscript(code);
}
} catch (e) {
debug('initQmenu', e);
}
}
function initDiynav(code) {
try {
var i = 0, l = 0;
var dom = document.createElement('div');
dom.innerHTML = code;
var allNodes = dom.childNodes;
var switchblind = $('switchblind');
var insertdom = '';
if(switchblind) {
insertdom = switchblind.parentNode;
for(i = 0,l = allNodes.length; i < l; i++) {
insertdom.appendChild(allNodes[0]);
}
} else {
var wp = $('wp');
if(wp) {
insertdom = wp.parentNode;
for(i = 0,l = allNodes.length; i < l; i++) {
insertdom.insertBefore(allNodes[0], wp);
}
}
}
} catch (e) {
debug('initDiynav', e);
}
}
function debug(name, e) {
if(console) {
console.log(name + ':' + e);
}
}
}
function htmlCheckUpdate() {
var timestamp = (+ new Date())/1000;
if(html_lostmodify && html_lostmodify < timestamp - 300) {
$F('make_html', [SITEURL + DYNAMICURL + (DYNAMICURL.indexOf('?') < 0 ? '?' : '&') + '_makehtml'], 'makehtml');
}
}