UNPKG

utils4js

Version:

Various utility functions for JavaScript.

1 lines 7.1 kB
(function(){var a=(function(){function b(){}b.isInArray=function(c,d){return d.indexOf(c)>-1};b.sortByKey=function(e,c,d){Object.byString=function(l,j){j=j.replace(/\[(\w+)\]/g,".$1");j=j.replace(/^\./,"");var f=j.split("."),h,m,g;for(h=0,m=f.length;h<m;h+=1){g=f[h];if(l.hasOwnProperty(g)){l=l[g]}else{return}}return l};return e.sort(function(h,g){var f=Object.byString(h,c),i=Object.byString(g,c);if(d){return((f<i)?-1:((f>i)?1:0))}else{return((i<f)?-1:((i>f)?1:0))}})};b.isArray=function(c){return(!!c)&&(c.constructor===Array)};return b}());if(typeof window==="undefined"){module.exports=a}else{window.ArrayUtils=a}}());(function(){var a=(function(){function b(){}b.sendMessageToExtension=function(d,c){chrome.runtime.sendMessage(d,c)};b.sendMessageToActiveTabInCurrentWindow=function(d,c){chrome.tabs.query({active:true,currentWindow:true},function(e){chrome.tabs.sendMessage(e[0].id,d,c)})};b.createContextMenuItemThatSendsMessageToActiveTabInCurrentWindow=function(h,f,g,c,e,d){chrome.contextMenus.create({id:h,title:f,contexts:g,visible:c,onclick:function(){b.sendMessageToActiveTabInCurrentWindow(e,d)}})};b.openNewPage=function(c){chrome.tabs.create({url:c})};b.createContextMenuItemThatOpensNewPage=function(h,f,g,c,e,d){chrome.contextMenus.create({id:h,title:f,contexts:g,visible:c,onclick:function(){chrome.tabs.create({url:e})},documentUrlPatterns:d})};b.handleMessage=function(c){chrome.runtime.onMessage.addListener(function(d){c(d)})};b.checkIfTabWithIDExists=function(d,e,c){function f(){if(chrome.runtime.lastError){if(c){c(chrome.runtime.lastError.message)}}else{if(e){e()}}}chrome.tabs.get(d,f)};return b}());if(typeof window==="undefined"){module.exports=a}else{window.ChromiumUtils=a}}());(function(){var a=(function(){function b(){}b.copyText=function(f){var g=false,d,c,e;if(typeof window!=="undefined"){d=window.document.createElement("textarea");c=window.document.getElementsByTagName("body")[0];d.textContent=f;c.appendChild(d);d.select();g=window.document.execCommand("copy");if(g){c.removeChild(d)}else{e=window.open("about:blank");e.document.title="Press CTRL-C to copy the highlighted text/data.";e.document.body.appendChild(d);d.style.width="100%";d.style.height="100%";d.select();d.onkeydown=function(i){var h=67;if(i.ctrlKey&&i.keyCode===h){window.setTimeout(function(){e.close()},256);return true}}}}return g};return b}());if(typeof window==="undefined"){module.exports=a}else{window.ClipboardUtils=a}}());(function(){var a=(function(){function b(){}b.formatDateToYYYYMMDD=function(c,d){d=typeof d!=="undefined"?d:"/";return c.getFullYear()+d+(((c.getMonth()+1)<10)?"0":"")+(c.getMonth()+1)+d+((c.getDate()<10)?"0":"")+c.getDate()};return b}());if(typeof window==="undefined"){module.exports=a}else{window.DateUtils=a}}());(function(){var a=(function(){function b(){}b.getHTMLforDOMElement=function(d){var c=document.createElement("div");c.appendChild(d.cloneNode(true));return c.innerHTML};b.getHTMLforDOMElementById=function(c){var d=document.getElementById(c);return b.getHTMLforDOMElement(d)};b.removeAllChildElementsOfDOMNode=function(c){var d=document.getElementById(c);while(d.firstChild){d.removeChild(d.firstChild)}};return b}());if(typeof window==="undefined"){module.exports=a}else{window.HTMLUtils=a}}());(function(){var a=(function(){function b(){}b.createImageElement=function(f,d,e){var c=window.document.createElement("img");c.src=f;if(d!==null){c.alt=d}if(e!==null){c.title=e}return c};return b}());if(typeof window==="undefined"){module.exports=a}else{window.ImageUtils=a}}());(function(){var a=(function(){function b(){}b.parseFromURL=function(c,e){var d=new XMLHttpRequest();d.onreadystatechange=function(){if(this.readyState===4&&this.status===200){var f=d.responseText,g=JSON.parse(f);e(g)}};d.open("GET",c,true);d.send()};return b}());if(typeof window==="undefined"){module.exports=a}else{window.JSONUtils=a}}());(function(){var a=(function(){function b(){}b.extractStringUsingJavaScriptRegEx=function(d,e){var c=d.match(e)||[""];return c[0]};return b}());if(typeof window==="undefined"){module.exports=a}else{window.RegExUtils=a}}());(function(){var a=(function(){function b(){}b.equals=function(d,c){return d.localeCompare(c)===0};return b}());if(typeof window==="undefined"){module.exports=a}else{window.StringUtils=a}}());(function(){var a=(function(){function b(){}b.createTableInPlaceHolder=function(f,g,e,j,c){var i=document.createElement("table"),d=document.createElement("tbody"),h=document.getElementById(f);i.style.width=typeof g!=="undefined"?g:"100%";i.setAttribute("border",typeof e!=="undefined"?e:"1");i.setAttribute("bordercolor",typeof j!=="undefined"?j:"LightSlateGray");i.style.borderCollapse=typeof c!=="undefined"?c:"collapse";i.appendChild(d);while(h.firstChild){h.removeChild(h.firstChild)}h.appendChild(i);return i};b.createRowWithCellValuesInTable=function(e,c){var f=document.createElement("tr"),d=e.tBodies[0];c.map(function(g){b.createCellWithContentInRow(f,g)});d.appendChild(f);return f};b.createRowWithCellsInTable=function(e,d){var f=document.createElement("tr"),c=e.tBodies[0];d.map(function(g){f.appendChild(g)});c.appendChild(f);return f};b.createCellWithContent=function(g,c,d){var f=document.createElement("td"),e=document.createElement("div");if(typeof g!=="undefined"){e.innerHTML=g}if(typeof c!=="undefined"){e.setAttribute("class",c)}if(d!==null){f.colSpan=d}f.appendChild(e);return f};b.createCellWithContentInRow=function(e,g,c,d){var f=b.createCellWithContent(g,c,d);e.appendChild(f);return f};return b}());if(typeof window==="undefined"){module.exports=a}else{window.TableUtils=a}}());(function(){var a=(function(){function b(){}b.runCodeEveryMinute=function(c,d){var e=60*1000,f=setInterval(function(){d(f)},e*c);d(f);return f};return b}());if(typeof window==="undefined"){module.exports=a}else{window.TimerUtils=a}}());(function(){var a=(function(){function b(){}b.parseFromURL=function(c,e){var d=new XMLHttpRequest();d.onreadystatechange=function(){if(this.readyState===4&&this.status===200){var g=d.responseText,f;if(typeof window.DOMParser!=="undefined"){f=(new window.DOMParser()).parseFromString(g,"text/xml")}else{throw new Error("No XML parser found")}e(f)}};d.open("GET",c,true);d.send()};b.isTagExists=function(c,d){return c.getElementsByTagName(d).length>0};return b}());if(typeof window==="undefined"){module.exports=a}else{window.XMLUtils=a}}());var Utils={};if(typeof window==="undefined"){Utils.Chromium=require("./chromium");Utils.Clipboard=require("./clipboard");Utils.Timer=require("./timer");Utils.Array=require("./array");Utils.String=require("./string");Utils.RegEx=require("./regex");Utils.HTML=require("./html");Utils.Image=require("./image");Utils.Table=require("./table");Utils.JSON=require("./json");Utils.XML=require("./xml")}else{Utils.Chromium=window.ChromiumUtils;Utils.Clipboard=window.ClipboardUtils;Utils.Timer=window.TimerUtils;Utils.Array=window.ArrayUtils;Utils.String=window.StringUtils;Utils.RegEx=window.RegExUtils;Utils.HTML=window.HTMLUtils;Utils.Image=window.ImageUtils;Utils.Table=window.TableUtils;Utils.JSON=window.JSONUtils;Utils.XML=window.XMLUtils};