<US_functions>
On this page you'll find a javascript framework that I made for Userscripts.
I splitted it in 6 parts:
I think these parts speak for them self and don't need any explaination.
All parts with their own functions are shown below.
Every function is well documented, so you can use them.
A little explaination is given, followed by an example of use. After that - if avaible - a returned value. And the syntax how to use the function.
17-09-2008US_functions Common
////////////////////////////////////////////////////////////////////////////
// Function Name;
// syntax: how to refer to this variable/function (params included);
// return: [Constructor Name] what it returns (mostly NodeList);
// params: [Constructor Name] all possible paramaters (also hidden ones)(mostly Node);
// note: a note;
////////////////////////////////////////////////////////////////////////////
/** COMMON **/
// Window or unsafeWindow (GreaseMonkey Object);
window._=window;
// Window;
// syntax: $w;
_.$w = _;
// Navigator;
// syntax: $n;
_.$n = navigator;
// Document;
// syntax: $d;
_.$d = document;
// Document Body;
// syntax: $db;
_.$db = $d.body;
// Today;
// syntax: $2D;
_.$2D = new Date();
// Now;
// syntax: $now;
_.$now = $2D.getTime();
// UserAgent (browser);
// syntax: $uA;
_.$uA = $n.userAgent;
// Get Element By Id;
// syntax: $gi("testDiv");
// syntax: $gi("testDiv",$gi("testFrame"));
// return: [Node/NodeList][^Null] founded element(s);
// params: str [String/Array] name of the id or list of names;
// (frame) [Node] frame element (default: document)(optional);
_.$gi = function(str){
var doc=arguments[1]?arguments[1]:$d;
if(what.type.of(str)=="array"){
var nwArr=[];
for(var i=0; i < str.length; i++){
nwArr[i]=$gi(str[i],(arguments[1]?arguments[1]:false));
}
return nwArr;
}
else{
if($d.getElementById){
return doc.getElementById(str);
}
else if($d.all){
return doc.all[str];
}
else if($d.layers){ // NS4
function getNodeNN4(node,str){
var obj = node.layers,
foundLayer;
for(var i=0; i < obj.length; i++){
if(obj[i].id==str){
foundLayer = obj[i];
}
else if(obj[i].layers.length){
var tmp = getNodeNN4(obj[i],str);
}
if(tmp){
foundLayer = tmp;
} }
return foundLayer;
};
return getNodeNN4(doc,str);
} } };
// Get Element By Name;
// syntax: $gn("testForm");
// syntax: $gn("testForm",$gi("testFrame"));
// return: [NodeList][^empty Array] founded elements;
// params: str [String] name of the object;
// (frame) [Node] frame element (default: document)(optional);
_.$gn = function(str){
var doc=arguments[1]?arguments[1]:$d;
return doc.getElementsByName(str);
};
// Get Elements By Tag Name;
// syntax: $gt("input");
// syntax: $gt("*",$gi("testFrame"));
// return: [NodeList][^empty Array] founded elements;
// params: str [String] HTML element or "*" for all tags;
// (frame) [Node] frame element (default: document)(optional);
_.$gt = function(str){
var doc=arguments[1]?arguments[1]:$d;
if($d.getElementsByTagName){
return doc.getElementsByTagName(str);
}
else if($d.all){
return doc.all.tags(str);
}
else return [];
};
// Get Elements By Attribute;
// syntax: $gb(document.body,"*","id");
// syntax: $gb($gi("testDiv"),"input","type","password");
// return: [NodeList][^empty Array] founded elements;
// params: node [Node] refered element;
// tag [String] HTML element or "*" for all elements;
// attr [String] attribute name;
// value [String] match value (optional);
_.$gb = function(node,tag,attr,value){
var elems = (tag=="*" && node.all) ? node.all : node.getElementsByTagName(tag),
returnElems = new Array(),
nValue = (typeof value!="undefined") ? new RegExp("(^|\\s)" + value + "(\\s|$)") : null,
nAttr,
cur;
for(var i=0; i < elems.length; i++){
cur = elems[i];
nAttr = cur.getAttribute && $ga(cur,attr);
if(typeof nAttr=="string" && nAttr.length > 0){
if(typeof value=="undefined" || (nValue && nValue.test(nAttr))){
returnElems.push(cur);
} } }
return returnElems;
};
// Get Elements By Class Name;
// syntax: $gc($gi("testDiv"),"testClass1 testClass2","*");
// return: [NodeList][^empty Array] founded elements;
// params: node [Node] refered element (default: document);
// class [String] classname, seperated by space;
// tag [String] HTML element or "*" for all elements (default: all);
_.$gc = function(node,class,tag){
return $getElementsByClassName(node,class,tag)
};
// Get Elements By Value;
// syntax: $gv("testValue");
// return: [NodeList][^empty Array] founded elements;
// params: str [String] matched value;
// (frame) [Node] frame element (default: document)(optional);
_.$gv=function(str){
var returnArr = [],
tags = $gt("*",(arguments[1]?arguments[1]:false));
for(var i=0; i < tags.length; i++){
if(tags[i].value && tags[i].value.toString()===str){
returnArr.push(tags[i]);
} }
return returnArr;
};
// Get Attribute;
// syntax: $ga($gi("testDiv"),"id"); // returns: "testDiv";
// return: [String/Number/Boolean][^Null] founded attribute value;
// params: node [Node] refered element;
// attr [String] name of attribute;
// flag [Integer] 0=case-insensitive, 1=case-sensitive, 2=case-insensitive (default: 0)(optional);
_.$ga = function(node,attr,flag){
var isIE = /*@cc_on!@*/false, // Internet Explorer attribute converter;
a = attr;
if(isIE){
switch(a.toLowerCase()){
case "acceptcharset":
a = "acceptCharset";
break;
case "accesskey":
return node.accessKey;
break;
case "allowtransparency":
a = "allowTransparency";
break;
case "bgcolor":
a = "bgColor";
break;
case "cellpadding":
a = "cellPadding";
break;
case "cellspacing":
a = "cellSpacing";
break;
case "checked":
a = "defaultChecked";
break;
case "class":
a = "className";
break;
case "colspan":
a = "colSpan";
break;
case "defaultchecked":
a = "defaultChecked";
break;
case "defaultselected":
a = "defaultSelected";
break;
case "defaultvalue":
a = "defaultValue";
break;
case "float":
a = "cssFloat";
break;
case "for":
a = "htmlFor";
break;
case "type":
return node.type;
break;
case "frameborder":
a = "frameBorder";
break;
case "hspace":
a = "hSpace";
break;
case "longdesc":
a = "longDesc";
break;
case "maxlength":
return node.maxLength;
break;
case "marginwidth":
a = "marginWidth";
break;
case "marginheight":
a = "marginHeight";
break;
case "noresize":
a = "noResize";
break;
case "noshade":
a = "noShade";
break;
case "readonly":
a = "readOnly";
break;
case "rowspan":
a = "rowSpan";
break;
case "style":
return node.style.cssText;
break;
case "tabindex":
a = "tabIndex";
break;
case "valign":
a = "vAlign";
break;
case "vspace":
a = "vSpace";
break;
} }
return node.getAttribute(a,flag);
};
// Set Attribute;
// syntax: $sa($ce("div"),"id","testDiv");
// return: [Node][^Null] refered element(s);
// params: node [Node/NodeList] refered element(s);
// attr [String] name of attribute;
// val [String/Number/Boolean] new value;
// flag [Integer] 0=case-insensitive, 1=case-sensitive (default: 1)(optional);
_.$sa = function(node,attr,val,flag){
var isIE = /*@cc_on!@*/false, // Internet Explorer attribute converter;
a = attr;
if(isIE){
switch(a.toLowerCase()){
case "acceptcharset":
a = "acceptCharset";
break;
case "accesskey":
node.accessKey=val;
return node;
break;
case "allowtransparency":
a = "allowTransparency";
break;
case "bgcolor":
a = "bgColor";
break;
case "cellpadding":
a = "cellPadding";
break;
case "cellspacing":
a = "cellSpacing";
break;
case "checked":
a = "defaultChecked";
break;
case "class":
a = "className";
break;
case "colspan":
a = "colSpan";
break;
case "defaultchecked":
a = "defaultChecked";
break;
case "defaultselected":
a = "defaultSelected";
break;
case "defaultvalue":
a = "defaultValue";
break;
case "float":
a = "cssFloat";
break;
case "for":
a = "htmlFor";
break;
case "name": // Needs to recreate the element with: document.createElement('<input name="testName"/>');
node.outerHTML = node.outerHTML.replace(/name=[a-zA-Z]+/," name=" + val + " ");
return;
break;
case "type": // 'type' is readonly, solution is to recreate the element;
node.outerHTML = node.outerHTML.replace(/type=[a-zA-Z]+/," type=" + val + " ");
return;
break;
case "frameborder":
a = "frameBorder";
break;
case "hspace":
a = "hSpace";
break;
case "longdesc":
a = "longDesc";
break;
case "maxlength":
node.maxLength=val;
return node;
break;
case "marginwidth":
a = "marginWidth";
break;
case "marginheight":
a = "marginHeight";
break;
case "noresize":
a = "noResize";
break;
case "noshade":
a = "noShade";
break;
case "readonly":
a = "readOnly";
break;
case "rowspan":
a = "rowSpan";
break;
case "style":
node.style.cssText=val;
return node;
break;
case "tabindex":
a = "tabIndex";
break;
case "valign":
a = "vAlign";
break;
case "vspace":
a = "vSpace";
break;
} }
if(what.type.of(node)=="array"){
for(var i=0; i < node.length; i++){
node[i].setAttribute(a,val,flag);
} }
else{
node.setAttribute(a,val,flag);
}
return node;
};
// Remove Attribute;
// syntax: $ra($gi("testDiv"),"id");
// return: [Node][^Null] refered element;
// params: node [Node/NodeList] refered element;
// attr [String] name of attribute;
// flag [Integer] 0=case-insensitive, 1=case-sensitive (default: 1)(optional);
_.$ra = function(node,attr,flag){
var isIE = /*@cc_on!@*/false, // Internet Explorer attribute converter;
a = attr;
if(isIE){
switch(a.toLowerCase()){
case "acceptcharset":
a = "acceptCharset";
break;
case "accesskey":
node.accessKey="";
return;
break;
case "allowtransparency":
a = "allowTransparency";
break;
case "bgcolor":
a = "bgColor";
break;
case "cellpadding":
a = "cellPadding";
break;
case "cellspacing":
a = "cellSpacing";
break;
case "checked":
a = "defaultChecked";
break;
case "class":
a = "className";
break;
case "colspan":
a = "colSpan";
break;
case "defaultchecked":
a = "defaultChecked";
break;
case "defaultselected":
a = "defaultSelected";
break;
case "defaultvalue":
a = "defaultValue";
break;
case "float":
a = "cssFloat";
break;
case "for":
a = "htmlFor";
break;
case "name": // Needs to recreate the element without the name in it;
node.outerHTML = node.outerHTML.replace(/name=[a-zA-Z]+/," ");
return;
break;
case "type": // 'type' is readonly, solution is to recreate the element;
node.outerHTML = node.outerHTML.replace(/type=[a-zA-Z]+/," ");
return;
break;
case "frameborder":
a = "frameBorder";
break;
case "hspace":
a = "hSpace";
break;
case "longdesc":
a = "longDesc";
break;
case "maxlength":
node.maxLength="";
return;
break;
case "marginwidth":
a = "marginWidth";
break;
case "marginheight":
a = "marginHeight";
break;
case "noresize":
a = "noResize";
break;
case "noshade":
a = "noShade";
break;
case "readonly":
a = "readOnly";
break;
case "rowspan":
a = "rowSpan";
break;
case "style":
node.style.cssText="";
return;
break;
case "tabindex":
a = "tabIndex";
break;
case "valign":
a = "vAlign";
break;
case "vspace":
a = "vSpace";
break;
} }
if(what.type.of(node)=="array"){
for(var i=0; i < node.length; i++){
node[i].removeAttribute(a,flag);
} }
else{
node.removeAttribute(a,flag);
}
return node;
};
// Create Element;
// syntax: $ce("div");
// syntax: $ce("div",$gi("testFrame"));
// return: [Node] new element;
// params: str [String] name of new element;
// (frame) [Node] frame element (default: document)(optional);
_.$ce = function(str){
var doc=arguments[1]?arguments[1]:$d;
return doc.createElement(str);
};
// Create Text;
// syntax: $ct("Hello World!");
// syntax: $ct("Hello World!",$gi("testFrame"));
// return: [Node] new element;
// params: str [String] name of new element;
// (frame) [Node] frame element (default: document)(optional);
_.$ct = function(str){
var doc=arguments[1]?arguments[1]:$d;
return doc.createTextNode(str);
};
// Inner Html;
// syntax: $ih($gi("testDiv"),"<strong>Some Text</strong>");
// return: [String] raw HTML;
// params: node [Node] refered element;
// HTML [String] raw HTML;
// note: to show the < and > character you must use <& and >&;
_.$ih = function(node,HTML){
return node.innerHTML = HTML;
};
// Append Child;
// syntax: $ac($ce("div"),$ct("Hello World!"));
// return: [Node] new element;
// params: node [Node] refered element;
// nNode [Node] new element;
_.$ac = function(node,nNode){
return node.appendChild(nNode);
};
// Append First;
// syntax: $af($ce("div"),$ct("Hello World!"));
// return: [Node] new element;
// params: node [Node] refered element;
// nNode [Node] new element;
_.$af = function(node,nNode){
return node.insertBefore(nNode,node.firstChild);
};
// Insert After;
// syntax: $ia($ce("div"),$ct("Hello World!"));
// return: [Node] new element;
// params: node [Node] refered element;
// nNode [Node] new element;
_.$ia = function(node,nNode){
return node.parentNode.insertBefore(nNode,node.nextSibling);
};
// Insert Before;
// syntax: $ib($ce("div"),$ct("Hello World!"));
// return: [Node] new element;
// params: node [Node] refered element;
// nNode [Node] new element;
_.$ib = function(node,nNode){
return node.parentNode.insertBefore(nNode,node);
};
// Remove Element;
// syntax: $re($gi("testDiv"));
// return: [Node] refered element;
// params: node [Node] refered element;
_.$re = function(node){
return node.parentNode.removeChild(node);
};
// Remove Childs;
// syntax: $rc($gi("testDiv"));
// return: [NodeList][^empty Array] deleted child objects;
// params: node [Node] refered element;
_.$rc = function(node){
var childs = [];
while(node.hasChildNodes()){
node.removeChild(node.firstChild);
childs.push(node.firstChild);
}
return childs;
};
17-09-2008US_functions Prototype
////////////////////////////////////////////////////////////////////////////
/** PROTOTYPE **/
/* Array */
// Compare;
// syntax: testArray1.compare(testArray2);
// return: [Boolean] returns boolean if arrays are the same;
// params: [Array] used array;
// arr [Array] target array;
// note: array's must be same length;
Array.prototype.compare = function(arr){
if(this.length != arr.length) return false;
for(var i = 0; i < arr.length; i++){
if(this[i].compare){
if(!this[i].compare(arr[i])) return false;
else continue;
}
if(this[i] != arr[i]) return false;
}
return true;
};
// Copy;
// syntax: testArray1=testArray2.clone();
// return: [Array] new array;
// params: [Array] used array;
Array.prototype.clone = function(){
var a = new Array();
for(var property in this){
a[property] = typeof(this[property])=='object' ? this[property].clone() : this[property];
}
return a;
};
// Empty;
// syntax: testArray.empty();
// return: [Array] empty array;
// syntax: [Array] used array;
Array.prototype.empty = function(){
for(var i=0; i<=this.length; i++){
this.shift();
}
return this;
};
// Exist;
// Checks if all nodes in a nodelist exist;
// syntax: testNodeList.exist();
// return: [Boolean] check if all nodes exist;
// syntax: [NodeList] used nodelist;
Array.prototype.exist = function(){
for(var i=0; i < this.length; i++){
if(what.type.of(this[i])!='node'){
return false;
} }
return true;
};
// Find;
// syntax: testArray.find("test");
// testArray.find(/^blue/i);
// return: [Array[Integer,...]][^false] returns position or false if not excist;
// syntax: [Array] used array;
// str [String/Regexp] value to look for, can be string or regexp;
Array.prototype.find = function(str){
var returnArr = false;
for(var i = 0; i < this.length; i++){
if(typeof(str) == 'function'){
if(str.test(this[i])){
if(!returnArr){
returnArr = [];
}
returnArr.push(i);
} }
else{
if(this[i]===str){
if(!returnArr){
returnArr = [];
}
returnArr.push(i);
} } }
return returnArr;
};
// Remove From To;
// syntax: testArray.remove(1); // Remove the second item from the array;
// testArray.remove(-3,-1); // Remove the last, second-to-last and third-to-last items from the array;
// return: [Array] refered array without selected part;
// syntax: [Array] used array;
// from [Integer] begin index;
// to [Integer] end index (optional);
// note: counting from zero (0). Using a negative integer (-) counts backwards (e.g: -2 is second-to-last);
Array.prototype.remove = function(from,to){
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this,rest);
};
// Unique;
// syntax: testArray.unique();
// return: [Array] refered array without duplicates;
// syntax: [Array] used array;
Array.prototype.unique = function(){
for(var i=1; i < this.length; i++){
if(this[i][0]==this[i-1][0]){
this.splice(i,1);
} }
return this;
};
// Replace;
// syntax: [13,3,["3",3.3],3,"3nd",{test3:"test3"}].replace(/3/,"Seven"); // returns: ["1Seven","Seven",["Seven","Seven.Seven"],"Seven","Seventh",{test3:"test3"}];
// [13,3,["3",3.3],3,"3nd",{test3:"test3"}].replace(/3/,9); // returns: [19,9,["9",9.9],9,"9th",{test3:"test3"}];
// return: [Array] refered array with new replacement;
// params: [Array] used array;
// exp [Regexp/String] condition to replace;
// str [String/Number] replacement;
// note: if both the array item and the str numbers are, they will be converted as number; Inherited array;Functions and Objects are excluded;
Array.prototype.replace = function(exp,str){
for(var i in this){
if(this[i].replace){
this[i].replace(exp,str);
}
while(this[i].toString().match(exp)){
var isN = typeof(this[i])=="number" && typeof(str)=="number";
this[i] = this[i].toString().replace(exp,str);
if(isN)this[i] = Number(this[i]);
}
}
return this;
};
// Search;
// syntax: [13,3,["3",3.3],3,"3nd",{test3:"test3"}].search("3"); // returns true;
// [13,3,["3",3.3],3,"3nd",{test3:"test3"}].search("3 ",false,false); // returns false;
// return: [Boolean] true if found, else false;
// params: [Array] used array;
// str [String] string to look for;
// caseInsens [Boolean] case insensitive (default: true)(optional);
// ignoreSpaces [Boolean] ignore spaces (default: true)(optional);
Array.prototype.search = function(str,caseInsens,ignoreSpaces){
var inArr = false,
nArr = [];
for(var i = 0; i < this.length; i++){
if(what.type.of(this[i])=="array"){
inArr=this[i].search(str,caseInsens,ignoreSpaces);
}
else{
nArr[i] = this[i];
if(caseInsens != false){
if(typeof(str)=="string"){str = str.toLowerCase();}
if(typeof(nArr[i])=="string"){nArr[i] = nArr[i].toLowerCase();}
}
if(ignoreSpaces != false){
if(typeof(str)=="string"){str = str.replace(/\s+/g,"");}
if(typeof(nArr[i])=="string"){nArr[i] = nArr[i].replace(/\s+/g,"");}
}
if(nArr[i] === str){
inArr = true;
break;
} } }
return inArr;
};
// Switch;
// syntax: [1,"two",3,4].switch(3,0)); // returns 4,"two",3,1;
// return: [Array] new array;
// params: [Array] used array;
// x [Integer] position 1;
// y [Integer] position x;
// note: an array index begins always with the number 0;
Array.prototype.switch = function(x,y){
this.splice(y+1,0,this.slice(x,x+1)[0]);
this.splice(x,1,this.splice(y,1)[0]);
return this;
};
/* Number */
// Between;
// syntax: var n=1986; n.between(100,2000); // returns: true;
// return: [Boolean] true if between values, else false;
// syntax: [Number] used number;
// min [Number] minimal value;
// max [Number] maximal value;
Number.prototype.between = function(min,max){
return(min<=this && this < max);
};
// Repeat;
// syntax: var n=3; n.repeat(5); // returns: 33333;
// return: [Integer][^NaN] multiplied integer;
// params: [Integer] used integer;
// n [Integer] how many times to repeat;
Number.prototype.repeat = function(n){
return Number(new Array(n + 1).join(this););
};
// Replace;
// syntax: var n=33; n.replace(/3/g,4); // returns: 44;
// return: [Number][^NaN] new number or NaN if not a number;
// params: [Number] used number;
// exp [Regexp] condition;
// n [Number] new number
Number.prototype.replace = function(exp,n){
return Number(this.toString().replace(exp,n.toString()));
}
/* Object */
// Copy;
// syntax: testObject1=testObject2.clone();
// return: [Object] new object;
// params: [Object] used object;
Object.prototype.clone = function(){
var o = new Object();
for(var property in this){
o[property] = typeof(this[property])=='object' ? this[property].clone() : this[property];
}
return o;
};
/* String */
// HTML To Entities;
// Convert HTML symbols to HTML entities;
// syntax: "'Hello World !'".htmlEntities(); // returns: "'Hello World !'";
// return: [String] string with converted symbols;
// params: [String] used string;
String.prototype.html2Entities = function(){
return this.replace(/[^\x09\x0A\x0D\x20-\x7F]|[\x21-\x2F]|[\x3A-\x40]|[\x5B-\x60]/g, function(e){
return '' + e.charCodeAt(0) + ';'
});
};
// First Letter Capital;
// syntax: "hello world".firstLetterCapital(); // returns: "Hello world";
// return: [String] string with first letter capital;
// params: [String] used string;
String.prototype.firstLetterCapital = function(){
return this.toString().substr(0,1).toUpperCase() + this.toString().toLowerCase().substr(1,this.toString().length);
};
// Repeat;
// syntax: "text ".repeat(5); // returns: "text text text text text ";
// return: [String] multiplied string;
// params: [String] used string;
// n [Integer] how many times to repeat;
String.prototype.repeat = function(n){
return new Array(n+1).join(this);
};
// Strip;
// syntax: "Hello World".strip(/\s/g); // returns: "HelloWorld";
// return: [String] string after rexexp;
// params: [String] used string;
// exp [Regexp] strip conditions (default: /\s/g)(optional);
String.prototype.strip = function(exp){
return this.replace(exp?exp:/\s/g,"");
};
// To Camel Case;
// syntax: "hello world".toCamelCase(); // returns: "helloWorld";
// return: [String] string with camelcase;
// params: [String] used string;
String.prototype.toCamelCase = function(){
return this.toString().replace(/([A-Z]+)/g, function(m,l){
return l.substr(0,1).toUpperCase() + l.toLowerCase().substr(1,l.length);
}).replace(/[\-_\s](.)/g, function(m,l){
return l.toUpperCase();
});
};
// Trim;
// syntax: " Hello World ".trim(); // returns: "Hello World";
// return: [String] string without leading and trailing spaces;
// params: [String] used string;
String.prototype.trim = function(){
return this.replace(/^\s\s*/,'').replace(/\s\s*$/,'');
};
// Truncate;
// syntax: "Hello World".truncate(10); // returns: "Hello W...";
// "Hello World".truncate(10,"~"); // returns: "Hello W~~~";
// "Hello World".truncate(10,false); // returns: "Hello Worl";
// return: [String] string truncated at length with specified ellipsis;
// params [String] used string;
// n [Integer] maximal string length;
// ellipsis [Boolean/String] false=no ellipsis, true=common ellipsis ("."), custom ellipsis (default: ".")(optional);
// note: ellipsis is multiple by 3 and when ellipsis is used the string is truncated even more with 3;
String.prototype.truncate = function(n,ellipsis){
return this.substring(0,(ellipsis!==false && this.length>n ? n-3 : n)) +
(ellipsis!==false && this.length>n ? (typeof ellipsis=="string" ? ellipsis : ".").repeat(3) : "");
};
17-09-2008US_functions Style
////////////////////////////////////////////////////////////////////////////
/** STYLE **/
// Add Style;
// syntax: $addCSS("table.commandTable{width:100%;padding:5px;background-color:#3399FF;border:1px solid #0066CC}");
// params: css [String] CSS;
// (frame) [Node] frame element (optional);
// note: Add "!important" at the end of the value to overrule an existing value;
_.$addCSS = function(css){
if(typeof US_addStyle!="undefined"){
GM_addStyle(css);
}
else if(typeof addStyle!="undefined"){
addStyle(css);
}
else{
var head = $gt("HEAD",(arguments[1]?arguments[1]:false)),
node = $ce("STYLE");
node.type = "text/css";
$ih(node,css);
$ac(head[0],node);
} };
// Get Rendered Style;
// syntax: $getStyle($gi("testDiv"),"font-size");
// return: [String] style value;
// params: node [Node] refered element;
// attr [String] style attribute;
// (frame) [Node] frame element (default: document)(optional);
// note: Mozilla (Firefox), Opera and Safari will return the actual pixels of a measurement, while IE returns the used value;
_.$getStyle = function(node,attr){
var doc=arguments[2]?arguments[2]:$d;
if($d.defaultView && $d.defaultView.getComputedStyle){ /**Mozilla,Opera,Safari**/
return doc.defaultView.getComputedStyle(node,null).getPropertyValue(attr);
}
else if(node.currentStyle){ /**IE**/
return node.currentStyle[attr.toCamelCase()];
} };
// Set Opacity;
// syntax: $setOpacity($gi("testDiv"),70);
// params: node [Node] element;
// n [Integer] procent from 0 to 100;
_.$setOpacity = function(node,n){
var node = node.style;
node.opacity = (n/100); /** CSS3: Gecko 1.9+/Opera 9+/WebKit 3+ **/
node.filter = "alpha(opacity="+n+")"; /** IE 5.5+ **/
node.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+n+")"; /** IE 5.5+ **/
node.MozOpacity = (n/100); /** Gecko: Mozilla/Firefox 0.9+ **/
node.KhtmlOpacity = (n/100); /** KHTML: Kongueror **/
node.WebkitOpacity = (n/100); /** Webkit: Safari **/
node.AppleOpacity = (n/100); /** Apple: Safari **/
};
// Set Return Opacity;
// syntax: $setReturnOpacity(70);
// return: [String] browser compatible opacity;
// params: n [Integer] procent from 0 to 100;
_.$setReturnOpacity = function(n){
return 'opacity:'+(n/100)+';'+ /** CSS3: Gecko 1.9+/Opera 9+/WebKit 3+ **/
'-ms-filter:"alpha(opacity='+n+')";'+ /** IE 8+ **/
'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity='+n+')";'+ /** IE 8+ **/
'filter:alpha(opacity='+n+');'+ /**IE 5.5+**/
'filter:progid:DXImageTransform.Microsoft.Alpha(opacity='+n+');'+ /** IE 5.5+ **/
'-moz-opacity:'+(n/100)+';'+ /** Gecko: Mozilla/Firefox 0.9+ **/
'-khtml-opacity:'+(n/100)+';'+ /** KHTML: Kongueror **/
'-webkit-opacity:'+(n/100)+';'+ /** Webkit: Safari **/
'-apple-opacity:'+(n/100)+';'; /** Apple: Safari **/
};
// Hide Show;
// syntax: if($hs($gi("cmdUpdater"),1,true)){$hs($gi("cmdUpdater"),2);};
// return: [Boolean/Node] if riturn is true a boolean is returned, else the refered element;
// params: node [Node] refered element;
// way [Integer] 0=hide, 1=show, 3=toggle (2=hide);
// riturn [Boolean] check for situation only (default: false)(optional);
// inlineTable [Boolean] check for inline tabels (default: false)(optional);
_.$hs = function(node,way,riturn,inlineTable){
hsDisplayObj = inlineTable?"":"block";
if(riturn){ /**return**/
if(way==1){ /**show**/
if(node.style.display=="block"||node.style.display=="inline-table"||node.style.visibility=="visible"||!(node.style.display=="none"||node.style.visibility=="hidden")){
return true;
}
else return false;
}
else if(way==2||way==0){ /**hide**/
if(node.style.display=="none"||node.style.visibility=="hidden"){
return true;
}
else return false;
}
else if(way==3){ /**toggle**/
$alert('',4,'$hs01','There is no toggle return');
return null;
} }
else{ /**switch**/
if(way==1){ /**show**/
node.style.display = hsDisplayObj;
node.style.visibility = "visible";
}
else if(way==2||way==0){ /**hide**/
node.style.display = "none";
node.style.visibility = "hidden";
}
else if(way==3){ /**toggle**/
if(node.style.display=="none"||node.style.visibility=="hidden"){
node.style.display = hsDisplayObj;
node.style.visibility = "visible";
}
else{
node.style.display = "none";
node.style.visibility = "hidden";
} }
return node;
} };
// Fade In;
// syntax: $opacityFadeIn($gi("testDiv"),-1,100,100,5,function(){alert("finished")},function(){alert("busy")});
// params: node [Node] refered element;
// start [Integer] start opacity (0-100%);
// end [Integer] end opacity (0-100%)(must be higher then start);
// time [Integer] time interval in miliseconds;
// steps [Integer] steps between start and end;
// fnFinish [Function] function to execute when finished (optional);
// fnBusy [Function] function to execute while busy (optional);
// note: to stop the time interval use: $w.clearTimeout($opacityFadeInTimer);
_.$opacityFadeIn = function(node,start,end,time,steps,fnFinish,fnBusy){
if(start < end){
$setOpacity(node,start);
if(fnBusy&&typeof(fnBusy)=="function"){fnBusy();} /*do something*/
var $opacityFadeInTimer = $w.setTimeout(function(){start+=(steps); $opacityFadeIn(node,start,end,time,steps,fnFinish,fnBusy)},time);
}
else if(start >= end){
if(fnFinish&&typeof(fnFinish)=="function"){fnFinish();} /*do something*/
} };
// Fade Out;
// syntax: $opacityFadeOut($gi("testDiv"),100,-1,100,5,function(){alert("finished")},function(){alert("busy")});
// params: node [Node] refered element;
// start [Integer] start opacity (0-100%);
// end [Integer] end opacity (0-100%)(must be lower then start);
// time [Integer] time interval in miliseconds;
// steps [Integer] steps between start and end;
// fnFinish [Function] function to execute when finished (optional);
// fnBusy [Function] function to execute while busy (optional);
// note: to stop the time interval use: $w.clearTimeout($opacityFadeOutTimer);
_.$opacityFadeOut = function(node,start,end,time,steps,fnFinish,fnBusy){
if(start > end){
$setOpacity(node,start);
if(fnBusy&&typeof(fnBusy)=="function"){fnBusy();} /*do something*/
var $opacityFadeOutTimer = $w.setTimeout(function(){start-=(steps); $opacityFadeOut(node,start,end,time,steps,fnFinish,fnBusy)},time);
}
else if(start<=end){
if(fnFinish&&typeof(fnFinish)=="function"){fnFinish();} /*do something*/
} };
17-09-2008US_functions Information
////////////////////////////////////////////////////////////////////////////
/** INFORMATION **/
// Get Navigator Information;
// syntax: Navigator.$browser(); // Browser name;
// Navigator.$version(); // Browser version;
// Navigator.$OS(); // Operating System;
// return: [String] given information;
_.Navigator = {
$browser: function(){
return this.searchString(this.dataBrowser) || "unknown";
},
$version: function(){
return this.searchVersion($uA) || this.searchVersion($n.appVersion) || "unknown";
},
$OS: function(){
return this.searchString(this.dataOS) || "unknown";
},
searchString: function(data){
for (var i=0;i < data.length;i++){
var dataString = data[i].str,
dataProp = data[i].prop;
this.versionSearchString = data[i].nr || data[i].id;
if(dataString) {
if(dataString.indexOf(data[i].sub)!=-1)
return data[i].id;
}
else if(dataProp){
return data[i].id;
} } },
searchVersion: function(dataString){
var index = dataString.indexOf(this.versionSearchString);
if(index==-1) return;
return /^[\d\.]*/.exec(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
str: $uA,
sub: "Chrome",
id: "Chrome"
},
{
str: $uA,
sub: "OmniWeb",
nr: "OmniWeb/",
id: "OmniWeb"
},
{
str: $n.vendor,
sub: "Apple",
id: "Safari"
},
{
prop: $w.opera,
id: "Opera"
},
{
str: $n.vendor,
sub: "iCab",
id: "iCab"
},
{
str: $n.vendor,
sub: "KDE",
id: "Konqueror"
},
{
str: $uA,
sub: "K-Meleon",
id: "K-Meleon"
},
{
str: $uA,
sub: "Firefox",
id: "Firefox"
},
{
str: $n.vendor,
sub: "Camino",
id: "Camino"
},
{ // for newer Netscapes (6+)
str: $uA,
sub: "Netscape",
id: "Netscape"
},
{
str: $uA,
sub: "MSIE",
id: "Explorer",
nr: "MSIE"
},
{
str: $uA,
sub: "Gecko",
id: "Mozilla",
nr: "rv"
},
{ // for older Netscapes (4-)
str: $uA,
sub: "Mozilla",
id: "Netscape",
nr: "Mozilla"
}
],
dataOS: [
{
str: $n.platform,
sub: "Win",
id: "Windows"
},
{
str: $n.platform,
sub: "Mac",
id: "Mac"
},
{
str: $n.platform,
sub: "Linux",
id: "Linux"
} ] };
// Get Program Measurement;
// syntax: Program.$width(); // Get Pogram Width;
// Program.$height(); // Get Pogram Height;
// return: [Integer][^Null] returns a integer or Null if not excist;
_.Program={
$width:function(){
var win=arguments[0]?arguments[0]:$w;
if(win.outerWidth){ // all except IE (no solution);
return win.outerWidth;
}
else return null;
},
$height:function(){
var win=arguments[0]?arguments[0]:$w;
if(win.outerHeight){ // all except IE (no solution); Opera excludes toolbars (no solution);
return win.outerHeight;
}
else return null;
} };
// Get Window Measurement;
// syntax: Window.$width(true); // Get Window Width Incl. Scrollbar;
// Window.$width(false); // Get Window Width Excl. Scrollbar;
// Window.$height(true); // Get Window Height Incl. Scrollbar;
// Window.$height(false); // Get Window Height Excl. Scrollbar;
// Window.$scrollbar.$width(); // Get Window SrcollBar Width;
// Window.$scrollbar.$height(); // Get Window SrcollBar Height;
// return: [Integer][^Null] returns a integer or Null if not excist;
// params: bar [Boolean] Includes/Excludes scrollbar (optioneel)(default: true);
// (document) specified document object;
// (window) specified window object;
_.Window={
IEscrollbar: [20,20], // width,height;
$width:function(bar){
var doc=arguments[1]?arguments[1]:$d,win=arguments[2]?arguments[2]:$w,ww=null;
if(bar===false){ // window width excl. scrollbar
if(doc.documentElement && doc.documentElement.clientWidth){ // all except IE5.5< ;
ww=doc.documentElement.clientWidth;
}
else if(doc.body && doc.body.clientWidth && (doc.body.clientWidth!=doc.body.scrollWidth)){
ww=doc.body.clientWidth;
}
}
else{ // window width incl. scrollbar
if(win.innerWidth){ // all except IE
ww=win.innerWidth;
}
else if(doc.documentElement && doc.documentElement.offsetWidth){
ww=doc.documentElement.offsetWidth;
}
if(Window.$width(false,doc,win) && ww && (ww-Window.$width(false,doc,win))<=0){ww=ww+Window.IEscrollbar[0];} // IE7 doctype on bug fix;
}
return ww;
},
$height:function(bar){
var doc=arguments[1]?arguments[1]:$d,win=arguments[2]?arguments[2]:$w,wh=null;
if(bar===false){ // window height excl. scrollbar
if(doc.body && doc.body.clientHeight){
wh=win.innerHeight; // bug for doc.body isnt long enought, didnt test it on outer browsers!
// wh=doc.body.clientHeight;
// if(win.innerHeight && wh>win.innerHeight){wh=doc.documentElement.clientHeight;} // FF doctype on bug fix;
// else if(doc.documentElement && doc.documentElement.clientHeight && wh>doc.documentElement.clientHeight){wh=doc.documentElement.clientHeight;} // IE7 & 6 doctype on bug fix;
}
}
else{ // window height incl. scrollbar
if(win.innerHeight){ // all except IE;
wh=win.innerHeight;
}
else if(doc.documentElement && doc.documentElement.offsetHeight){
wh=doc.documentElement.offsetHeight;
if(wh<=Window.$height(false,doc,win)){wh=wh+Window.IEscrollbar[1]}; // IE7 & 6 doctype on bug fix;
}
}
return wh;
},
$scrollbar:{
$width:function(){ // scrollbar width
var doc=arguments[0]?arguments[0]:$d,win=arguments[1]?arguments[1]:$w,wsw=null;
if(Window.$width(false,doc,win) && Window.$width(true,doc,win)){
wsw=(Window.$width(true,doc,win)-Window.$width(false,doc,win));
if(wsw < 0){wsw=Window.IEscrollbar[0];} // IE7 doctype on bug;
}
return wsw;
},
$height:function(){ // scrollbar height
var doc=arguments[0]?arguments[0]:$d,win=arguments[1]?arguments[1]:$w;
if(Window.$height(false,doc,win) && Window.$height(true,doc,win)){
return(Window.$height(true,doc,win)-Window.$height(false,doc,win));
}
else return null;
} } };
// Get Document Measurement;
// syntax: Document.$width(); // Get Document Width; Width of the whole document;
// Document.$height(); // Get Document Height; Height of the whole document;
// Document.$left(); // Get Document Left; From the left of the document to the left side of the current view;
// Document.$top(); // Get Document Top; From the top of the document to the top of the current view;
// Document.$right(); // Get Document Right; From the right of document to the right side of the current view;
// Document.$bottom(); // Get Document Bottom; From the bottom of document to the bottom of the current view;
// return: [Integer][^Null] returns a integer or Null if not excist;
// params: (document) specified document object;
// (window) specified window object;
_.Document={
$width:function(){ // document total width
var doc=arguments[0]?arguments[0]:$d,dw=null;
if(doc.documentElement && doc.documentElement.scrollWidth){
dw=doc.documentElement.scrollWidth;
if(doc.body.scrollWidth && doc.documentElement.scrollWidth==doc.documentElement.offsetWidth){dw=doc.body.scrollWidth;} // IE doctype off bug fix; FF doctype off bug fix;
}
else if(doc.body.scrollWidth){ // extra
dw=doc.body.scrollWidth;
}
return dw;
},
$height:function(){ // document total height
var doc=arguments[0]?arguments[0]:$d,dh=null;
if(doc.documentElement && doc.documentElement.scrollHeight){
dh=doc.documentElement.scrollHeight;
if(doc.body.scrollHeight && (dh==doc.documentElement.offsetHeight && dh==doc.body.offsetHeight)){ // IE doctype off bug fix;
dh=doc.body.scrollHeight;
}
}
else if(doc.body.scrollHeight){ // extra
dh=doc.body.scrollHeight;
}
return dh;
},
$left:function(){ // document scroll left
var doc=arguments[0]?arguments[0]:$d,dl=null;
if(doc.documentElement && (doc.documentElement.scrollLeft||doc.documentElement.scrollLeft==0)){
dl=doc.documentElement.scrollLeft;
if((doc.body.scrollLeft || doc.body.scrollLeft==0) && dl<=0){dl=doc.body.scrollLeft;} // FF2 doctype off bug fix; IE doctype off bug fix; IE5.5< doctype on bug fix;
}
else if(doc.body.scrollLeft || doc.body.scrollLeft==0){ // extra
dl=doc.body.scrollLeft;
}
return dl;
},
$top:function(){ // document scroll top
var doc=arguments[0]?arguments[0]:$d,dt=null;
if(doc.documentElement && doc.documentElement.scrollTop){
dt=doc.documentElement.scrollTop;
if((doc.body.scrollTop || doc.body.scrollTop==0) && dt<=0){dt=doc.body.scrollTop;}
}
else if(doc.body.scrollTop || doc.body.scrollTop==0){ // FF2 doctype off bug fix; IE doctype off bug fix; IE5.5< doctype on bug fix;
dt=doc.body.scrollTop;
}
return dt;
},
$right:function(){ // document scroll right
var doc=arguments[0]?arguments[0]:$d,win=arguments[1]?arguments[1]:$w;
if((Document.$width(doc)||Document.$width(doc)==0) && (Document.$left(doc)||Document.$left(doc)==0) && (Window.$width(false,doc,win)||Window.$width(false,doc,win)==0)){
return(Document.$width(doc)-Document.$left(doc)-Window.$width(false,doc,win));
}
else return null;
},
$bottom:function(){ // document scroll bottom
var doc=arguments[0]?arguments[0]:$d,win=arguments[1]?arguments[1]:$w;
if((Document.$height(doc)||Document.$height(doc)==0) && (Document.$top(doc)||Document.$top(doc)==0) && (Window.$height(false,doc,win)||Window.$height(false,doc,win)==0)){
return(Document.$height(doc)-Document.$top(doc)-Window.$height(false,doc,win));
}
else return null;
} };
// Detects Doctype (DTD);
// syntax: $detectDoctype();
// return: [Boolean and Object] boolean for existence and object doctype with specified info;
// doctype.registration [String or Null or false] string if excist, Null if not found, false if not excist;
// doctype.organization [String or Null or false] string if excist, Null if not found, false if not excist;
// doctype.label [String or Array or Null or false] string if excist, array if multiple, Null if not found, false if not excist;
// doctype.label.host [String or Array or Null or false] string if excist, array if multiple, Null if not found, false if not excist;
// doctype.label.version [String or Array or Null or false] string if excist, array if multiple, Null if not found, false if not excist;
// doctype.label.type [String or Array or Null or false] string if excist, array if multiple, Null if not found, false if not excist;
// doctype.language [String or Null or false] string if excist, Null if not found, false if not excist;
_.$detectDoctype = function(){
var regDTD = /\s*(.*)\/\/\s*(\w*)\/\/\s*(\w*)\s+(.*)\s*\/\/\s*(\w*)\s*/gi;
var regLabel = /(\w*)\s+([a-zA-Z]*)\s*([\d\.]*)\s*(\w*)/gi;
$w.doctype = {};
doctype.registration = null;
doctype.organization = null;
doctype.type = null;
doctype.label = [null];
doctype.label.host = null;
doctype.label.version = null;
doctype.label.type = null;
doctype.language = null;
if($d.doctype){
identifier = $d.doctype.publicId;
}
else{
return false;
}
if(typeof(identifier)=="string" && identifier.match(regDTD)){
doctype.registration = RegExp.$1?RegExp.$1:null;
doctype.organization = RegExp.$2?RegExp.$2:null;
doctype.type = RegExp.$3?RegExp.$3:null;
doctype.label = RegExp.$4?RegExp.$4:null;
doctype.language = RegExp.$5?RegExp.$5:null;
if(labels = doctype.label.split(/\s*plus\s*/)){
doctype.label = labels;
doctype.label.host = [];
doctype.label.version = [];
doctype.label.type = [];
for(var i=0; i < labels.length; i++){
labels[i].match(regLabel);
doctype.label.host.push(RegExp.$1?RegExp.$1:null);
doctype.label.version.push(RegExp.$3?RegExp.$3:null);
if(RegExp.$2){
doctype.label.type.push(RegExp.$2?RegExp.$2:null);
}
else{
doctype.label.type.push(RegExp.$4?RegExp.$4:null);
} } }
return true;
}
else{
doctype.registration = false;
doctype.organization = false;
doctype.type = false;
doctype.label = [false];
doctype.label.host = false;
doctype.label.version = false;
doctype.label.type = false;
doctype.language = false;
return false;
} };
17-09-2008US_functions Extra
////////////////////////////////////////////////////////////////////////////
/** EXTRA **/
// Add Event;
// syntax: $addEvent($gi("testDiv"),"click",function(){alert('hoi');});
// params: node [Node] refered element;
// type [String] event type without "on";
// fn [String or Function] function to execute;
// useCapture [Boolean] false=bubbling, true=capturing (default: false)(optional);
_.$addEvent = function(node,type,fn,useCapture){
if(node.addEventListener){
node.addEventListener(type,fn,useCapture);
}
else if(node.attachEvent){
node["e"+type+fn] = fn;
node[type+fn] = function(){node["e"+type+fn]($w.event);};
node.attachEvent("on"+type,node[type+fn]);
} };
// Remove Event;
// syntax: $removeEvent($gi("testDiv"),"click",function(){alert('hoi');});
// params: node [Node] refered element;
// type [String] event type without "on";
// fn [String or Function] function to execute;
// useCapture [Boolean] false=bubbling, true=capturing (default: false)(optional);
_.$removeEvent = function(node,type,fn,useCapture){
if(node.removeEventListener){
node.removeEventListener(type,fn,useCapture);
}
else if(node.detachEvent){
node.detachEvent("on"+type,node[type+fn]);
node[type+fn] = null;
node["e"+type+fn] = null;
} };
// Get Elements By Class Name;
// syntax: $getElementsByClassName(document,"class1");
// $getElementsByClassName($gi("testDiv"),"class1 class2","div");
// return: [NodeList][^empty Array] founded elements;
// params: node [Node] refered element;
// class [String] classname, seperated by space;
// tag [String] HTML element or "*" for all elements (default: all)(optional);
_.$getElementsByClassName = function(node,class,tag){
if($d.getElementsByClassName){
getElementsByClassName = function(node,class,tag){
var elems = node.getElementsByClassName(class),
nodeName = (tag) ? new RegExp("\\b" + tag + "\\b","i") : null,
returnElems = [],
cur;
for(var i=0; i < elems.length; i++){
cur = elems[i];
if(!nodeName || nodeName.test(cur.nodeName)){
returnElems.push(cur);
} }
return returnElems;
};
}
else if($d.evaluate){
getElementsByClassName = function(node,class,tag){
tag = tag || "*";
var classes = class.split(" "),
classes2Check = "",
xhtmlNamespace = "http://www.w3.org/1999/xhtml",
namespaceResolver = ($d.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null,
returnElems = [],
elems;
for(var j=0; j < classes.length; j++){
classes2Check += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
}
try{
elems = $d.evaluate(".//" + tag + classes2Check, node, namespaceResolver, 0, null);
}
catch(e){
elems = $d.evaluate(".//" + tag + classes2Check, node, null, 0, null);
}
while((node = elems.iterateNext())){
returnElems.push(node);
}
return returnElems;
};
}
else{
getElementsByClassName = function(node,class,tag){
tag = tag || "*";
var classes = class.split(" "),
classes2Check = [],
elems = (tag==="*" && node.all) ? node.all : node.getElementsByTagName(tag),
cur,
returnElems = [],
match;
for(var k=0; k < classes.length; k++){
classes2Check.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
}
for(var l=0; l < elems.length; l++){
cur = elems[l];
match = false;
for(var m=0; m < classes2Check.length; m++){
match = classes2Check[m].test(cur.class);
if(!match){
break;
} }
if(match){
returnElems.push(cur);
} }
return returnElems;
};
}
return getElementsByClassName(node,class,tag);
};
// Time/Date To Words;
// syntax: $timeDateWords(24*60*60*1000,new US_language({langMod:"en"})); // returns: "1 day";
// $timeDateWords(24*60*60*1000,new US_language({langMod:"en"}),true); // returns: "day";
// return: [String] number and time name;
// params: n [Integer] number to convert;
// lang [Object] object from US_language();
// shorten [Boolean] removes integer if it's 1 (default: false)(optional);
_.$timeDateWords = function(n,lang,shorten){
var shortn = shorten?shorten:false, word=false, l=lang, timeUnits = [
{name: l.localise(["tDW","millisecond"]), plural: l.localise(["tDW","milliseconds"]), min: 0, max: 1000},
{name: l.localise(["tDW","second"]), plural: l.localise(["tDW","secondes"]), min: 1000, max: 60*1000},
{name: l.localise(["tDW","minute"]), plural: l.localise(["tDW","minutes"]), min: 60*1000, max: 60*60*1000},
{name: l.localise(["tDW","hour"]), plural: l.localise(["tDW","hours"]), min: 60*60*1000, max: 24*60*60*1000},
{name: l.localise(["tDW","day"]), plural: l.localise(["tDW","days"]), min: 24*60*60*1000, max: 7*24*60*60*1000},
{name: l.localise(["tDW","week"]), plural: l.localise(["tDW","weeks"]), min: 7*24*60*60*1000, max: 365*24*60*60*1000},
{name: l.localise(["tDW","year"]), plural: l.localise(["tDW","years"]), min: 365*24*60*60*1000, max: Infinity}
];
for(var i=0, tU=null; tU=timeUnits[i]; i++){
if(n.between(tU.min,tU.max)){
var val = Math.floor(n / (tU.min!=0?tU.min:1));
word = (val!=(1 && shortn)?val+" ":"") + (val!=1?tU.plural:tU.name);
}
}
return word;
};
// Named Colors;
// syntax: $namedColors();
// return: [Array] all color names;
_.$namedColors = function(){
return new Array('AliceBlue','AntiqueWhite','Aqua','Aquamarine','Azure','Beige','Bisque','Black','BlanchedAlmond','Blue','BlueViolet','Brown','BurlyWood','CadetBlue','Chartreuse','Chocolate','Coral','CornflowerBlue','Cornsilk','Crimson','Cyan','DarkBlue','DarkCyan','DarkGoldenRod','DarkGray','DarkGreen','DarkKhaki','DarkMagenta','DarkOliveGreen','Darkorange','DarkOrchid','DarkRed','DarkSalmon','DarkSeaGreen','DarkSlateBlue','DarkSlateGray','DarkTurquoise','DarkViolet','DeepPink','DeepSkyBlue','DimGray','DodgerBlue','Feldspar','FireBrick','FloralWhite','ForestGreen','Fuchsia','Gainsboro','GhostWhite','Gold','GoldenRod','Gray','Grey','Green','GreenYellow','HoneyDew','HotPink','IndianRed','Indigo','Ivory','Khaki','Lavender','LavenderBlush','LawnGreen','LemonChiffon','LightBlue','LightCoral','LightCyan','LightGoldenRodYellow','LightGrey','LightGreen','LightPink','LightSalmon','LightSeaGreen','LightSkyBlue','LightSlateBlue','LightSlateGray','LightSteelBlue','LightYellow','Lime','LimeGreen','Linen',
'Magenta','Maroon','MediumAquaMarine','MediumBlue','MediumOrchid','MediumPurple','MediumSeaGreen','MediumSlateBlue','MediumSpringGreen','MediumTurquoise','MediumVioletRed','MidnightBlue','MintCream','MistyRose','Moccasin','NavajoWhite','Navy','OldLace','Olive','OliveDrab','Orange','OrangeRed','Orchid','PaleGoldenRod','PaleGreen','PaleTurquoise','PaleVioletRed','PapayaWhip','PeachPuff','Peru','Pink','Plum','PowderBlue','Purple','Red','RosyBrown','RoyalBlue','SaddleBrown','Salmon','SandyBrown','SeaGreen','SeaShell','Sienna','Silver','SkyBlue','SlateBlue','SlateGray','Snow','SpringGreen','SteelBlue','Tan','Teal','Thistle','Tomato','Turquoise','Violet','VioletRed','Wheat','White','WhiteSmoke','Yellow','YellowGreen',
/* system colors => */ 'ActiveBorder','ActiveCaption','AppWorkspace','Background','ButtonFace','ButtonHighlight','ButtonShadow','ButtonText','CaptionText','GrayText','Highlight','HighlightText','InactiveBorder','InactiveCaption','InactiveCaptionText','InfoBackground','InfoText','Menu','MenuText','Scrollbar','ThreeDDarkShadow','ThreeDFace','ThreeDHighlight','ThreeDLightShadow','ThreeDShadow','Window','WindowFrame','WindowText');
};
// Validates a input for a valid color;
// syntax: $validateColorInput([$gi("testDiv1"),$gi("testDiv2")],[$gi("testDiv3"),$gi("testDiv4")]);
// params: node [NodeList] value that needs to be checked;
// alternativeObj [NodeList] alternative objects that doesn't need to be checked and are valid (optional);
_.$validateColorInput = function(node,alternativeObj){
var colorField = node,
validateColorFalse = [],
v = 0;
var spaceRegExp = /\s+/g;
var colorRegExp1a = /^#?([a-fA-F0-9]){6,6}\s*$/; // e.g.: "#123456" / "123456" / "#123abc" / "123abc" / "#abcdef" / "abcdef" ( + hoofdletter ongevoelig)
var colorRegExp1b = /^#?([a-fA-F0-9]){3,3}\s*$/; // e.g.: "#123" / "123" / "#12a" / "12a" / "#abc" / "abc" ( + hoofdletter ongevoelig)
var colorRegExp2 = /^([a-zA-Z]){1}/; // e.g.: "red" / "Red"
var colorRegExp3 = /^#?([a-fA-F0-9]{1})([a-fA-F0-9]{1})([a-fA-F0-9]{1})\s*$/;
for(var f=0; f < colorField.length; f++){
colorField[f].value = colorField[f].value.replace(spaceRegExp,"");
if(colorRegExp1a.test(colorField[f].value)){
if(colorField[f].value.indexOf("#",0)){
colorField[f].value = "#" + colorField[f].value;
validateColorFalse[v] = f;
v++;
}
else{
colorField[f].value = colorField[f].value;
validateColorFalse[v] = f;
v++;
}
}
else if(colorRegExp1b.test(colorField[f].value)){
colorField[f].value = colorField[f].value.replace(colorRegExp3,"$1$1$2$2$3$3");
if(colorField[f].value.indexOf("#",0)){
colorField[f].value = "#" + colorField[f].value;
validateColorFalse[v] = f;
v++;
}
else{
colorField[f].value = colorField[f].value;
validateColorFalse[v] = f;
v++;
}
}
else if(colorRegExp2.test(colorField[f].value)){
if($namedColors().searchArray(colorField[f].value)){
colorField[f].value = colorField[f].value.charAt(0).toUpperCase() + colorField[f].value.substring(1,colorField[f].value.length).toLowerCase();
validateColorFalse[v] = f;
v++;
}
else colorField[f].value = colorField[f].value;
}
else{
colorField[f].value = colorField[f].value;
}
$sa(colorField[f],"style","background-image:" + $getStyle(colorField[f],"background-image") + ";background-repeat:no-repeat;background-position:right;" + "border-color: red;");
for(j=0;j < v;j++){
$sa(colorField[validateColorFalse[j]],"style","background-image:" + $getStyle(colorField[j],"background-image") + ";background-repeat:no-repeat;background-position:right;" + "border-color: green;");
}
}
for(var a=0; a < alternativeObj.length; a++){
$sa(alternativeObj[a],"style","background-image:" + $getStyle(alternativeObj[a],"background-image") + ";background-repeat:no-repeat;background-position:right;" + "border-color: green;");
}
// return false / true
if((colorField.length - v) > 0){return false;}
else return true;
};
// ???
function $x(xpath,root){
var doc = root ? root.evaluate ? root : root.ownerDocument : $d, next;
var got = doc.evaluate(xpath, root||doc, null, null, null), result = [];
while(next = got.iterateNext())
result.push(next);
return result;
};
// ???
function $xs(xpath,root){
var doc = root ? root.evaluate ? root : root.ownerDocument : $d, next;
return doc.evaluate(xpath, root||doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
};
// Is Integer;
// syntax: $isInt(-33,false); // returns: true;
// return: [Boolean] true if valid, else false;
// params: n [Integer or String] integer to check;
// way [Boolean] true=positive, false=negitive, nothing is both ways (default: both)(optional);
_.$isInt = function(n,way){
var exp;
if(way===true){ // positive
exp=/^[0-9]+$/;
}
else if(way===false){ // negative
exp=/^-[0-9]+$/;
}
else{ // both
exp=/^-?[0-9]+$/;
}
return exp.test(n.toString());
};
// Is Url;
// syntax: $isUrl("http://some.host"); // returns: true;
// return: [Boolean] true if valid, else false;
// params: str [String] url to check;
_.$isUrl = function(str){
if(str.indexOf(" ")!=-1){return false;}
else if(str.indexOf("http://")==-1){return false;}
else if(str=="http://"){return false;}
else if(str.indexOf("http://")>0){return false;}
str=str.substring(7,str.length);
if(str.indexOf(".")==-1){return false;}
else if(str.indexOf(".")==0){return false;}
else if(str.charAt(str.length-1)=="."){return false;}
if(str.indexOf("/")!=-1){
str=str.substring(0,str.indexOf("/"));
if(str.charAt(str.length-1)=="."){return false;}
}
if(str.indexOf(":")!=-1){
if(str.indexOf(":")==(str.length-1)){return false;}
else if(str.charAt(str.indexOf(":")+1)=="."){return false;}
str=str.substring(0,str.indexOf(":"));
if(str.charAt(str.length-1)=="."){return false;}
}
return true;
};
// Is Type Of;
// Checks if variable is that constructor;
// note: node must be a "window." object;
// node must be written as a string;
// syntax: isTypeOf("x0","undefined"); // returns: true;
// return: [Boolean] true if valid, else false;
// params: variable [String] variable to check;
// constructor [String] constructor (e.g.: number, string, boolean, object, function, date, regexp, null, undefined);
_.isTypeOf = function(variable,constructor){
return eval('(typeof('+variable+') == "'+constructor+'");');
};
// What Type Of;
// Returns the type of contructor;
// syntax: what.type.of(new Date); // returns: date;
// return: [String] constructor;
// params: node [Node] object to check;
_.what={
type:{
of:function(node){
for(var i in is){
if(is[i](node)){
return i.toLowerCase();
} } } } };
_.is={
Null:function(a){
return a===null;
},
Undefined:function(a){
return a===undefined;
},
nt:function(a){
return(a===null||a===undefined);
},
Function:function(a){
return(typeof(a)==='function')?a.constructor.toString().match(/Function/)!==null:false;
},
String:function(a){
return(typeof(a)==='string')?true:(typeof(a)==='object')?a.constructor.toString().match(/string/i)!==null:false;
},
Array:function(a){
return(typeof(a)==='object')?a.constructor.toString().match(/array/i)!==null||a.length!==undefined:false;
},
Boolean:function(a){
return(typeof(a)==='boolean')?true:(typeof(a)==='object')?a.constructor.toString().match(/boolean/i)!==null:false;
},
Date:function(a){
return(typeof(a)==='date')?true:(typeof(a)==='object')?a.constructor.toString().match(/date/i)!==null:false;
},
HTML:function(a){
return(typeof(a)==='object')?a.constructor.toString().match(/html/i)!==null:false;
},
Number:function(a){
return(typeof(a)==='number')?true:(typeof(a)==='object')?a.constructor.toString().match(/Number/)!==null:false;
},
Object:function(a){
return(typeof(a)==='object')?a.constructor.toString().match(/object/i)!==null:false;
},
RegExp:function(a){
return(typeof(a)==='function')?a.constructor.toString().match(/regexp/i)!==null:false;
} };
17-09-2008US_functions Userscript Functions
////////////////////////////////////////////////////////////////////////////
/** USERSCRIPT FUNCTIONS **/
// Sets a value;
// syntax: US_setValue("foo", "bar");
// params: name [string] name value;
// value [integer, boolean or string];
US_setValue = function(name,value){
if(GM_setValue){ // GM
return GM_setValue(name,value);
}
else if(PRO_setValue){ // IEpro
return PRO_setValue(name,value);
}
else{
// cookie
} };
// Gets a value;
// syntax: alert(US_getValue("foo"));
// return: [string] value;
// params: name [string] name value;
// def [integer, boolean or string] if no value return, this value is used (optional);
// todo: if undefined value returns true, but should be undefined!
US_getValue = function(name,def){
if(GM_getValue){ // GM
return GM_getValue(name,def);
}
else if(PRO_getValue){ // IEpro
return PRO_getValue(name);
}
else{
// cookie
} };
// Logging information;
// note: Since Firebug 1.0, extensions.firebug.showChromeMessages must be set to true for GM_log messages to show up in the Firebug console (Firefox only).
// If you aren't seeing your messages, make sure you navigate to about:config, and change the values of javascript.options.showInConsole and javascript.options.strict to true (Firefox only).
// syntax: Us_log("Hello World!");
// params: msg [object] logs any object;
US_log = function(msg){
if(GM_log){ // GM
return GM_log(msg);
}
else if(PRO_log){ // IEpro
return PRO_log(msg);
}
else{
// alert ($alert);
} };
// Opens url in new tab;
// syntax: US_openInTab("http://www.google.com/");
// params: url [string] valid url;
// flags [integer] 0 = curren tab / 1 = new tab / 2 = new tab in background (default: 2)(optional);
US_openInTab = function(url,flags){
if(GM_openInTab){ // GM
return GM_openInTab(url);
}
else if(PRO_openInTab){ // IEpro
return PRO_openInTab(url,flags);
}
else{
// window.open (can use flags also);
} };
// Adds CSS to the document;
// note: Add "!important" at the end of the code to override a existing value;
// syntax: US_addStyle("table.commandTable{width:100%;padding:5px;background-color:#3399FF;border:1px solid #0066CC}");
// params: css [string CSS] CSS;
// documentFrame ???
US_addStyle = function(css,documentFrame){
if(GM_addStyle){ // GM
return GM_addStyle(css);
}
else if(PRO_addStyle){ // IEpro
return PRO_addStyle(css,documentFrame);
}
else{
$addCSS(css);
} };
// Add command to menu with key-control;
// syntax: GM_registerMenuCommand("Hello, world!",command,"e","control shift alt","w");
// params: commandName [string] ???
// commandFunc [object function] ???
// accelKey ???
// accelModifiers ???
// accessKey ???
US_registerMenuCommand = function(commandName,commandFunc,accelKey,accelModifiers,accessKey){
if(GM_registerMenuCommand){ // GM
return GM_registerMenuCommand(commandName,commandFunc,accelKey,accelModifiers,accessKey);
}
else if(PRO_registerMenuCommand){ // IEpro
return PRO_registerMenuCommand(accelKey,commandFunc);
}
else{
// script only to use keycontrol to a command;
} };
///////don't know//////////////
// Show prompt;
// params: label [string] ???
// defValue [object] ???
US_prompt = function(label,defValue){
if(PRO_prompt){ // IEpro
return PRO_prompt(label,defValue);
}
else{
// prompt
} };
// ???
// return: [string] ???
PRO_documentText = function(){
if(PRO_documentText){ // IEpro
return PRO_documentText();
}
else{
// iets anders
} };
// Rounds borders;
// syntax: PRO_roundCorner('div.cl', {color:#FF0000, compact:true});
// PRO_roundCorner('#node', {color:#FF0000});
// PRO_roundCorner(node);
// params: node [object or string];
// options [object] (color is in #XXXXXX or #XXX format) (optional):
// corners ["all/top/bottom/tl/tr/bl/br"] (default: all);
// color ["fromElement/transparent/[color]"] (default: fromElement);
// bgColor ["fromParent/[color]"] (default: fromParent);
// blend [boolean] (default: true);
// border [color];
// compact [booelan] (default: false);
// document (optional);
PRO_roundCorner = function(node,options,document){
if(PRO_roundCorner){ // IEpro
return PRO_roundCorner(node,options,document);
}
else{
// externe script (moz-border-radius);
} };
// Get language;
// return: [string] e.g.: nld: Dutch;
PRO_getLang = function(){
if(PRO_getLang){ // IEpro
return PRO_getLang();
}
else{
// iets anders
} };
// ???
// return: ???
// params: sURL [string] url of document;
// vArguments ??? (optional);
// sFeatures ??? (optional);
PRO_showModalDialog = function(sURL,vArguments,sFeatures){
if(PRO_showModalDialog){ // IEpro
return PRO_showModalDialog(sURL,vArguments,sFeatures)
}
else{
// iets anders
} };
// ???
// return: ???
// params: sURL [string] url of document;
// vArguments ??? (optional);
// sFeatures ??? (optional);
PRO_showModelessDialog = function(sURL,vArguments,sFeatures){
if(PRO_showModelessDialog){ // IEpro
return PRO_showModelessDialog(sURL,vArguments,sFeatures)
}
else{
// iets anders
} };
// Loads external resource (text);
// note: Add a metadata block to make it working: "// @resource prototype http://www.example.com/prototype.js" (Firefox only).
// syntax: var myPrototype = GM_getResourceText("prototype");
// return: [string] ???;
// params: resourceName [string] resource name;
GM_getResourceText = function(resourceName){
if(GM_getResourceText){ // GM
return GM_getResourceText(resourceName);
}
else{
// iets anders
} };
// Loads external resource (image);
// note: Add a metadata block to make it working: "// @resource fooLogo http://www.example.com/logo.png" (Firefox only).
// syntax: var fooLogo = GM_getResourceURL("fooLogo");
// return: [string base64] ???;
// params: resourceName [string] resource name;
GM_getResourceURL = function(resourceName){
if(GM_getResourceURL){ // GM
return GM_getResourceURL(resourceName);
}
else{
// iets anders
} };
This text should not be seen and spoken.