You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
33 KiB

3 years ago
/**
* $Id: helpers.js 697 2010-11-11 18:54:51Z wingedfox $
* $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.029/helpers.js $
*
* File contains differrent helper functions
*
* @author Ilya Lebedev <ilya@lebedev.net>
* @license LGPL
* @version $Rev: 697 $
3 years ago
*/
function isUndefined(i){return(typeof i=='undefined');}function isFunction(i){return(typeof i=='function');}function isString(i){return(typeof i=='string');}function isNumber(i){return(typeof i=='number');}function isNumeric(i){return(isNumber(i)||isString(i))&&!isNaN(parseInt(i))&&isFinite(parseInt(i));}function isArray(i){return(i instanceof Array);}function isRegExp(i){return(i instanceof RegExp);}function isBoolean(i){return('boolean'==typeof i);}function isScalar(i){return isNumeric(i)||isString(i)||isBoolean(i);}function isEmpty(i){if(isBoolean(i))return false;if(isRegExp(i)&&new RegExp("").toString()==i.toString())return true;if(isString(i)||isNumber(i)||isFunction(i))return!i;if(Boolean(i)&&false!=i){for(var I in i)if(i.hasOwnProperty(I))return false}return true}function gluePath(){var i=arguments.length,I=i-2,l=arguments[i-1];for(;I>=0;I--)l=((!isString(arguments[I])&&!isNumber(arguments[I]))||isEmpty(arguments[I])?l:arguments[I]+'\x00'+l);return l?l.replace(/\/*\x00+\/*/g,"/"):""}function findPath(i){var I=document.getElementsByTagName('html')[0].innerHTML,l=new RegExp('<scr'+'ipt[^>]+?src\\s*=\\s*["\']?([^>]+?/|)('+i+')([^"\'\\s]*)[^>]*>(.|[\r\n])*?</scr'+'ipt>','i'),o=I.match(l);if(o){if(!o[1])o[1]="";if(o[1].match(/^((https?|file)\:\/{2,}|\w:[\\])/))return o[1];if(o[1].indexOf("/")==0)return o[1];b=document.getElementsByTagName('base');if(b[0]&&b[0].href)return b[0].href+o[1];return(document.location.href.match(/(.*[\/\\])/)[0]+o[1]).replace(/^\/+/,"");}return null}function getScriptQuery(i){var I=document.getElementsByTagName('html')[0].innerHTML,l=new RegExp('<scr'+'ipt[^>]+?src\\s*=\\s*["\']?(?:[^>]+?/|)'+i+'([^#"\']*).+?</scr'+'ipt>','i'),o=I.match(l);if(o)return parseQuery(o[1].replace(/^[^?]*\?([^#]+)/,"$1"));return{}}function parseQuery(i){if('string'!=typeof i||i.length<2)return{};i=i.split(/&amp;|&/g);for(var I=0,l=i.length,o={},O,Q;I<l;I++){O=i[I].split("=");O[0]=O[0].replace(/[{}\[\]]*$/,"");Q=o[O[0]];O[1]=unescape(O[1]?O[1].replace("+"," "):"");if(Q)if('array'==typeof(Q))o[O[0]][o[O[0]].length]=O[1];else o[O[0]]=[o[O[0]],O[1]];else o[O[0]]=O[1]}return o}function table2array(i,I,l,o){if(isString(i))i=document.getElementById(i);if(!i||!DOM.hasTagName(i,['table','tbody,','thead','tfoot']))return null;if(!isEmpty(l)&&(!isString(l)||!(i=i.getElementsByTagName(l))))return null;if(!isEmpty(o)&&(!isNumber(o)||o<0||!(i=i[o])))return null;if(isUndefined(i.rows))return null;var O=[],Q=document.createElement('span'),_=null,c=null;for(var C=0,e=i.rows.length;C<e;C++){var v=[];if(isArray(I)){for(var V=0,x=I.length;V<x;V++){c=i.rows[C].cells[I[V]];if(c){Q.innerHTML=c.innerText?c.innerText:c.innerHTML.replace(/<script\s+(.|\r?\n)*?<\/script>|<[^>]*>/g,"");Q.normalize();v[v.length]=Q.firstChild?Q.firstChild.nodeValue.trim(" \xA0"):""}else{v[v.length]=""}}}else{for(var V=0,X=i.rows[C].cells.length;V<X;V++){cd=i.rows[C].cells[V];Q.innerHTML=c.innerText?c.innerText:c.innerHTML.replace(/<script\s+(.|\r?\n)*?<\/script>|<[^>]*>/g,"");Q.normalize();v[v.length]=Q.firstChild?Q.firstChild.nodeValue.trim(" \xA0"):""}}if(!isEmpty(v))O[O.length]=v}return O}document.createElementExt=function(i,I){var l,o,O,Q=document.createElement(i);if(!Q)return null;for(o in I){if(!I.hasOwnProperty(o))continue;switch(o){case"class":Q.setAttribute('className',I[o]);Q.setAttribute('class',I[o]);break;case"style":for(O in I[o]){if(!I[o].hasOwnProperty(O))continue;Q.style[O]=I[o][O]}break;case"event":for(O in I[o]){if(!I[o].hasOwnProperty(O))continue;Q.attachEvent(O,I[o][O]);}break;case"child":l=I[o].length;for(O=0;O<l;O++)Q.appendChild(I[o][O]);break;case"param":for(O in I[o]){if(!I[o].hasOwnProperty(O))continue;try{Q[O]=I[o][O]}catch(e){}}break}}return Q};function playInterval(I,o,O){return setInterval(function(){(O instanceof Array)?I.apply(this,O):I.call(this,O)},o)}function playTimeout(I,o,O){return setTimeout(function(){(O instanceof Array)?I.apply(this,O):I.call(this,O)},o)}function cloneObject(i){if(isScalar(i)||isFunction(i)||null==i)return i;try{var I=new i.constructor();}catch(e){return null}if(isArray(I)){for(var l=0,o=i.length;l<o;