This repository has been archived by the owner on Apr 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
co.js
54 lines (48 loc) · 1.58 KB
/
co.js
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
// CrossOriginJS
// Copyright (C) 2017-2018 Zaoqi
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
var _$CO$_=[];
var CrossOrigin=(function(){
var host="";
throw "請填寫CrossOrigin-host";
var uri=encodeURIComponent;
var scripts=[];
var free_cbs=[];
function uri_cb(callback){
var i=free_cbs.pop();
if(i===null){i=_$CO$_.length;}
_$CO$_[i]=function(x){
_$CO$_[i]=null;
free_cbs.push(i);
callback(x);};
return uri("_$CO$_["+i+"]");}
function alloc_script(src){
var script=scripts.pop();
if(script===null){
script=document.createElement('script');
script.src=src;
document.body.appendChild(script);
return script;
}else{
script.src=src;
return script;}}
function free_script(x){scripts.push(x);}
function http_get(file, callback, onerr) {
var script;
var cb=uri_cb(function(x){
free_script(script);
if(x===false) {
onerr&&onerr();
} else {
callback(x);}});
script=alloc_script(host+"/get.php?cb="+cb+"&x="+uri(file););}
return {get: http_get};})();