Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // STAGE I
- var MYGLOBAL = window.MYGLOBAL || {};
- MYGLOBAL.myProgram = function () {
- return {
- init: function () {
- alert('Hello, world!');
- }
- };
- }();
- window.onload = function () {
- MYGLOBAL.myProgram.init();
- };
- // STAGE II
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- window[trueName].myProgram = function () {
- return {
- init: function () {
- alert('Hello, ' + trueName + '!');
- }
- };
- }();
- window.onload = function () {
- window[trueName].myProgram.init();
- };
- // STAGE III
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function () {
- alert('Hello again, ' + trueName + '!');
- }
- };
- }();
- window.onload = function () {
- $.f.init();
- };
- })();
- // STAGE IV
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function (target) {
- var theScripts = document.getElementsByTagName('SCRIPT');
- for (var i = 0; i < theScripts.length; i++) {
- if (theScripts[i].src.match(target)) {
- $.w = document.createElement('DIV');
- $.w.innerHTML = 'Hello, world. My name is ' + trueName + '.';
- theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
- theScripts[i].parentNode.removeChild(theScripts[i]);
- break;
- }
- }
- }
- };
- }();
- var thisScript = /behavior.js/;
- var thisScriptProduction = /^https?:\/\/[^\/]*yourdomain.com\/yourpath\/behavior.js$/;
- window.onload = function () {
- $.f.init(thisScript);
- };
- })();
- // STAGE V
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function (target) {
- var theScripts = document.getElementsByTagName('SCRIPT');
- for (var i = 0; i < theScripts.length; i++) {
- if (theScripts[i].src.match(target)) {
- $.w = document.createElement('DIV');
- $.w.innerHTML = 'Hello, world. My name is ' + trueName + '.';
- theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
- theScripts[i].parentNode.removeChild(theScripts[i]);
- break;
- }
- }
- }
- };
- }();
- var thisScript = /behavior.js/;
- var thisScriptProduction = /^https?:\/\/[^\/]*yourdomain.com\/yourpath\/behavior.js$/;
- if (typeof window.addEventListener !== 'undefined') {
- window.addEventListener('load', function () {
- $.f.init(thisScript);
- }, false);
- } else if (typeof window.attachEvent !== 'undefined') {
- window.attachEvent('onload', function () {
- $.f.init(thisScript);
- });
- }
- })();
- // STAGE VI
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function (target) {
- var theScripts = document.getElementsByTagName('SCRIPT');
- for (var i = 0; i < theScripts.length; i++) {
- if (theScripts[i].src.match(target)) {
- $.w = document.createElement('DIV');
- $.w.innerHTML = 'Hello, world. My name is ' + trueName + '.';
- $.a = {};
- if (theScripts[i].innerHTML) {
- $.a = $.f.parseJson(theScripts[i].innerHTML);
- }
- if ($.a.err) {
- alert('bad json!');
- }
- if ($.a.color) {
- $.w.style.color = $.a.color;
- }
- theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
- theScripts[i].parentNode.removeChild(theScripts[i]);
- break;
- }
- }
- },
- parseJson: function (json) {
- this.parseJson.data = json;
- if (typeof json !== 'string') {
- return {
- "err": "trying to parse a non-string JSON object"
- };
- }
- try {
- var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,',
- 'Array,String,Math,RegExp,Image,ActiveXObject;',
- 'return (', json.replace(/<\!--.+-->/gim, '').replace(/\bfunction\b/g, 'function'), ');'
- ].join(''));
- return f();
- } catch (e) {
- return {
- "err": "trouble parsing JSON object"
- };
- }
- }
- };
- }();
- var thisScript = /behavior.js/;
- var thisScriptProduction = /^https?:\/\/[^\/]*yourdomain.com\/yourpath\/behavior.js$/;
- if (typeof window.addEventListener !== 'undefined') {
- window.addEventListener('load', function () {
- $.f.init(thisScript);
- }, false);
- } else if (typeof window.attachEvent !== 'undefined') {
- window.attachEvent('onload', function () {
- $.f.init(thisScript);
- });
- }
- })();
- // STAGE VII
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function (target) {
- var theScripts = document.getElementsByTagName('SCRIPT');
- for (var i = 0; i < theScripts.length; i++) {
- if (theScripts[i].src.match(target)) {
- $.w = document.createElement('DIV');
- $.a = {};
- if (theScripts[i].innerHTML) {
- $.a = $.f.parseJson(theScripts[i].innerHTML);
- }
- if ($.a.err) {
- alert('bad json!');
- }
- $.w.q = document.createElement('INPUT');
- if ($.a.query) {
- $.w.q.value = $.a.query;
- }
- $.w.q.onkeypress = function (e) {
- if ((e ? e.which : event.keyCode) == 13) {
- $.f.runSearch();
- }
- };
- $.w.appendChild($.w.q);
- $.w.b = document.createElement('BUTTON');
- $.w.b.innerHTML = 'Search';
- if ($.a.site) {
- $.w.b.innerHTML += ' ' + $.a.site;
- }
- $.w.b.onmouseup = function () {
- $.f.runSearch();
- };
- $.w.appendChild($.w.b);
- $.w.r = document.createElement('UL');
- $.w.appendChild($.w.r);
- theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
- theScripts[i].parentNode.removeChild(theScripts[i]);
- break;
- }
- }
- },
- runSearch: function () {
- $.w.r.innerHTML = '';
- if ($.w.q.value) {
- if (!$.f.runFunction) {
- $.f.runFunction = [];
- }
- var n = $.f.runFunction.length;
- var id = trueName + '.f.runFunction[' + n + ']';
- $.f.runFunction[n] = function (r) {
- delete($.f.runFunction[n]);
- $.f.removeScript(id);
- $.f.renderResult(r);
- }
- var url = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?';
- url += '&appid=YahooSearch';
- url += '&results=5';
- url += '&output=json';
- url += '&query=' + $.w.q.value;
- url += '&callback=' + id;
- if ($.a.site) {
- url += '&site=' + $.a.site;
- }
- $.f.runScript(url, id);
- }
- },
- renderResult: function (r) {
- for (var i = 0; i < r.ResultSet.Result.length; i++) {
- var li = document.createElement('LI');
- var a = document.createElement('A');
- a.innerHTML = r.ResultSet.Result[i].Title;
- a.href = r.ResultSet.Result[i].Url;
- a.target = '_blank';
- li.appendChild(a);
- $.w.r.appendChild(li);
- }
- },
- runScript: function (url, id) {
- var s = document.createElement('script');
- s.id = id;
- s.type = 'text/javascript';
- s.src = url;
- document.getElementsByTagName('body')[0].appendChild(s);
- },
- removeScript: function (id) {
- var s = '';
- if (s = document.getElementById(id)) {
- s.parentNode.removeChild(s);
- }
- },
- parseJson: function (json) {
- this.parseJson.data = json;
- if (typeof json !== 'string') {
- return {
- "err": "trying to parse a non-string JSON object"
- };
- }
- try {
- var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,',
- 'Array,String,Math,RegExp,Image,ActiveXObject;',
- 'return (', json.replace(/<\!--.+-->/gim, '').replace(/\bfunction\b/g, 'function'), ');'
- ].join(''));
- return f();
- } catch (e) {
- return {
- "err": "trouble parsing JSON object"
- };
- }
- }
- };
- }();
- var thisScript = /behavior.js/;
- var thisScriptProduction = /^https?:\/\/[^\/]*yourdomain.com\/yourpath\/behavior.js$/;
- if (typeof window.addEventListener !== 'undefined') {
- window.addEventListener('load', function () {
- $.f.init(thisScript);
- }, false);
- } else if (typeof window.attachEvent !== 'undefined') {
- window.attachEvent('onload', function () {
- $.f.init(thisScript);
- });
- }
- })();
- // STAGE VIII
- (function () {
- var trueName = '';
- for (var i = 0; i < 16; i++) {
- trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
- }
- window[trueName] = {};
- var $ = window[trueName];
- $.f = function () {
- return {
- init: function (target) {
- var theScripts = document.getElementsByTagName('SCRIPT');
- for (var i = 0; i < theScripts.length; i++) {
- if (theScripts[i].src.match(target)) {
- $.w = document.createElement('DIV');
- $.a = {};
- if (theScripts[i].innerHTML) {
- $.a = $.f.parseJson(theScripts[i].innerHTML);
- }
- if ($.a.err) {
- alert('bad json!');
- }
- $.d = {
- "background": "#fff",
- "border": "1px solid #000"
- };
- for (var k in $.d) {
- if ($.a[k] === undefined) {
- $.a[k] = $.d[k];
- }
- }
- var ns = document.createElement('style');
- document.getElementsByTagName('head')[0].appendChild(ns);
- if (!window.createPopup) {
- ns.appendChild(document.createTextNode(''));
- ns.setAttribute("type", "text/css");
- }
- var s = document.styleSheets[document.styleSheets.length - 1];
- var rules = {
- "": "{zoom:1;padding:5px;margin:5px;background:" + $.a.background + ";border:" + $.a.border + "}",
- "button": "{margin-left:5px;}",
- "ul": "{margin:0; padding:0;}",
- "ul li": "{list-style:none;}",
- };
- var ieRules = "";
- for (r in rules) {
- var selector = '.' + trueName + ' ' + r;
- if (!window.createPopup) {
- var theRule = document.createTextNode(selector + rules[r]);
- ns.appendChild(theRule);
- } else {
- ieRules += selector + rules[r];
- }
- }
- if (window.createPopup) {
- s.cssText = ieRules;
- }
- $.w.className = trueName;
- $.w.q = document.createElement('INPUT');
- if ($.a.query) {
- $.w.q.value = $.a.query;
- }
- $.w.q.onkeypress = function (e) {
- if ((e ? e.which : event.keyCode) == 13) {
- $.f.runSearch();
- }
- };
- $.w.appendChild($.w.q);
- $.w.b = document.createElement('BUTTON');
- $.w.b.innerHTML = 'Search';
- if ($.a.site) {
- $.w.b.innerHTML += ' ' + $.a.site;
- }
- $.w.b.onmouseup = function () {
- $.f.runSearch();
- };
- $.w.appendChild($.w.b);
- $.w.r = document.createElement('UL');
- $.w.appendChild($.w.r);
- theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
- theScripts[i].parentNode.removeChild(theScripts[i]);
- break;
- }
- }
- },
- runSearch: function () {
- $.w.r.innerHTML = '';
- if ($.w.q.value) {
- if (!$.f.runFunction) {
- $.f.runFunction = [];
- }
- var n = $.f.runFunction.length;
- var id = trueName + '.f.runFunction[' + n + ']';
- $.f.runFunction[n] = function (r) {
- delete($.f.runFunction[n]);
- $.f.removeScript(id);
- $.f.renderResult(r);
- }
- var url = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?';
- url += '&appid=YahooSearch';
- url += '&results=5';
- url += '&output=json';
- url += '&query=' + $.w.q.value;
- url += '&callback=' + id;
- if ($.a.site) {
- url += '&site=' + $.a.site;
- }
- $.f.runScript(url, id);
- }
- },
- renderResult: function (r) {
- for (var i = 0; i < r.ResultSet.Result.length; i++) {
- var li = document.createElement('LI');
- var a = document.createElement('A');
- a.innerHTML = r.ResultSet.Result[i].Title;
- a.href = r.ResultSet.Result[i].Url;
- a.target = '_blank';
- li.appendChild(a);
- $.w.r.appendChild(li);
- }
- },
- runScript: function (url, id) {
- var s = document.createElement('script');
- s.id = id;
- s.type = 'text/javascript';
- s.src = url;
- document.getElementsByTagName('body')[0].appendChild(s);
- },
- removeScript: function (id) {
- var s = '';
- if (s = document.getElementById(id)) {
- s.parentNode.removeChild(s);
- }
- },
- parseJson: function (json) {
- this.parseJson.data = json;
- if (typeof json !== 'string') {
- return {
- "err": "trying to parse a non-string JSON object"
- };
- }
- try {
- var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,',
- 'Array,String,Math,RegExp,Image,ActiveXObject;',
- 'return (', json.replace(/<\!--.+-->/gim, '').replace(/\bfunction\b/g, 'function'), ');'
- ].join(''));
- return f();
- } catch (e) {
- return {
- "err": "trouble parsing JSON object"
- };
- }
- }
- };
- }();
- var thisScript = /behavior.js/;
- var thisScriptProduction = /^https?:\/\/[^\/]*yourdomain.com\/yourpath\/behavior.js$/;
- if (typeof window.addEventListener !== 'undefined') {
- window.addEventListener('load', function () {
- $.f.init(thisScript);
- }, false);
- } else if (typeof window.attachEvent !== 'undefined') {
- window.attachEvent('onload', function () {
- $.f.init(thisScript);
- });
- }
- })();
- //<script src="behavior.js"></script>
- //<script src="behavior.js">{"site":"en.wikipedia.org", "background":"#ffa"}</script>
- //<script src="behavior.js">{"query":"madonna", "site":"mtv.com", "border":"1px solid red"}</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement