-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.html
143 lines (130 loc) · 3.62 KB
/
share.html
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>转发按钮</title>
<link href="css/component/retweet/retweet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
function share(){
var qstr = location.search.substr(1);
window.open('index.php?m=share&'+qstr);
}
function dequery(url){
var param = {};
url = url.substr(url.indexOf('?')+1);
if(url){
url = url.split('&');
for(var i=0,len=url.length;i<len;i++){
var arr = url[i].split('=');
param[arr[0]] = decodeURIComponent( arr[1] );
}
}
return param;
}
var params = dequery(location.search);
var type = params['type']||1;
var num = 0;
document.write('<div class="share share-'+type+'" onclick="share()"></div>');
function q(key) { return params[key]||''; }
// ----
var appkey = q('appkey') || 1681459862;
var jsc = +new Date;
/*
if(num)
getCount();
*/
function getJSON(s) {
var data;
var jsonp;
var ts = +new Date;
var jsre = /=\?(&|$)/g;
s.data = s.data || "";
s.data = (s.data ? s.data + "&" : "") + "callback" + "=?";
jsonp = "jsonp" + jsc++;
s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
window[jsonp] = function(tmp) {
data = tmp;
success();
window[jsonp] = undefined;
try{ delete window[jsonp]; }catch(e){}
if (head) head.removeChild(script);
};
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
if (s.data) {
s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
s.data = null;
}
var done = false;
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
if (s.scriptCharset) script.charset = s.scriptCharset;
script.src = s.url;
script.onload = script.onreadystatechange = function() {
if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
// success();
script.onload = script.onreadystatechange = null;
try {head.removeChild( script );}catch(e){}
}
};
head.appendChild(script);
var success = function() {
if (s.success) {
s.success(data);
}
};
}
function loadCount(url) {
var short_url = "http://api.t.sina.com.cn/short_url/shorten.json";
var count_url = "http://api.t.sina.com.cn/short_url/share/counts.json";
var short_data = "source=" + appkey + "&url_long=" + encodeURI(url);
getJSON({
url: short_url,
data: short_data,
scriptCharset: "utf-8",
success: function(data) {
if (!data) {
alert("API接口错误!");
return;
}
var count_data = "source=" + appkey + "&url_short=" + encodeURI(data[0].url_short);
getJSON({
url: count_url,
data: count_data,
scriptCharset: "utf-8",
success: function(data) {
if (!data) {
alert("API接口错误!");
return;
}
setCount(data);
}
});
}
});
};
function getCount() {
var url = q('url');
loadCount(url);
};
function setCount(data) {
var count = 0;
try {
count = data[0].share_counts || 0;
var n = count / 10000 >> 0;
if (n > 0) {
var m = (count % 10000) / 1000 >> 0;
m = m > 0 ? "." + m : "";
count = "" + n + m + "万"
}
} catch (e) {}
var ct = document.getElementById("count");
if(ct)
ct.innerHTML = count;
};
</script>
</body>
</html>