view on requirebin
Created
October 17, 2013 13:34
-
-
Save donavon/7024999 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xcop = require("xcop"); | |
console.log("** XCOP DEMO **\n"); | |
var options = { | |
xcopDocument: "/host/0B32WZ_OndfDhY0lkSTNaeTNvSzA/xcop.html" | |
}; | |
var origin = "https://googledrive.com"; | |
xcop(origin, options).done(function (xhr) { | |
var request = { url: "message.json" }; | |
xhr(request).done(function (response) { | |
console.log("Status = " + response.status); | |
console.log("Headers ="); | |
for (var key in response.headers) { | |
console.log(" " + key + ": " + response.headers[key]); | |
} | |
console.log("Body = "); | |
console.log(response.body); | |
}); | |
}, function (err) { | |
console.log(err.message); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function(t,n,e){function r(e,i){if(!n[e]){if(!t[e]){var u="function"==typeof require&&require;if(!i&&u)return u(e,!0);if(o)return o(e,!0);throw Error("Cannot find module '"+e+"'")}var s=n[e]={exports:{}};t[e][0].call(s.exports,function(n){var o=t[e][1][n];return r(o?o:n)},s,s.exports)}return n[e].exports}for(var o="function"==typeof require&&require,i=0;e.length>i;i++)r(e[i]);return r}({xcop:[function(t,n){n.exports=t("4FMrKQ")},{}],"4FMrKQ":[function(t,n){"use strict";var e=t("q"),r=t("./xhr");n.exports=function(t,n){function o(n){var r=e.defer();return d[p]={deferred:r},v.postMessage(JSON.stringify({id:p,request:n}),t),p=(p+1)%65536,r.promise}function i(t){clearTimeout(y),window.removeEventListener("message",c),h.parentNode.removeChild(h),l.reject(t)}function u(){i(Error("XCOP is unavailable from origin "+t))}function s(n){return n.source===v&&n.origin===t?JSON.parse(n.data):null}function c(t){var n=s(t);n&&"XCOP-READY"===n.type?(clearTimeout(y),window.removeEventListener("message",c),window.addEventListener("message",f),l.resolve(o)):n&&"XCOP-ERROR"===n.type&&i(Error(n.message))}function f(t){var n=s(t);if(n&&"XCOP-RESPONSE"===n.type){var e=n.response,r=d[n.id].deferred;delete d[n.id],r.resolve(e)}}var a=location.protocol+"//"+location.host;if(n=n||{},t&&t!==a){var p=0,d={},l=e.defer();window.addEventListener("message",c);var h=document.createElement("iframe");h.style.display="none",document.body.appendChild(h);var v=h.contentWindow,y=setTimeout(u,1e3*(n.proxyTimeout||15));return h.src=t+(n.xcopDocument||"/xcop.html")+"?origin="+encodeURIComponent(a),l.promise}e.resolve(r)}},{"./xhr":1,q:2}],3:[function(t,n){var e=n.exports={};e.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(n){var e=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),e.length>0)){var n=e.shift();n()}},!0),function(t){e.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.binding=function(){throw Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(){throw Error("process.chdir is not supported")}},{}],2:[function(t,n,e){(function(t){(function(t){if("function"==typeof bootstrap)bootstrap("promise",t);else if("object"==typeof e)n.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=t}else Q=t()})(function(){"use strict";function n(t){return function(){return Y.apply(t,arguments)}}function e(t){return t===Object(t)}function r(t){return"[object StopIteration]"===on(t)||t instanceof J}function o(t,n){if(B&&n.stack&&"object"==typeof t&&null!==t&&t.stack&&-1===t.stack.indexOf(sn)){for(var e=[],r=n;r;r=r.source)r.stack&&e.unshift(r.stack);e.unshift(t.stack);var o=e.join("\n"+sn+"\n");t.stack=i(o)}}function i(t){for(var n=t.split("\n"),e=[],r=0;n.length>r;++r){var o=n[r];c(o)||u(o)||!o||e.push(o)}return e.join("\n")}function u(t){return-1!==t.indexOf("(module.js:")||-1!==t.indexOf("(node.js:")}function s(t){var n=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(t);if(n)return[n[1],Number(n[2])];var e=/at ([^ ]+):(\d+):(?:\d+)$/.exec(t);if(e)return[e[1],Number(e[2])];var r=/.*@(.+):(\d+)$/.exec(t);return r?[r[1],Number(r[2])]:void 0}function c(t){var n=s(t);if(!n)return!1;var e=n[0],r=n[1];return e===$&&r>=K&&dn>=r}function f(){if(B)try{throw Error()}catch(t){var n=t.stack.split("\n"),e=n[0].indexOf("@")>0?n[1]:n[2],r=s(e);if(!r)return;return $=r[0],r[1]}}function a(t,n,e){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(n+" is deprecated, use "+e+" instead.",Error("").stack),t.apply(t,arguments)}}function p(t){return g(t)?t:w(t)?C(t):N(t)}function d(){function t(t){n=t,i.source=t,G(e,function(n,e){W(function(){t.promiseDispatch.apply(t,e)})},void 0),e=void 0,r=void 0}var n,e=[],r=[],o=nn(d.prototype),i=nn(v.prototype);if(i.promiseDispatch=function(t,o,i){var u=z(arguments);e?(e.push(u),"when"===o&&i[1]&&r.push(i[1])):W(function(){n.promiseDispatch.apply(n,u)})},i.valueOf=a(function(){if(e)return i;var t=m(n);return g(t)&&(n=t),t},"valueOf","inspect"),i.inspect=function(){return n?n.inspect():{state:"pending"}},p.longStackSupport&&B)try{throw Error()}catch(u){i.stack=u.stack.substring(u.stack.indexOf("\n")+1)}return o.promise=i,o.resolve=function(e){n||t(p(e))},o.fulfill=function(e){n||t(N(e))},o.reject=function(e){n||t(S(e))},o.notify=function(t){n||G(r,function(n,e){W(function(){e(t)})},void 0)},o}function l(t){if("function"!=typeof t)throw new TypeError("resolver must be a function.");var n=d();try{t(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}return n.promise}function h(t){return l(function(n,e){for(var r=0,o=t.length;o>r;r++)p(t[r]).then(n,e)})}function v(t,n,e){void 0===n&&(n=function(t){return S(Error("Promise does not support operation: "+t))}),void 0===e&&(e=function(){return{state:"unknown"}});var r=nn(v.prototype);if(r.promiseDispatch=function(e,o,i){var u;try{u=t[o]?t[o].apply(r,i):n.call(r,o,i)}catch(s){u=S(s)}e&&e(u)},r.inspect=e,e){var o=e();"rejected"===o.state&&(r.exception=o.reason),r.valueOf=a(function(){var t=e();return"pending"===t.state||"rejected"===t.state?r:t.value})}return r}function y(t,n,e,r){return p(t).then(n,e,r)}function m(t){if(g(t)){var n=t.inspect();if("fulfilled"===n.state)return n.value}return t}function g(t){return e(t)&&"function"==typeof t.promiseDispatch&&"function"==typeof t.inspect}function w(t){return e(t)&&"function"==typeof t.then}function k(t){return g(t)&&"pending"===t.inspect().state}function j(t){return!g(t)||"fulfilled"===t.inspect().state}function x(t){return g(t)&&"rejected"===t.inspect().state}function b(){an||"undefined"==typeof window||window.Touch||!window.console||console.warn("[Q] Unhandled rejection reasons (should be empty):",cn),an=!0}function R(){for(var t=0;cn.length>t;t++){var n=cn[t];console.warn("Unhandled rejection reason:",n)}}function E(){cn.length=0,fn.length=0,an=!1,pn||(pn=!0,t!==void 0&&t.on&&t.on("exit",R))}function O(t,n){pn&&(fn.push(t),n&&n.stack!==void 0?cn.push(n.stack):cn.push("(no stack) "+n),b())}function T(t){if(pn){var n=Z(fn,t);-1!==n&&(fn.splice(n,1),cn.splice(n,1))}}function S(t){var n=v({when:function(n){return n&&T(this),n?n(t):this}},function(){return this},function(){return{state:"rejected",reason:t}});return O(n,t),n}function N(t){return v({when:function(){return t},get:function(n){return t[n]},set:function(n,e){t[n]=e},"delete":function(n){delete t[n]},post:function(n,e){return null===n||void 0===n?t.apply(void 0,e):t[n].apply(t,e)},apply:function(n,e){return t.apply(n,e)},keys:function(){return rn(t)}},void 0,function(){return{state:"fulfilled",value:t}})}function C(t){var n=d();return W(function(){try{t.then(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}}),n.promise}function D(t){return v({isDef:function(){}},function(n,e){return F(t,n,e)},function(){return p(t).inspect()})}function P(t,n,e){return p(t).spread(n,e)}function q(t){return function(){function n(t,n){var u;if(un){try{u=e[t](n)}catch(s){return S(s)}return u.done?u.value:y(u.value,o,i)}try{u=e[t](n)}catch(s){return r(s)?s.value:S(s)}return y(u,o,i)}var e=t.apply(this,arguments),o=n.bind(n,"next"),i=n.bind(n,"throw");return o()}}function M(t){p.done(p.async(t)())}function L(t){throw new J(t)}function A(t){return function(){return P([this,I(arguments)],function(n,e){return t.apply(n,e)})}}function F(t,n,e){return p(t).dispatch(n,e)}function I(t){return y(t,function(t){var n=0,e=d();return G(t,function(r,o,i){var u;g(o)&&"fulfilled"===(u=o.inspect()).state?t[i]=u.value:(++n,y(o,function(r){t[i]=r,0===--n&&e.resolve(t)},e.reject,function(t){e.notify({index:i,value:t})}))},void 0),0===n&&e.resolve(t),e.promise})}function _(t){return y(t,function(t){return t=tn(t,p),y(I(tn(t,function(t){return y(t,V,V)})),function(){return t})})}function U(t){return p(t).allSettled()}function X(t,n){return p(t).then(void 0,void 0,n)}function Q(t,n){return p(t).nodeify(n)}var B=!1;try{throw Error()}catch(H){B=!!H.stack}var $,J,K=f(),V=function(){},W=function(){function n(){for(;e.next;){e=e.next;var t=e.task;e.task=void 0;var r=e.domain;r&&(e.domain=void 0,r.enter());try{t()}catch(i){if(u)throw r&&r.exit(),setTimeout(n,0),r&&r.enter(),i;setTimeout(function(){throw i},0)}r&&r.exit()}o=!1}var e={task:void 0,next:null},r=e,o=!1,i=void 0,u=!1;if(W=function(n){r=r.next={task:n,domain:u&&t.domain,next:null},o||(o=!0,i())},t!==void 0&&t.nextTick)u=!0,i=function(){t.nextTick(n)};else if("function"==typeof setImmediate)i="undefined"!=typeof window?setImmediate.bind(window,n):function(){setImmediate(n)};else if("undefined"!=typeof MessageChannel){var s=new MessageChannel;s.port1.onmessage=function(){i=c,s.port1.onmessage=n,n()};var c=function(){s.port2.postMessage(0)};i=function(){setTimeout(n,0),c()}}else i=function(){setTimeout(n,0)};return W}(),Y=Function.call,z=n(Array.prototype.slice),G=n(Array.prototype.reduce||function(t,n){var e=0,r=this.length;if(1===arguments.length)for(;;){if(e in this){n=this[e++];break}if(++e>=r)throw new TypeError}for(;r>e;e++)e in this&&(n=t(n,this[e],e));return n}),Z=n(Array.prototype.indexOf||function(t){for(var n=0;this.length>n;n++)if(this[n]===t)return n;return-1}),tn=n(Array.prototype.map||function(t,n){var e=this,r=[];return G(e,function(o,i,u){r.push(t.call(n,i,u,e))},void 0),r}),nn=Object.create||function(t){function n(){}return n.prototype=t,new n},en=n(Object.prototype.hasOwnProperty),rn=Object.keys||function(t){var n=[];for(var e in t)en(t,e)&&n.push(e);return n},on=n(Object.prototype.toString);J="undefined"!=typeof ReturnValue?ReturnValue:function(t){this.value=t};var un;try{Function("(function* (){ yield 1; })"),un=!0}catch(H){un=!1}var sn="From previous event:";p.resolve=p,p.nextTick=W,p.longStackSupport=!1,p.defer=d,d.prototype.makeNodeResolver=function(){var t=this;return function(n,e){n?t.reject(n):arguments.length>2?t.resolve(z(arguments,1)):t.resolve(e)}},p.promise=l,p.passByCopy=function(t){return t},v.prototype.passByCopy=function(){return this},p.join=function(t,n){return p(t).join(n)},v.prototype.join=function(t){return p([this,t]).spread(function(t,n){if(t===n)return t;throw Error("Can't join: not the same: "+t+" "+n)})},p.race=h,v.prototype.race=function(){return this.then(p.race)},p.makePromise=v,v.prototype.toString=function(){return"[object Promise]"},v.prototype.then=function(t,n,e){function r(n){try{return"function"==typeof t?t(n):n}catch(e){return S(e)}}function i(t){if("function"==typeof n){o(t,s);try{return n(t)}catch(e){return S(e)}}return S(t)}function u(t){return"function"==typeof e?e(t):t}var s=this,c=d(),f=!1;return W(function(){s.promiseDispatch(function(t){f||(f=!0,c.resolve(r(t)))},"when",[function(t){f||(f=!0,c.resolve(i(t)))}])}),s.promiseDispatch(void 0,"when",[void 0,function(t){var n,e=!1;try{n=u(t)}catch(r){if(e=!0,!p.onerror)throw r;p.onerror(r)}e||c.notify(n)}]),c.promise},p.when=y,v.prototype.thenResolve=function(t){return this.then(function(){return t})},p.thenResolve=function(t,n){return p(t).thenResolve(n)},v.prototype.thenReject=function(t){return this.then(function(){throw t})},p.thenReject=function(t,n){return p(t).thenReject(n)},p.nearer=m,p.isPromise=g,p.isPromiseAlike=w,p.isPending=k,v.prototype.isPending=function(){return"pending"===this.inspect().state},p.isFulfilled=j,v.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},p.isRejected=x,v.prototype.isRejected=function(){return"rejected"===this.inspect().state};var cn=[],fn=[],an=!1,pn=!0;p.resetUnhandledRejections=E,p.getUnhandledReasons=function(){return cn.slice()},p.stopUnhandledRejectionTracking=function(){E(),t!==void 0&&t.on&&t.removeListener("exit",R),pn=!1},E(),p.reject=S,p.fulfill=N,p.master=D,p.spread=P,v.prototype.spread=function(t,n){return this.all().then(function(n){return t.apply(void 0,n)},n)},p.async=q,p.spawn=M,p["return"]=L,p.promised=A,p.dispatch=F,v.prototype.dispatch=function(t,n){var e=this,r=d();return W(function(){e.promiseDispatch(r.resolve,t,n)}),r.promise},p.get=function(t,n){return p(t).dispatch("get",[n])},v.prototype.get=function(t){return this.dispatch("get",[t])},p.set=function(t,n,e){return p(t).dispatch("set",[n,e])},v.prototype.set=function(t,n){return this.dispatch("set",[t,n])},p.del=p["delete"]=function(t,n){return p(t).dispatch("delete",[n])},v.prototype.del=v.prototype["delete"]=function(t){return this.dispatch("delete",[t])},p.mapply=p.post=function(t,n,e){return p(t).dispatch("post",[n,e])},v.prototype.mapply=v.prototype.post=function(t,n){return this.dispatch("post",[t,n])},p.send=p.mcall=p.invoke=function(t,n){return p(t).dispatch("post",[n,z(arguments,2)])},v.prototype.send=v.prototype.mcall=v.prototype.invoke=function(t){return this.dispatch("post",[t,z(arguments,1)])},p.fapply=function(t,n){return p(t).dispatch("apply",[void 0,n])},v.prototype.fapply=function(t){return this.dispatch("apply",[void 0,t])},p["try"]=p.fcall=function(t){return p(t).dispatch("apply",[void 0,z(arguments,1)])},v.prototype.fcall=function(){return this.dispatch("apply",[void 0,z(arguments)])},p.fbind=function(t){var n=p(t),e=z(arguments,1);return function(){return n.dispatch("apply",[this,e.concat(z(arguments))])}},v.prototype.fbind=function(){var t=this,n=z(arguments);return function(){return t.dispatch("apply",[this,n.concat(z(arguments))])}},p.keys=function(t){return p(t).dispatch("keys",[])},v.prototype.keys=function(){return this.dispatch("keys",[])},p.all=I,v.prototype.all=function(){return I(this)},p.allResolved=a(_,"allResolved","allSettled"),v.prototype.allResolved=function(){return _(this)},p.allSettled=U,v.prototype.allSettled=function(){return this.then(function(t){return I(tn(t,function(t){function n(){return t.inspect()}return t=p(t),t.then(n,n)}))})},p.fail=p["catch"]=function(t,n){return p(t).then(void 0,n)},v.prototype.fail=v.prototype["catch"]=function(t){return this.then(void 0,t)},p.progress=X,v.prototype.progress=function(t){return this.then(void 0,void 0,t)},p.fin=p["finally"]=function(t,n){return p(t)["finally"](n)},v.prototype.fin=v.prototype["finally"]=function(t){return t=p(t),this.then(function(n){return t.fcall().then(function(){return n})},function(n){return t.fcall().then(function(){throw n})})},p.done=function(t,n,e,r){return p(t).done(n,e,r)},v.prototype.done=function(n,e,r){var i=function(t){W(function(){if(o(t,u),!p.onerror)throw t;p.onerror(t)})},u=n||e||r?this.then(n,e,r):this;"object"==typeof t&&t&&t.domain&&(i=t.domain.bind(i)),u.then(void 0,i)},p.timeout=function(t,n,e){return p(t).timeout(n,e)},v.prototype.timeout=function(t,n){var e=d(),r=setTimeout(function(){e.reject(Error(n||"Timed out after "+t+" ms"))},t);return this.then(function(t){clearTimeout(r),e.resolve(t)},function(t){clearTimeout(r),e.reject(t)},e.notify),e.promise},p.delay=function(t,n){return void 0===n&&(n=t,t=void 0),p(t).delay(n)},v.prototype.delay=function(t){return this.then(function(n){var e=d();return setTimeout(function(){e.resolve(n)},t),e.promise})},p.nfapply=function(t,n){return p(t).nfapply(n)},v.prototype.nfapply=function(t){var n=d(),e=z(t);return e.push(n.makeNodeResolver()),this.fapply(e).fail(n.reject),n.promise},p.nfcall=function(t){var n=z(arguments,1);return p(t).nfapply(n)},v.prototype.nfcall=function(){var t=z(arguments),n=d();return t.push(n.makeNodeResolver()),this.fapply(t).fail(n.reject),n.promise},p.nfbind=p.denodeify=function(t){var n=z(arguments,1);return function(){var e=n.concat(z(arguments)),r=d();return e.push(r.makeNodeResolver()),p(t).fapply(e).fail(r.reject),r.promise}},v.prototype.nfbind=v.prototype.denodeify=function(){var t=z(arguments);return t.unshift(this),p.denodeify.apply(void 0,t)},p.nbind=function(t,n){var e=z(arguments,2);return function(){function r(){return t.apply(n,arguments)}var o=e.concat(z(arguments)),i=d();return o.push(i.makeNodeResolver()),p(r).fapply(o).fail(i.reject),i.promise}},v.prototype.nbind=function(){var t=z(arguments,0);return t.unshift(this),p.nbind.apply(void 0,t)},p.nmapply=p.npost=function(t,n,e){return p(t).npost(n,e)},v.prototype.nmapply=v.prototype.npost=function(t,n){var e=z(n||[]),r=d();return e.push(r.makeNodeResolver()),this.dispatch("post",[t,e]).fail(r.reject),r.promise},p.nsend=p.nmcall=p.ninvoke=function(t,n){var e=z(arguments,2),r=d();return e.push(r.makeNodeResolver()),p(t).dispatch("post",[n,e]).fail(r.reject),r.promise},v.prototype.nsend=v.prototype.nmcall=v.prototype.ninvoke=function(t){var n=z(arguments,1),e=d();return n.push(e.makeNodeResolver()),this.dispatch("post",[t,n]).fail(e.reject),e.promise},p.nodeify=Q,v.prototype.nodeify=function(t){return t?(this.then(function(n){W(function(){t(null,n)})},function(n){W(function(){t(n)})}),void 0):this};var dn=f();return p})})(t("__browserify_process"))},{__browserify_process:3}],1:[function(t,n){"use strict";var e=t("q");n.exports=function(t){var n=e.defer(),r=new XMLHttpRequest;return r.open(t.method||"GET",t.url,!0),Object.keys(t.headers||{}).forEach(function(n){r.setRequestHeader(n,t.headers[n])}),r.onreadystatechange=function(){if(r.readyState===r.DONE){var t={},e=r.getAllResponseHeaders();e.split(/\r?\n/).forEach(function(n){var e=/^([^\s]*)\s*:\s*(.*)/.exec(n);e&&(t[e[1].toLowerCase()]=e[2])});var o={status:r.status,body:r.responseText,headers:t};n.resolve(o)}},r.send(t.body),n.promise}},{q:2}]},{},[]);var xcop=require("xcop");console.log("** XCOP DEMO **\n");var options={xcopDocument:"/host/0B32WZ_OndfDhY0lkSTNaeTNvSzA/xcop.html"},origin="https://googledrive.com";xcop(origin,options).done(function(t){var n={url:"message.json"};t(n).done(function(t){console.log("Status = "+t.status),console.log("Headers =");for(var n in t.headers)console.log(" "+n+": "+t.headers[n]);console.log("Body = "),console.log(t.body)})},function(t){console.log(t.message)}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment