My Function library

enter something useful

目前为 2017-09-23 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/9160/219970/My%20Function%20library.js

  1. /**
  2. * Created by Magnus Fohlström on 2016-09-24 at 22:56
  3. * with file name
  4. * in project TampermonkeyUserscripts.
  5. */
  6. "use strict";
  7. //// ==UserScript==
  8. // @name My Function library
  9. // @namespace http://use.i.E.your.homepage/
  10. // @version 0.52
  11. // @description enter something useful
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_deleteValue
  15. // @grant GM_listValues
  16. // @grant GM_xmlhttpRequest
  17. // @run-at document-start
  18.  
  19. // @created 2015-04-06
  20. // @released 2014-00-00
  21. // @updated 2014-00-00
  22. // @history @version 0.25 - first version: public@released - 2015-04-12
  23. // @history @version 0.30 - Second version: public@released - 2015-12-10
  24. // @history @version 0.35 - Second version: public@released - 2016-03-04
  25. // @history @version 0.45 - Second version: public@released - 2016-09-24
  26. // @history @version 0.45 - third version: public@released - 2017-01-10
  27. // @history @version 0.51 - third version: public@released - 2017-08-17
  28. // @history @version 0.52 - third version: public@released - 2017-09-23
  29.  
  30. // @compatible Greasemonkey, Tampermonkey
  31. // @license GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
  32. // @copyright 2014+, Magnus Fohlström
  33. // ==/UserScript==
  34. /*global $, jQuery*/
  35. /*jshint -W014, -W030, -W082*/
  36. // -W014, laxbreak, Bad line breaking before '+'
  37. // -W030, Expected assignment or function call instead saw an expression
  38. // -W082, a function declaration inside a block statement
  39.  
  40. /*
  41. $("li").not(function() {
  42. // returns true for those elements with at least one span as child element
  43. return $(this).children('span').length > 0
  44. }).each(function() { /* ... })
  45. */
  46. //noinspection JSUnresolvedFunction,JSUnresolvedVariable,BadExpressionStatementJS,JSPotentiallyInvalidConstructorUsage, JSPrimitiveTypeWrapperUsage
  47. //noinspection BadExpressionStatementJS,JSUnresolvedVariable,JSDeprecatedSymbols
  48. performance;
  49.  
  50. function setGM(window2) {
  51. window2 = window2 || window;
  52. console.log('setGM' );
  53. var localStorage = localStorage;
  54. window2.GM_getValue = function( key, def ){
  55. return localStorage[key] || def;
  56. };
  57. window2.GM_setValue = function( key, value ){
  58. localStorage[key] = value;
  59. };
  60. window2.GM_deleteValue = function( key ){
  61. delete localStorage[ key ];
  62. };
  63. window2.GM_listValues = function( ){
  64. return Object.keys( localStorage );
  65. };
  66. window2.GM_lister = function( remove, item ){
  67. var keys = GM_listValues(), i = 0, val;
  68. for ( i; i <= keys.length; i++ ) {
  69. val = keys[i];
  70. //noinspection JSUnresolvedVariable
  71. val !== undefined && (
  72. console.log( 'GM_ListItem: ' + val + ':', GM_getValue( val ) ),
  73. ( ( item !== undefined && val.inElem( item ) ) || item === undefined )
  74. && Boolean.parse( remove ) && GM_deleteValue( val ) );
  75. }
  76. };
  77. }
  78.  
  79. console.log('isFunction( GM_getValue() )', $.isFunction( window.GM_getValue ) );
  80.  
  81. !!$.isFunction( window.GM_getValue ) || setGM();
  82.  
  83. (function(){
  84.  
  85. var eventMatchers = {
  86. 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
  87. 'MouseEvents': /^(?:click|mouse(?:down|up|over|move|enter|out))$/
  88. //'MouseEvents': /^(?:click|dblclick|hover|contextmenu|mouse(?:down|up|over|move|enter|leave|out))$/
  89. };
  90.  
  91. var defaultOptions = {
  92. pointerX: 0,
  93. pointerY: 0,
  94. button: 0,
  95. ctrlKey: false,
  96. altKey: false,
  97. shiftKey: false,
  98. metaKey: false,
  99. bubbles: true,
  100. cancelable: true
  101. };
  102.  
  103. jQuery.fn.simulate = function(eventName) {
  104. var element = this[0];
  105. var options = $.extend(true, defaultOptions, arguments[2] || { });
  106. var oEvent, eventType = null;
  107.  
  108. for (var name in eventMatchers) {
  109. if (eventMatchers[name].test(eventName)) { eventType = name; break; }
  110. }
  111.  
  112. if (!eventType)
  113. throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
  114. //noinspection JSUnresolvedVariable
  115. if (document.createEvent) {
  116. //noinspection JSUnresolvedFunction
  117. oEvent = document.createEvent(eventType);
  118. if (eventType == 'HTMLEvents') {
  119. oEvent.initEvent(eventName, options.bubbles, options.cancelable);
  120. }
  121. else {
  122. //noinspection JSDeprecatedSymbols,noinspection JSUnresolvedVariable
  123. oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
  124. options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
  125. options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
  126. }
  127. element.dispatchEvent(oEvent);
  128. }
  129. else {
  130. options.clientX = options.pointerX;
  131. options.clientY = options.pointerY;
  132. //noinspection JSUnresolvedFunction
  133. oEvent = $.extend(document.createEventObject(), options);
  134. element.fireEvent('on' + eventName, oEvent);
  135. }
  136. return element;
  137. };
  138. })();
  139.  
  140. /*window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
  141. console.debug('Error: ' + errorMsg + '\nScript: ' + url + '\nLine: ' + lineNumber
  142. + '\nColumn: ' + column + '\nStackTrace: ' + errorObj);
  143. };*/
  144. /**
  145. * @namespace waitUntilExists_Intervals
  146. */
  147. $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild){
  148. var found = 'found',
  149. $this = $(this.selector),
  150. $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true);
  151. if( !isChild ) {
  152. (window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {})[this.selector] =
  153. window.setInterval(function () {
  154. $this.waitUntilExists(
  155. handler, shouldRunHandlerOnce, true);
  156. }, 500);
  157. }
  158. else if (shouldRunHandlerOnce && $elements.length){
  159. window.clearInterval(window.waitUntilExists_Intervals[this.selector]);
  160. }
  161. return $this;
  162. };
  163.  
  164. $.extend( $.easing,{
  165. easeOutBounceSmall : function(x, t, b, c, d) {
  166. var ts=(t/=d)*t;
  167. var tc=ts*t;
  168. return b+c*(-16.195*tc*ts + 49.935*ts*ts + -53.785*tc + 21.795*ts + -0.75*t);
  169. },
  170. easeOutSmoothBounce : function(x, t, b, c, d) {
  171. var ts=(t/=d)*t;
  172. var tc=ts*t;
  173. return b+c*(-19.4293*tc*ts + 53.3838*ts*ts + -49.8485*tc + 15.8081*ts + 1.08586*t);
  174. },
  175. easeInOutCubic : function(x, t, b, c, d) {
  176. if ((t/=d/2) < 1) return c/2*t*t*t + b;
  177. return c/2*((t-=2)*t*t + 2) + b;
  178. }
  179. });
  180. $.extend( $.fn, {
  181. // Name of our method & one argument (the parent selector)
  182. /**
  183. * Suppress all rules containing "unused" in this
  184. * class
  185. *
  186. * @SuppressWarnings("unused")
  187. */
  188. //noinspection JSUnusedProperty
  189. isNode : function ( node ) {
  190. var e = this[0] || $('<undefined/>'),
  191. node_name = e.nodeName;
  192. return node_name !== undefined && e.nodeName.toLowerCase() === node.toLowerCase();
  193. }
  194. });
  195.  
  196. $.extend( $.fn, {
  197. // Name of our method & one argument (the parent selector)
  198. /**
  199. * Suppress all rules containing "unused" in this
  200. * class
  201. *
  202. * @SuppressWarnings("unused")
  203. */
  204. //noinspection JSUnusedProperty
  205. within: function( pSelector ) {
  206. // Returns a subset of items using jQuery.filter
  207. return this.filter(function(){
  208. // Return truthy/falsey based on presence in parent
  209. return $(this).closest( pSelector ).length;
  210. });
  211. /* Example
  212. $("li").within(".x").css("background", "red");
  213.  
  214. This selects all list items on the document, and then filters to only
  215. those that have .x as an ancestor. Because this uses jQuery internally,
  216. you could pass in a more complicated selector:
  217.  
  218. $("li").within(".x, .y").css("background", "red");
  219.  
  220. http://stackoverflow.com/questions/2389540/jquery-hasparent
  221. http://stackoverflow.com/a/2389549
  222. */
  223. }
  224. });
  225.  
  226. $.fn.extend({
  227. exists : function () {
  228. return !!this.length;
  229. },
  230. Exists : function ( callback ) {
  231. var self = this;
  232. var wrapper = (function(){
  233. function notExists(){}
  234. //noinspection JSPotentiallyInvalidConstructorUsage
  235. notExists.prototype.ExistsNot = function( fallback ){
  236. !self.length && fallback.call(); };
  237. //noinspection JSPotentiallyInvalidConstructorUsage
  238. return new notExists;
  239. })();
  240. self.length && callback.call();
  241. return wrapper;
  242.  
  243. /* And now i can write code like this -
  244. $("#elem").Exists(function(){
  245. alert ("it exists");
  246. }).ExistsNot(function(){
  247. alert ("it doesn't exist");
  248. });
  249. */
  250. },
  251. ifExists : function ( fn ) {
  252. this.length && fn( this );
  253. return this.length && this;
  254. /*
  255. $("#element").ifExists( function( $this ){
  256. $this.addClass('someClass').animate({marginTop:20},function(){alert('ok')});
  257. });
  258. */
  259. },
  260. iff : function ( bool, fn ) {
  261. ( bool && this.length || !bool && !this.length) && fn( this );
  262. return ( bool && this.length || !bool && !this.length ) && this;
  263. /*
  264. $("#element").if( true, function( $this ){);
  265. $("#element").if( false, function( $this ){);
  266. */
  267. },
  268. ifs : function ( fnTrue, fnFalse ) {
  269. fn( this.length ? fnTrue : fnFalse );
  270. /*
  271. $("#element").ifs( function( $this ){}, function( $this ){});
  272. */
  273. },
  274.  
  275. hasId : function ( id ) {
  276. return id === this.attr('id');
  277. },
  278. hasClasses : function ( classes, any ) {
  279. classes = classes.split( classes.inElem(',') ? ',' : ' ' );
  280. var check = 0, i = 0;
  281. for ( i; i < classes.length; i++ ) {
  282. this.hasClass( classes[ i ] ) && check++;
  283. if ( any !== undefined && check !== 0 ) return true;
  284. }
  285. return check === classes.length;
  286. },
  287. hasClassLongerThan : function ( length, addClass ) {
  288. var str = $( this ).addClass('å').attr('class'),
  289. classes = str.split( ' ' ),
  290. check = 0, i = 0;
  291.  
  292. for ( i; i < classes.length; i++ ) {
  293. check = classes[ i ].length >= length ? check++ : check;
  294. classes[ i ].length >= length && $( this ).addClass( addClass );
  295. $( this ).removeClass('å');
  296. }
  297. return check;
  298. },
  299. hasIdLongerThan : function ( length, addClass ) {
  300. var str = $( this ).hasAttr('id') ? $( this ).attr('id') : ' ', check = 0;
  301. check = str.length >= length ? check++ : check;
  302.  
  303. str.length >= length && $( this ).addClass( addClass );
  304.  
  305. return check;
  306. },
  307. hasAttrLength : function ( attar, length, addClass ) {
  308. var str = $( this ).attr( attar ),
  309. attribs = str.attr( attar, $( this ).attr( attar ) + ' ' ).split( ' ' ),
  310. check = 0, i = 0;
  311.  
  312. for ( i; i < attribs.length; i++ ) {
  313. check = attribs[ i ].length >= length ? check++ : check;
  314. //attribs[ i ].length >= length
  315. check && $( this ).addClass( addClass );
  316. }
  317. return check;
  318. },
  319. hasSiblings : function ( find ) {
  320. return !!$(this).siblings( find ).length;
  321. },
  322. hasChildren : function () {
  323. return $(this).children().length !== 0;
  324. },
  325. hasNoChildren : function ( selection ) {
  326. return $( this ).filter( function(){
  327. return $( this ).children( selection ).length === 0;
  328. });
  329. },
  330. /* hasParent : function( parentSelection ){
  331. return parentSelection.inElem('#')
  332. ? this.parent().hasId( parentSelection.split('#').shift() )
  333. : this.parent().hasClass( parentSelection.split('.').shift() );
  334. },
  335. */
  336. hasAncestor : function ( Ancestor ) {
  337. return this.filter(function() {
  338. return !!$( this ).closest( Ancestor ).length;
  339. });
  340. //$('.element').hasAncestor('.container').myAction();
  341. },
  342. hasParent : function ( selection ) {
  343. return !!$( this ).parent( selection ).length;
  344. },
  345. hasParents : function ( selection ) {
  346. return !!$( this ).parents( selection ).length;
  347. },
  348. hasQuery : function ( query ) {
  349. return document.querySelector(query).length;
  350. },
  351. hasAttr : function ( name, val ) {
  352. var thisAttr = $( this ).attr( name );
  353. thisAttr =
  354. val !== undefined
  355. ? thisAttr === val
  356. : thisAttr;
  357. return ( typeof thisAttr !== "undefined" && thisAttr !== false && thisAttr !== null );
  358.  
  359. //return val !== undefined
  360. // ? attrName === val
  361. // : typeof( attrName ) !== 'undefined'; //$( this )[0].hasAttribute( name );
  362. },
  363. getThisAttr : function ( destinationObj ) {
  364. var that = this,
  365. allAttributes = ($(that) && $(that).length > 0) ? $(that).prop("attributes") : null;
  366.  
  367. allAttributes && $(destinationObj) && $(destinationObj).length == 1 &&
  368. $.each(allAttributes, function() {
  369. this.name == "class" ? $(destinationObj).addClass(this.value) : destinationObj.attr(this.name, this.value);
  370. });
  371.  
  372. return destinationObj !== undefined && $(destinationObj).length == 1 ? $(destinationObj) : allAttributes;
  373. },
  374. getAttrFrom : function ( sourceObj ) {
  375. var that = this,
  376. allAttributes = ($(sourceObj) && $(sourceObj).length > 0) ? $(sourceObj).prop("attributes") : null;
  377.  
  378. allAttributes && $(that) && $(that).length == 1 &&
  379. $.each(allAttributes, function() {
  380. this.name == "class" ? $(that).addClass(this.value) : that.attr(this.name, this.value);
  381. });
  382.  
  383. return that;
  384. },
  385. isTag : function ( tag ) {
  386. var e = this[0] || $('<undefined/>'),
  387. nodename = e.nodeName;
  388. return nodename !== undefined && e.nodeName.toLowerCase() === tag.toLowerCase();
  389. },
  390. isNode : function ( node ) {
  391. var e = this[0] || $('<undefined/>'),
  392. nodename = e.nodeName;
  393. return nodename !== undefined && e.nodeName.toLowerCase() === node.toLowerCase();
  394. },
  395.  
  396. swapClass : function ( replace, newClass) {
  397. this.className.replace(replace, newClass);
  398. },
  399. toggleClasses : function ( add, remove, if_none) {
  400. var $this = $(this.selector);
  401. if_none !== undefined && !$this.hasClass(add) && !$this.hasClass(remove) && $this.addClass(if_none);
  402. $this.addClass(add).removeClass(remove);
  403. },
  404. searchAttr : function ( search, type, chkLen ) { //bool name value length or 1 2 3 4
  405. var Attributes = this[0].attributes;
  406.  
  407. if ( arguments.length === 0 ) {
  408. var obj = {};
  409. $.each( Attributes, function() {
  410. this.specified && ( obj[ this.name ] = this.value );
  411. });
  412. return obj;
  413. } else if( search != undefined ) {
  414. var name = '', val = '';
  415. $.each( Attributes, function() {
  416. if( this.specified && type == 'length' ) {
  417. if( this.name.length > chkLen ) {
  418. name = this.name;
  419. c.i('Attributes', Attributes);
  420. return false;
  421. }
  422. }
  423. else {
  424. if( this.specified && this.name.inElem( search ) ) {
  425. name = this.name;
  426. val = this.value;
  427. return false;
  428. }
  429. }
  430. });
  431. return ( type == 'bool' || type == 1 ) ? name.length :
  432. ( type == 'name' || type == 2 ) ? name :
  433. ( type == 'value' || type == 3 ) ? val :
  434. ( type == 'length' || type == 4 ) && name;
  435. }
  436. },
  437. findClass : function ( Class ) {
  438. return this.find('.' + Class);
  439. },
  440. findNextSibling : function ( thisSelector, bool ) {
  441. bool = bool || true;
  442. return bool ? this.eq(0).nextAll( thisSelector ).eq(0) : this.nextAll( thisSelector ).eq(0) ;
  443. },
  444. findPrevSibling : function ( thisSelector, bool ) {
  445. bool = bool || true;
  446. return bool ? this.eq(0).prevAll( thisSelector ).eq(0) : this.prevAll( thisSelector ).eq(0) ;
  447. },
  448. nthChildClass : function(expr) {
  449. return this.filter(':nth-child('+ expr +')');
  450. },
  451.  
  452. href : function ( newURL ) {
  453. return arguments.length === 0 ? this.attr('href') : this.attr('href', newURL);
  454. },
  455. src : function ( newSRC ) {
  456. return arguments.length === 0 ? this.attr('src') : this.attr('src', newSRC);
  457. },
  458. refreshElement : function ( speed, parentBoolean ) {
  459. var $elem = parentBoolean ? this.parent() : this, data = $elem.html();
  460. $elem.hide( speed / 2 ).empty().html( data ).fadeIn( speed );
  461. },
  462. replaceElementOld : function ( newTagName, addAttr ) {
  463.  
  464. function stringifyAttr( attrs ){
  465. var attrString = '', newAttr = addAttr || '';
  466. $.each( attrs, function( index ){
  467. attrString += ' ' + attrs[ index ].name + '="' + attrs[ index ].value + '"';
  468. });
  469. return newAttr.length ? attrString + ' ' + newAttr : attrString;
  470. }
  471.  
  472. $( this ).each(function(){
  473. var attributes = stringifyAttr( this.attributes ),
  474. StartTag = '<' + newTagName + attributes +'>',
  475. EndTag = '</' + newTagName + '>';
  476. $( this ).replaceWith( StartTag + $( this ).html() + EndTag );
  477. });
  478. },
  479. replaceElement : function ( newNodeName, htmlElement ) {
  480.  
  481. newNodeName = $('<'+ newNodeName +'/>');
  482. htmlElement = htmlElement !== undefined ? htmlElement : $('<span/>',{ 'data-tmp':'TemparyAttribute'});
  483.  
  484. function newElem_addAttr( attrs, newAttr, newElem ){
  485. $.each( attrs, function( index ){
  486. newElem.attr( attrs[ index ].name, attrs[ index ].value ); });
  487. $.each( newAttr, function( index ){
  488. newElem.attr( newAttr[ index ].name, newAttr[ index ].value ); });
  489. return newElem;
  490. }
  491.  
  492. $( this ).each(function(){
  493. $( this ).replaceWith( newElem_addAttr(
  494. this.attributes, htmlElement[0].attributes, newNodeName ).html( $( this ).html() ).removeAttr('data-tmp') );
  495. });
  496.  
  497. return this;
  498. },
  499. equals : function ( compareTo ) {
  500. if (!compareTo || this.length != compareTo.length)
  501. return false;
  502.  
  503. for (var i = 0; i < this.length; ++i) {
  504. if (this[i] !== compareTo[i])
  505. return false;
  506. }
  507. return true;
  508. },
  509.  
  510. cleaner : function () {
  511. $( this ).contents().filter(function () {
  512. return this.nodeType !== 1 && this.nodeType !== 3 && this.nodeType !== 10;
  513. }).remove();
  514. return this;
  515. },
  516.  
  517. defragText : function (){
  518. this.nodeType === 3 && this.normalize();
  519. return this;
  520. },
  521. removeText : function () {
  522. $( this ).contents().filter(function () {
  523. return this.nodeType === 3;
  524. }).remove();
  525. return this;
  526. },
  527. selectText : function(){
  528.  
  529. var range,
  530. selection,
  531. obj = this[0],
  532. type = {
  533. func:'function',
  534. obj:'object'
  535. },
  536. // Convenience
  537. is = function(type, o){
  538. return typeof o === type;
  539. };
  540.  
  541. if( is(type.obj, obj.ownerDocument)
  542. && is(type.obj, obj.ownerDocument.defaultView)
  543. && is(type.func, obj.ownerDocument.defaultView.getSelection) ){
  544.  
  545. selection = obj.ownerDocument.defaultView.getSelection();
  546.  
  547. if( is(type.func, selection.setBaseAndExtent) ){
  548. // Chrome, Safari - nice and easy
  549. selection.setBaseAndExtent(obj, 0, obj, $(obj).contents().size());
  550. }
  551. else if( is(type.func, obj.ownerDocument.createRange) ){
  552.  
  553. range = obj.ownerDocument.createRange();
  554.  
  555. if( is(type.func, range.selectNodeContents)
  556. && is(type.func, selection.removeAllRanges)
  557. && is(type.func, selection.addRange)){
  558. // Mozilla
  559. range.selectNodeContents(obj);
  560. selection.removeAllRanges();
  561. selection.addRange(range);
  562. }
  563. }
  564. }
  565. else if( is(type.obj, document.body) && is(type.obj, document.body.createTextRange) ){
  566.  
  567. range = document.body.createTextRange();
  568.  
  569. if( is(type.obj, range.moveToElementText) && is(type.obj, range.select) ){
  570. // IE most likely
  571. range.moveToElementText(obj);
  572. range.select();
  573. }
  574. }
  575.  
  576. // Chainable
  577. return this;
  578. },
  579. selectThisText : function(){
  580. var doc = document
  581. , element = this[0]
  582. , range, selection
  583. ;
  584. if (doc.body.createTextRange) {
  585. range = document.body.createTextRange();
  586. range.moveToElementText(element);
  587. range.select();
  588. } else if (window.getSelection) {
  589. selection = window.getSelection();
  590. range = document.createRange();
  591. range.selectNodeContents(element);
  592. selection.removeAllRanges();
  593. selection.addRange(range);
  594. }
  595. return this;
  596. },
  597. justText : function ( newText, prepend ) {
  598. var $children = null,
  599. placement = prepend === undefined ? 'prepend':'append';
  600. if ( newText ) {
  601. $children = $( this )
  602. .children()
  603. .clone();
  604. $( this )
  605. .children()
  606. .remove()
  607. .end()
  608. .text( newText )
  609. [ placement ]( $children );
  610. return $(this);
  611. }
  612. else {
  613. return $.trim( $( this )
  614. .clone()
  615. .children()
  616. .remove()
  617. .end()
  618. .text());
  619. }
  620. },
  621. justThisText : function () {
  622. var array = [];
  623. this.contents().each(function(){
  624. this.nodeType == 3 && array.push( this.textContent || this.innerText || '' ); });
  625. return array;
  626. },
  627. toComment : function ( textNode ) {
  628. textNode = textNode || false;
  629. var $this = $( this ),
  630. comment = function( elem ){
  631. return document.createComment( !textNode ? elem.get(0).outerHTML : elem );
  632. };
  633.  
  634. textNode !== undefined && textNode
  635. ? $this.contents().filter(function(){ return this.nodeType === 3; })
  636. .each(function(){ $( this ).replaceWith( comment( this.nodeValue ) ); })
  637. : $this.replaceWith( comment( $this ) );
  638. },
  639. uncomment : function ( recurse ) {
  640. <!-- hidden --> // this will reveal, whats inside. In this case it will bi the word hidden
  641. recurse = recurse || false;
  642. $( this ).contents().each(function(){
  643. this.nodeType === 8 && $( this ).replaceWith( this.nodeValue ); });
  644.  
  645. recurse && $( this ).hasChildren()
  646. && $( this ).find('> *').not('iframe').uncomment( recurse );
  647.  
  648. /*
  649. $( this ).contents().each(function() {
  650. if ( recurse && this.hasChildNodes() ) {
  651. $( this ).uncomment(recurse);
  652. } else {
  653. if ( this.nodeType == 8 ) {
  654. // Need to "evaluate" the HTML content,
  655. // otherwise simple text won't replace
  656. var e = $('<span>' + this.nodeValue + '</span>');
  657. $( this ).replaceWith( e.contents() );
  658. }
  659. }
  660. });
  661. */
  662. // $('#uncomment').uncomment( true );
  663. // http://stackoverflow.com/a/22439787
  664. },
  665.  
  666. getComment : function ( getValue ) {
  667. var COMMENT_NODE = this.contents().filter(function(){
  668. return this.nodeType == Node.COMMENT_NODE;
  669. });
  670. return getValue
  671. ? COMMENT_NODE.each(function(){
  672. return $( this ).nodeValue.str2html(); })
  673. : COMMENT_NODE;
  674. },
  675. getURL : function ( url, how ) {
  676. //$.get('defaultComp/foot.html', function(dataContent) {$('#foot').replaceWith(dataContent); });
  677. how = how || 'html';
  678. var that = this;
  679. $.get( url, function(dataContent) {
  680. $(that)[ how ](dataContent);
  681. });
  682. return this;
  683. },
  684.  
  685. scrollTuneAdv : function ( opt ){
  686. // $("body").scrollTune({ pps: 1700, pageY: config.pageY, easing:'easeOutSmoothBounce', hsc: true }).promise()
  687. // .done( function() { setTimeout(function(){ toggleClassState( config, 'fullPlayer', type ); },100); })
  688. console.log('scrollTune');
  689.  
  690. var position,
  691. defaults = {
  692. tune: 0,
  693. speed: 0,
  694. pps: false, // pixel per second
  695. ppsM: 1000,
  696. pageYmini: 0,
  697. pageY: false, //{ pps: 300, pageY: event.pageY }
  698. hsc: false, // height speed compensation
  699. animate: false,
  700. // require http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js or jQueryUI - if other than ' swing or linear '
  701. easing: "easeInOutCubic", // easeInOutCubic easeInOutQuad easeInOutElastic http://easings.net/
  702. delay: 0,
  703. varStore: '',
  704. varAltStore:false,
  705. name: false,
  706. start: false,
  707. startTime: 0,
  708. step: false,
  709. stepTime: 0,
  710. complete: false,
  711. completeTime: 0,
  712. done: false,
  713. doneTime: 0,
  714. goTo: $('body')
  715. },
  716. heightSpeedComp = function(){
  717. return opt.hsc ? 1 + ( ( $(document).height() / opt.pageY ) / 1.4 ) : 1 ;
  718. },
  719. varStore = function( action, step ){
  720. (console.log(action,step),
  721. opt.name !== false
  722. ? opt.varAltStore !== false
  723. ? ( console.log('Store'), opt.varAltStore[opt.name][ action ](step) )
  724. : ( console.log('Store false'), opt.name[ action ](step) )
  725. : opt.pageYmini < opt.pageY || opt.varStore === config
  726. ? ( console.log('config'), opt.varStore[ action ](step) )
  727. : ( console.log('config false'), opt.varStore(step) ));
  728. };
  729. console.log('opt.pageY',opt.pageY);
  730. opt = $.extend( {}, defaults, opt );
  731. position = ( $( this ).offset().top + opt.tune ) + 'px';
  732.  
  733. opt.pps !== false || opt.animate !== false || ( typeof opt.speed === 'string' ? opt.speed.length !== 0 : opt.speed !== 0 )
  734. ? (
  735. opt.speed = opt.pps !== false ? parseInt( ( opt.pageY / opt.pps * heightSpeedComp() ) * opt.ppsM ) : opt.speed,
  736. opt.goTo.delay( opt.delay ).animate(
  737. { scrollTop : position },
  738. { duration : opt.speed, easing: opt.easing,
  739. start : function(){
  740. opt.start && setTimeout(function(){
  741. varStore('start');
  742. }, opt.startTime );
  743. },
  744. step : function(i){
  745. opt.step && setTimeout(function(){
  746. varStore('step',i);
  747. }, opt.stepTime );
  748. },
  749. complete : function(){
  750. opt.complete && setTimeout(function(){
  751. varStore('complete');
  752. }, opt.completeTime );
  753. },
  754. done : function(){
  755. opt.done && setTimeout(function(){
  756. varStore('done');
  757. }, opt.doneTime );
  758. }
  759. }
  760. )
  761. )
  762. : opt.goTo.scrollTop( position );
  763.  
  764. return this; // for chaining...
  765.  
  766. },
  767. scrollTuneNew : function ( opt ){
  768. var defaultOptions = {
  769. tune: 0,
  770. speed: 512,
  771. animate: true,
  772. easing: 'swing',
  773. goTo: $('html, body')
  774. },
  775. element = $( this ),
  776. options = $.extend({}, defaultOptions, $.fn.scrollTuneNew.changeDefaults, opt ),
  777. position = ( element.offset().top + options.tune ) + 'px';
  778.  
  779. options.animate
  780. ? options.goTo.animate({ scrollTop: position }, options.speed, options.easing )
  781. : options.goTo.scrollTop( position );
  782.  
  783. return element; // for chaining...
  784. },
  785. simulateMouseEvent : function ( MouseEvents ){
  786. var $this = this[0], evt,
  787. mEvent = MouseEvents || 'click';
  788. //noinspection JSUnresolvedVariable, noinspection JSUnresolvedFunction
  789. document.createEvent
  790. //noinspection JSUnresolvedFunction
  791. ? ( evt = document.MouseEvents('MouseEvents'),
  792. //evt.initCustomEvent(type, bubbles, cancelable, detail)
  793. //evt.initCustomEvent("MyEventType", true, true, "Any Object Here");
  794. evt.initEvent(mEvent, true, false),
  795. $this.dispatchEvent(evt) )
  796.  
  797. : //noinspection JSUnresolvedFunction
  798. document.createEventObject
  799. ? $this.fireEvent('onclick')
  800. : typeof node['on' + mEvent] == 'function' && $this['on' + mEvent]();
  801. },
  802. simulateMouse : function ( typeOfEvent ){
  803. var $this = this[0],
  804. evt = document.createEvent("MouseEvents"),
  805. mEvent = typeOfEvent || 'click';
  806. //noinspection JSDeprecatedSymbols
  807. evt.initMouseEvent( mEvent, true, true, $this.ownerDocument.defaultView,
  808. 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  809. $this !== undefined && $this.dispatchEvent(evt);
  810. return this;
  811. },
  812. simulateMouseAdv : function ( typeOfEvent, options ){
  813.  
  814. var target = this[0],
  815. event = document.createEvent("MouseEvents"),
  816. defaults = {
  817. mButton : 'left',
  818. type : typeOfEvent || 'click',
  819. canBubble : true,
  820. cancelable : true,
  821. view : target.ownerDocument.defaultView, //window, //
  822. detail : 1,
  823. screenX : 0, //The coordinates within the entire page
  824. screenY : 0,
  825. clientX : 0, //The coordinates within the viewport
  826. clientY : 0,
  827. ctrlKey : false,
  828. altKey : false,
  829. shiftKey : false,
  830. metaKey : false, //I *think* 'meta' is 'Cmd/Apple' on Mac, and 'Windows key' on Win. Not sure, though!
  831. button : 0, //0 = left, 1 = middle, 2 = right
  832. relatedTarget : null
  833. },
  834. opts = $.extend({}, defaults, $.fn.simulateMouseAdv.changeDefaults, options ),
  835. oButton = {
  836. left:0, middle:1, right:2
  837. };
  838.  
  839. console.log('oButton', opts.mButton );
  840. opts.button = oButton[ opts.mButton ];
  841.  
  842. //Pass in the options
  843. //noinspection JSDeprecatedSymbols
  844. event.initMouseEvent(
  845. opts.type,
  846. opts.canBubble,
  847. opts.cancelable,
  848. opts.view,
  849. opts.detail,
  850. opts.screenX,
  851. opts.screenY,
  852. opts.clientX,
  853. opts.clientY,
  854. opts.ctrlKey,
  855. opts.altKey,
  856. opts.shiftKey,
  857. opts.metaKey,
  858. opts.button,
  859. opts.relatedTarget
  860. );
  861.  
  862. //Fire the event
  863. target.dispatchEvent(event);
  864. },
  865.  
  866. hasEvent : function ( event ) {
  867. var eventHandlerType;
  868. $( this ).on( event, clickEventHandler ).triggerHandler( event );
  869. function clickEventHandler( e ) {
  870. eventHandlerType = e.type;
  871. }
  872. return eventHandlerType === event;
  873. },
  874. qUnWrap : function (){
  875. $( this ).find(':first-child').unwrap();
  876. },
  877. designMode : function ( state, contenteditable ) {
  878. state = ( state === true || state === 1 || state === 'on' ) ? 'on' :
  879. ( state === false || state === 0 || state === 'off' ) && 'off';
  880. contenteditable = contenteditable || 'off';
  881. contenteditable !== 'off'
  882. ? contenteditable === 'document'
  883. ? document.designMode = state
  884. : contenteditable
  885. ? this.attr('contenteditable', true)
  886. : this.removeAttr('contenteditable')
  887. : this.contentWindow.document.designMode = state;
  888. },
  889.  
  890. getThisComputedStyle : function ( style ) {
  891. return window.getComputedStyle( $(this), null ).getPropertyValue( style );
  892. },
  893. thisCompStyle : function ( cssStyle ) {
  894. return cssStyle !== undefined ? this.getComputedStyle().getPropertyValue( cssStyle ) : this.getComputedStyle();
  895. },
  896. getStyle : function( propertyKey ) {
  897. var cssPropAll = window.getComputedStyle(this, null);
  898. return propertyKey === undefined ? cssPropAll : cssPropAll.getPropertyValue( propertyKey );
  899. }
  900. });
  901.  
  902. //$.fn.scrollTune.changeDefault = {};
  903.  
  904. $.extend({
  905. confirm: function (title, message, yesText, noText, yesCallback) {
  906. //dialog needs jQueryUI
  907. /*
  908. $.confirm(
  909. "CONFIRM", //title
  910. "Delete " + filename + "?", //message
  911. "Delete", //button text
  912. deleteOk //"yes" callback
  913. );
  914. */
  915. $("<div></div>").dialog( {
  916. buttons: [{
  917. text: yesText,
  918. click: function() {
  919. yesCallback();
  920. $( this ).remove();
  921. }
  922. },
  923. {
  924. text: noText,
  925. click: function() {
  926. $( this ).remove();
  927. }
  928. }
  929. ],
  930. close: function (event, ui) { $(this).remove(); },
  931. resizable: false,
  932. title: title,
  933. modal: true
  934. }).text(message).parent().addClass("alert");
  935. }
  936. });
  937. $.extend( $.expr[":"], {
  938.  
  939. });
  940. $.extend( $.expr[":"], {
  941. ldata: function(el, idx, selector) {
  942. var attr = selector[3].split(", ");
  943. return el.dataset[attr[0]] === attr[1];
  944. },
  945. value: function(el, idx, selector) {
  946. return el.value === selector[selector.length - 1];
  947. },
  948. isEmptyTrimmed: function(el){
  949. return !$.trim($(el).html());
  950. },
  951. lengthBetween: function(elem, i, match) {
  952. var params = match[3].split(","); //split our parameter string by commas
  953. var elemLen = $(elem).val().length; //cache current element length
  954. return ((elemLen >= params[0] - 0) && (elemLen <= params[1] - 0)); //perform our check
  955. },
  956. data: $.expr.createPseudo
  957. ? $.expr.createPseudo(function( dataName ) {
  958. return function( elem ) {
  959. return !!$.data( elem, dataName );
  960. };
  961. })
  962. // support: jQuery <1.8
  963. : function( elem, i, match ) {
  964. return !!$.data( elem, match[ 3 ] );
  965. }
  966. });
  967. $.extend( $.expr[":"], {
  968. 'nth-class': function(elem, index, match) {
  969. return $(elem).is(':nth-child('+ match[3] +')');
  970. },
  971. 'nth-last-class': function(elem, index, match) {
  972. return $(elem).is(':nth-last-child('+ match[3] +')');
  973. },
  974. 'nth-class-of-type': function(elem, index, match) {
  975. return $(elem).is(':nth-of-type('+ match[3] +')');
  976. },
  977. 'nth-last-class-of-type': function(elem, index, match) {
  978. return $(elem).is(':nth-last-of-type('+ match[3] +')');
  979. },
  980. 'only-class-of-type': function(elem, index, match) {
  981. return $(elem).is(':first-of-type');
  982. },
  983. 'first-class-of-type': function(elem, index, match) {
  984. return $(elem).is(':first-of-type');
  985. },
  986. 'last-class-of-type': function(elem, index, match) {
  987. return $(elem).is(':last-of-type');
  988. },
  989. 'first-class': function(elem, index, match) {
  990. return $(elem).is(':first-child');
  991. },
  992. 'last-class': function(elem, index, match) {
  993. return $(elem).is(':last-child');
  994. },
  995. 'has': function(elem, index, match) {
  996. return $(elem).has( match[3] );
  997. },
  998. 'nth-class-leftOver' : function(elem, index, match, array){
  999. var elemLen = $(elem).length,
  1000. div = index % match[3],
  1001. indexLT = ( ( $(elem).length % match[3] === 0 ) * match[3] ) + 1;
  1002.  
  1003. var N= document.getElementsByTagName('*');
  1004. c.i('indexOf',Array.prototype.indexOf.call(elem, $(elem).parent()));
  1005.  
  1006. c.i('elem.eq', $(elem).eq( ));
  1007. c.i('elem', $(elem));
  1008. c.i('elemLen', elemLen);
  1009. c.i('index', index);
  1010. c.i('div', div);
  1011. c.i('indexLT', indexLT);
  1012. return $(elem).is(':lt(' + indexLT + ')');
  1013. //return $(elem).lt( ( ( $(elem).length % match[3] === 0 ) * match[3] ) + 1 );
  1014. },
  1015. external: function(element,index,match) {
  1016. if(!element.href) {return false;}
  1017. return element.hostname && match[3] !== undefined || false
  1018. ? element.hostname !== window.location.hostname
  1019. && element.hostname.search( match[3] ) === window.location.hostname.search( match[3] )
  1020. : element.hostname !== window.location.hostname;
  1021. },
  1022. inView: function(element) {
  1023. var st = (document.documentElement.scrollTop || document.body.scrollTop),
  1024. ot = $(element).offset().top,
  1025. wh = (window.innerHeight && window.innerHeight < $(window).height()) ? window.innerHeight : $(window).height();
  1026. return ot > st && ($(element).height() + ot) < (st + wh);
  1027. },
  1028. width: function(element,index,match) {
  1029. // Usage: $('div:width(>200)'); // Select all DIVs that have a width greater than 200px
  1030. // Alternative usage: ('div:width(>200):width(<300)');
  1031. if(!match[3]||!(/^(<|>)d+$/).test(match[3])) {return false;}
  1032. return match[3].substr(0,1) === '>' ?
  1033. $(element).width() > match[3].substr(1) : $(element).width() < match[3].substr(1);
  1034. },
  1035. containsNC: function(elem, i, match, array) {
  1036. return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
  1037. },
  1038. containsExact: function( element, index, details, collection ){
  1039. return $(element).text() === details[3];
  1040. }
  1041.  
  1042. });
  1043.  
  1044. jQuery.expr[":"].Contains = $.expr.createPseudo(function(selector) {
  1045. return function( elem ) {
  1046. return jQuery(elem).text().toUpperCase().indexOf(selector.toUpperCase()) >= 0;
  1047. };
  1048. });
  1049. jQuery.expr[':']['new-nth-class'] = function(elem, index, match) {
  1050. return $(elem).is(':nth-child('+ match[3] +')');
  1051. };
  1052. jQuery.expr[':']['new-nth-class'] = $.expr.createPseudo( function( matchSelection ) {
  1053. return function( elem ) {
  1054. return $(elem).is(':nth-child('+ matchSelection +')');
  1055. };
  1056. });
  1057.  
  1058. $.isInArray = function( item, array ) {
  1059. return !!~$.inArray(item, array);
  1060. };
  1061. $.allVar = function( array, value, all, atLeast ) {
  1062. var count = 0,
  1063. arrLength = array.length,
  1064. isBool = typeof value === 'boolean';
  1065.  
  1066. $.each( array, function( i, e ){
  1067. value === ( isBool ? !!e : e ) && count++;
  1068. });
  1069.  
  1070. return all ? count === arrLength : count >= atLeast;
  1071. };
  1072. /*
  1073. Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
  1074. //$( selector ).get(0).playing;
  1075. get: function(){
  1076. return !!( this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2 );
  1077. }
  1078. });
  1079. */
  1080. /* Object.prototype.hasAttribute = function( attrName, val ){
  1081. var thisAttr =
  1082. this.attr
  1083. ? val !== undefined
  1084. ? this.attr( attrName ) === val
  1085. : this.attr( attrName )
  1086. : this.getAttribute( attrName );
  1087. return ( typeof thisAttr !== "undefined" && thisAttr !== false && thisAttr !== null );
  1088. };
  1089. */
  1090. Array.prototype.findArrayObj = function( findKey, exactValue ){
  1091. return $.grep( this, function( obj ){
  1092. return obj[ findKey ] === exactValue;
  1093. })[0];
  1094. //This prototype doesn't modify the array,
  1095. // it gets the element that contains key with correct value and
  1096. // the returns that element
  1097. };
  1098. Array.prototype.removeArrayObj = function( findKey, exactValue ){
  1099. //my own example test: http://jsfiddle.net/aPH7m/82/
  1100. //This prototype doesn't modify the array, needs to be overwritten or put into new var array
  1101. return $.grep( this, function( obj ) {
  1102. return obj[ findKey ] !== exactValue;
  1103. });
  1104. };
  1105. Array.prototype.addKeyToArrayObj = function( findKey, exactValue, newKey, newValue ){
  1106. return $.grep( this, function( obj ){
  1107. return obj[ findKey ] === exactValue ? obj[ newKey ] = newValue : obj[ findKey ] !== exactValue;
  1108. });
  1109. // This prototype doesn't modify the array,
  1110. // it gets the element that contains key with correct value and
  1111. // adds a new key with its value to that element
  1112. };
  1113.  
  1114. Array.prototype.filterArrayObj = function( doWhat, findKey, exactValue, newKey, newValue ){
  1115. return doWhat === 'remove'
  1116. ? this.filter(function( obj ) {
  1117. return obj[ findKey ] !== exactValue;
  1118. })
  1119. : doWhat === 'addKey'
  1120. ? this.filter(function( obj ){
  1121. return obj[ findKey ] === exactValue
  1122. ? obj[ newKey ] = newValue
  1123. : obj[ findKey ] !== exactValue;
  1124. })
  1125. : doWhat === 'find'
  1126. && this.filter(function( obj ){
  1127. return obj[ findKey ] === exactValue;
  1128. })[0];
  1129. };
  1130. Array.prototype.grepArrayObj = function( doWhat, idKey, uniqueValue, theKey, theValue ){
  1131. doWhat = doWhat === 'updateKey' ? 'addKey' : doWhat;
  1132. return doWhat === 'remove'
  1133. ? $.grep( this, function( obj ){
  1134. return obj[ idKey ] !== uniqueValue;
  1135. })
  1136. : doWhat === 'addKey'
  1137. ? $.grep( this, function( obj ){
  1138. return obj[ idKey ] === uniqueValue
  1139. ? (
  1140. obj[ theKey ] = theValue,
  1141. obj[ idKey ] === uniqueValue
  1142. )
  1143. : obj[ idKey ] !== uniqueValue;
  1144. })
  1145. : doWhat === 'find'
  1146. ? $.grep( this, function( obj ){
  1147. return obj[ idKey ] === uniqueValue;
  1148. })[0]
  1149. : doWhat === 'deleteKey'
  1150. && $.grep( this, function( obj ){
  1151. return obj[ idKey ] === uniqueValue
  1152. ? (
  1153. delete obj[ theKey ],
  1154. obj[ idKey ] === uniqueValue
  1155. )
  1156. : obj[ idKey ] !== uniqueValue;
  1157. });
  1158. };
  1159. /*Array.prototype.sortObjArray = function( key, reverse ){
  1160. this.sort(function(a, b){
  1161. return ( reverse || false ) ? b[key] - a[key] : a[key] - b[key];
  1162. })
  1163. };*/
  1164.  
  1165. //noinspection JSPrimitiveTypeWrapperUsage
  1166. Boolean.parse = function(val) {
  1167. // http://stackoverflow.com/a/24744599
  1168. var falsely = /^(?:f(?:alse)?|no?|0+)$/i;
  1169. return !falsely.test(val) && !!val;
  1170. };
  1171. Boolean.prototype.isFalse = function( ){
  1172. return this.toString() == "false";
  1173. };
  1174. Boolean.prototype.isTrue = function( ){
  1175. return this.toString() == "true";
  1176. };
  1177. Boolean.prototype.ifs = function ( fnTrue, fnFalse ){
  1178. fn( this ? fnTrue : fnFalse );
  1179. /*
  1180. $("#element").ifs( function( $this ){}, function( $this ){});
  1181. */
  1182. };
  1183. Boolean.prototype.ifBool = function ( Boolean, fn ){
  1184. ( this == ( typeof Boolean === 'string' ) ? parseBoolean( Boolean ) : Boolean ) && fn();
  1185. };
  1186.  
  1187. /*
  1188. Object.prototype.isObjectType = function( type, showType ){ //"[object Number]"
  1189. var objectString = Object.prototype.toString.call( this );
  1190. return showType === 'show' ? objectString :
  1191. showType === 'exact' ? objectString === type :
  1192. showType === 'search' && objectString.toLowerCase().inElem( type.toLowerCase() );
  1193. };
  1194.  
  1195. Object.defineProperty(String.prototype, "_defineBool", {
  1196. //myBool.toString()._defineBool()
  1197. get : function() {
  1198. var falsely = /^(?:f(?:alse)?|no?|off?|n?|failure?|sudumoo?|0+)$/i,
  1199. truely = /^(?:t(?:rue)?|yes?|on?|y?|success?|yabbdoo?|1+)$/i,
  1200. stateBool = !!this;
  1201.  
  1202. return ( truely.test( this ) === stateBool ) ? true : ( falsely.test( this ) === stateBool ) ? false : !isNaN(parseFloat( this )) && isFinite( this ) ? true : null;
  1203. }
  1204. });
  1205. Object.prototype.obj2Str = function( obj ){
  1206. var objArr = $.makeArray( obj );
  1207. return objArr[0].outerHTML;
  1208. };
  1209. */
  1210. String.prototype.splitEvery = function( splitter, every ){
  1211. var array = this.split( splitter ), returnString = '';
  1212. $.each( array, function( index, elem ){
  1213. returnString += elem + ( index < array.length - 1 || index % every === 0 ) ? '' : splitter;
  1214. });
  1215. return returnString;
  1216. };
  1217. String.prototype.advSplit = function( chr, nbr ){
  1218. var str = this.split(chr),
  1219. strLen = str.length,
  1220. chrLen = chr.length,
  1221. returnStr = ['',''],
  1222. newArr = [];
  1223.  
  1224. $.each( str, function( index ){
  1225. returnStr[ index < nbr ? 0 : 1 ] += str[ index ] + chr;
  1226. });
  1227.  
  1228. $.each( returnStr, function( index ){
  1229. returnStr[ index ] = returnStr[ index ].slice(0, - chrLen);
  1230. returnStr[ index ].length > 0 && newArr.push( returnStr[ index] );
  1231. });
  1232.  
  1233. return newArr;
  1234. };
  1235. String.prototype.advSplitJoin = function( chr, nbr, ips ){
  1236.  
  1237. var str = this.split(chr),
  1238. strLen = str.length,
  1239. ipsLen = ips.length,
  1240. returnStr = '',
  1241. returnStrLen;
  1242.  
  1243. $.each( str, function( index ) {
  1244. var add = index < strLen - 1
  1245. ? chr
  1246. : '';
  1247. returnStr += index + 1 === nbr
  1248. ? str[index] + ips
  1249. : str[index] + add;
  1250. });
  1251.  
  1252. returnStrLen = returnStr.length;
  1253. returnStr.slice( returnStrLen - ipsLen ) === ips
  1254. && ( returnStr = returnStr.slice( 0, returnStrLen - ipsLen ) );
  1255.  
  1256. return returnStr;
  1257. };
  1258. String.prototype.extract = function( start, end, inside, newWay ){
  1259. var str = this,
  1260. myArray = [ true, 1, 'yes', 'inside' ],
  1261. startCharIndex = str.indexOf( start ),
  1262. endCharIndex = str.indexOf( end );
  1263.  
  1264. newWay = newWay !== undefined ? $.inArray( newWay, myArray ) !== -1 : false;
  1265. inside = inside !== undefined ? $.inArray( inside, myArray ) !== -1 : false;
  1266.  
  1267. function simpler() {
  1268. return inside
  1269. ? str.split( start ).pop().split( end ).shift()
  1270. : start + str.split( start ).pop().split( end ).shift() + end;
  1271. }
  1272. function older() {
  1273. return inside //old buggy way, some old scripts may depends on it
  1274. ? str.replace( start, '').replace( end, '')
  1275. : str.substr( startCharIndex, endCharIndex );
  1276. }
  1277. return newWay ? simpler() : older();
  1278. };
  1279. String.prototype.extractNew = function( start, end, inside ){
  1280. var str = this;
  1281. return inside !== undefined && inside
  1282. ? str.split( start ).pop().split( end ).shift()
  1283. : inside
  1284. || start + str.split( start ).pop().split( end ).shift() + end;
  1285. };
  1286.  
  1287. String.prototype.charTrim = function( char ){
  1288. // alert("...their.here.".charTrim('.'));
  1289. var first_pos = 0,
  1290. last_pos = this.length- 1, i ;
  1291. //find first non needle char position
  1292. for( i = 0; i < this.length; i++ ){
  1293. if( this.charAt( i ) !== char ){
  1294. first_pos = ( i == 0 ? 0 : i );
  1295. break;
  1296. }
  1297. }
  1298. //find last non needle char position
  1299. for( i = this.length - 1; i > 0; i-- ){
  1300. if( this.charAt( i ) !== char ){
  1301. last_pos = ( i == this.length ? this.length: i + 1 );
  1302. break;
  1303. }
  1304. }
  1305. return this.substring( first_pos, last_pos );
  1306. };
  1307. String.prototype.reduceWhiteSpace = function(){
  1308. return this.replace(/\s+/g, ' ');
  1309. };
  1310. String.prototype.formatString = function(){
  1311.  
  1312. var inputStr = this.toString().reduceWhiteSpace()
  1313. .split('!').join(' !').split('!;').join("!important;")
  1314. .split(/\s+/g).join(' ')
  1315. .split('{').join('{\n\t')
  1316. .split('; ').join(';')
  1317.  
  1318.  
  1319.  
  1320. .split('( ').join('(')
  1321. .split(' )').join(')')
  1322.  
  1323. .split(' :').join(':')
  1324.  
  1325. .split(';').join(';\n\t')
  1326. .split('*/').join('*/\n')
  1327. .split(')*(').join(') * (')
  1328. .split('}').join('}\n'),
  1329. returnStr = '\t', pop;
  1330.  
  1331. $.each( inputStr.split('\n'), function ( i, elem ) {
  1332.  
  1333. elem.search( '{' ) === -1 && elem.search( ': ' ) === -1
  1334. && ( elem.search( ':' ) > 1
  1335. ? ( pop = elem.split(': ').join(':').split( ':' ).pop(), elem = elem.split( pop ).shift() + ' ' + pop )
  1336. : elem.search(':') === 1 && ( elem = elem.split(': ').join(':').split( ':' ).join( ': ' ) ) );
  1337. // : elem.search( '{' ) === 1 && ( elem.search( ': ' ) !== -1 || elem.search( ' :' ) !== -1 || elem.search( ' : ' ) !== -1 )
  1338. // && ( elem = elem.split( ': ' ).join( ' :' ).split( ' :' ).join( ':' ).split( ' : ' ).join( ': ' ) );
  1339.  
  1340. returnStr += elem + '\n\t';
  1341. });
  1342. returnStr = returnStr.split('>').join(' > ').split(' > ').join(' > ').split( ': //' ).join( '://' ).split( ':url' ).join( ': url' );
  1343. return returnStr.slice( 0, returnStr.lastIndexOf('}') ) + '}';
  1344. };
  1345.  
  1346. /**
  1347. * Parses mixed type values into booleans. This is the same function as filter_var in PHP using boolean validation
  1348. * //@return {Boolean|Null}
  1349. */
  1350. String.prototype.parseBooleanStyle = function( onNull ){
  1351. //myBool.toString().parseBooleanStyle()
  1352. onNull = onNull || false;
  1353. var bool, $this = this.toString().toLowerCase();
  1354. switch( $this ){
  1355. case 'true':
  1356. case '1':
  1357. case 'on':
  1358. case 'y':
  1359. case 'yes':
  1360. bool = true;
  1361. break;
  1362. case 'false':
  1363. case '0':
  1364. case 'off':
  1365. case 'n':
  1366. case 'no':
  1367. bool = false;
  1368. break;
  1369. default:
  1370. bool = typeof bool === 'boolean' ? bool : null;
  1371. break;
  1372. }
  1373. return onNull && bool == null || parseInt( $this ) > 0 || bool;
  1374. };
  1375. String.prototype.parseBool = function(){
  1376. //myBool.toString().parseBool()
  1377. var thisStr = ( parseInt( this ) ? this === 0 ? 'false' : !isNaN( parseFloat( this ) ) && 'true' : '' + this ).toLowerCase().trim(),
  1378. trueArray = [ 'on', 'yes','y', 'j', 'success', 'true', true ],
  1379. falseArray = [ 'off', 'no', 'n', 'failure', 'false', false ];
  1380.  
  1381. thisStr = thisStr.toLowerCase().trim();
  1382.  
  1383. return $.inArray( thisStr, trueArray ) !== -1 ? true : $.inArray( thisStr, falseArray ) !== -1 ? false : null;
  1384. };
  1385. String.prototype.defineBool = function(){
  1386. var falsely = /^(?:f(?:alse)?|no?|off?|n?|failure?|sudumoo?|0+)$/i,
  1387. truely = /^(?:t(?:rue)?|yes?|on?|y?|success?|yabbdoo?|1+)$/i,
  1388. stateBool = !!this,
  1389. $string = this;
  1390.  
  1391. return ( truely.test( this ) === stateBool )
  1392. ? true : ( falsely.test( this ) === stateBool )
  1393. ? false : $string != 0 && !isNaN(parseFloat($string)) && ( (typeof $string === 'number' || typeof $string === 'string') && isFinite($string) ) ? true : null;
  1394. };
  1395.  
  1396. String.prototype.isType = function( type ){
  1397. return !!$.type( this ) === type;
  1398. };
  1399. String.prototype.undef = function( replace ){
  1400. return this === undefined ? replace : this;
  1401. };
  1402. String.prototype.isUndefined = function( state, replace ){
  1403. state = state !== undefined ? state : true;
  1404. replace = replace !== undefined ? replace : true;
  1405. return state ? this === undefined ? replace : this : state;
  1406. };
  1407. String.prototype.isNumber = function ( float ) {
  1408. var reg = new RegExp( "^[-]?[0-9]+[\.]?[0-9]+$" );
  1409. return reg.test( this );
  1410. };
  1411.  
  1412. String.prototype.inURL = function(){
  1413. var winLoc = window.location.href;
  1414. return winLoc.search(this) !== -1;
  1415. };
  1416. String.prototype.inString = function( string ){
  1417. return string !== undefined ? string.search(this) !== -1 : false;
  1418. };
  1419. String.prototype.inElem = function( search ){
  1420. return this !== undefined ? this.search(search) !== -1 : false;
  1421. };
  1422. String.prototype.inElemX = function( search, exact ){
  1423.  
  1424. var isAll,isNone,inArr,checkInArr,
  1425. string = this,
  1426. countAll = 0, countNone = 0;
  1427.  
  1428. exact = exact || false;
  1429. isAll = exact === 'all';
  1430. isNone = exact === 'none';
  1431. exact = isNone || isAll ? false : exact;
  1432.  
  1433. checkInArr = function( search, all ){
  1434. inArr = false;
  1435. $.each( search, function( i, e ){
  1436. if(string.search( e ) !== -1 || string.search( e ) === -1){
  1437. inArr = true;
  1438. if( all ) string.search( e ) !== -1 ? countAll++ : string.search( e ) === -1 && countNone++;
  1439. else return false;
  1440. }
  1441. });
  1442. return all ? inArr && ( string.length === countAll || string.length === countNone ) : inArr;
  1443. };
  1444.  
  1445. return exact
  1446. ? string === search
  1447. : $.isArray( search )
  1448. ? checkInArr( search, isAll || isNone )
  1449. : isNone
  1450. ? string.search( search ) === -1
  1451. : string.search( search ) !== -1;
  1452. };
  1453. String.prototype.count = function( char, UpperCase ){
  1454. var numberOf = this.toString().match( new RegExp( char, ( UpperCase ? "gi" : "g" ) ) );
  1455. return numberOf != null ? numberOf.length : 0;
  1456. };
  1457. String.prototype.startsWith = function( str ){
  1458. return this.slice(0, str.length) == str;
  1459. };
  1460. String.prototype.removeStarts = function( many ){
  1461. return this.substring( many - 1, this.length );
  1462. };
  1463. String.prototype.removeEnds = function( many ){
  1464. return this.substring( 0, this.length - many );
  1465. };
  1466. String.prototype.endsWith = function( str ){
  1467. return this.slice( -str.length ) == str;
  1468. };
  1469. String.prototype.capitalizeFirst = function(){
  1470. return this.charAt(0).toUpperCase() + this.slice(1);
  1471. };
  1472. String.prototype.lpad = function( padString, length ){
  1473. var str = this;
  1474. while ( str.length < length ) {
  1475. str = padString + str; }
  1476. return str;
  1477. };
  1478.  
  1479. // use full to convert String URL, so that you can use location commands
  1480. String.prototype.toLocation = function(){
  1481. var a = document.createElement('a');
  1482. a.href = this;
  1483. return a;
  1484. };
  1485. String.prototype.toStyle = function( styleId, append ){
  1486. append = append || 'head';
  1487. var cssID,
  1488. cssSplit = this.split('¤'),
  1489. cssStyled = cssSplit.pop().formatString();
  1490. styleId = styleId !== undefined ? styleId : cssSplit.shift();
  1491. cssID = $( append + ' #' + styleId );
  1492. cssID.length
  1493. ? cssID.html( cssStyled )
  1494. : $( $( '<style/>',{ id: styleId, class:'mySuperStyles', html: cssStyled } ) ).appendTo( append );
  1495. };
  1496.  
  1497. String.prototype.HTMLEncodedParserHTML = function(){
  1498. return $('<div/>').html( $( $.parseHTML( decodeURI(this) ) ) ).contents();
  1499. };
  1500. String.prototype.strParserHTML = function(){
  1501. return $($.parseHTML(this));
  1502. };
  1503. String.prototype.strDOMParser = function(){
  1504. return new DOMParser().parseFromString(this, "text/html");
  1505. };
  1506. String.prototype.str2html = function(){
  1507. return $('<div/>').html( this ).contents();
  1508. };
  1509.  
  1510. String.prototype.autoCopyToClipboard = function( cssElement, how ) {
  1511. cssElement = cssElement || 'body';
  1512. how = how || 'append';
  1513.  
  1514. var mainID = 'autoCopyToClipboard',
  1515. copyThis = $( '#' + mainID );
  1516.  
  1517. $( cssElement )[ how ](
  1518. $('<div/>',{ id: mainID + 'Wrapper', style: 'position:relative;' }).append(
  1519. $('<textarea/>',{
  1520. id: mainID, rows:"5", cols:"500", type:"text", value: this.toString(),
  1521. style: 'position:absolute; top:-300px; display:block;' }) ) );
  1522.  
  1523. setTimeout(function (){
  1524. copyThis.focus().select();
  1525. document.execCommand("copy");
  1526. var remove = setInterval(function(){
  1527. $( '#' + mainID + 'Wrapper' ).ifExists(function( $this ){
  1528. $this.remove();
  1529. clearInterval( remove );
  1530. });
  1531. },8);
  1532. },2);
  1533. };
  1534.  
  1535. //HTMLObjectElement.prototype.obj2Str = function(){var objArr = $.makeArray( this ); return objArr[0].outerHTML;};
  1536. /*
  1537. String.prototype.replaceAll = function( target, replacement ) {
  1538. return this.split(target).join(replacement);
  1539. };
  1540. */
  1541. function ScrollZoomTune( selection, zooms, tune, ani, speed ){
  1542. //ScrollZoomTune("div.thumb .title a",1,-25,1,'slow');
  1543. var body = $('body'), sel = $( selection), position;
  1544. //noinspection JSValidateTypes
  1545. sel.size() !== 0 && (
  1546. body.css('zoom',zooms),
  1547. position = sel.position().top + tune,
  1548. ani === 1
  1549. ? body.animate({ scrollTop: position * zooms }, speed )
  1550. : body.scrollTop( position * zooms )
  1551. );
  1552. }
  1553. function refreshElement( elem , speed ){ //refreshElement('.videoPlayer','slow');
  1554. var $elem = $( elem ), data = $elem.html();
  1555. $elem.empty().html( data ).fadeIn( speed );
  1556. }
  1557.  
  1558. !!$.isFunction( $.fn.execCommand ) || ($.fn.execCommand = function(){});
  1559.  
  1560. function autoCopy2Clipboard( input, cssElement, how ){
  1561. cssElement = cssElement || 'body';
  1562. how = how || 'append';
  1563.  
  1564. var mainID = 'autoCopyToClipboard',
  1565. copyThis = $( '#' + autoCopyToClipboard );
  1566.  
  1567. '#autoCopyToClipboard { position:absolute; top:-300px; display:block; }'.toStyle( mainID );
  1568. $( cssElement )[ how ]( $('<textarea/>',{ id:mainID, rows:"5", cols:"500", type:"text", value: input }) );
  1569.  
  1570. copyThis.focus().select();
  1571. document.execCommand("copy");
  1572. copyThis.remove();
  1573. }
  1574. function toStyle( styleId, str, append ){
  1575. append = append || 'head';
  1576. var $id = $( append + ' #' + styleId ),
  1577. cssID = str.formatString();
  1578.  
  1579. $id.length
  1580. ? $id.html( cssID )
  1581. : $( $( '<style/>',{ id: styleId, class:'mySuperStyles', html: cssID } ) ).appendTo( append );
  1582. }
  1583. function getTheStyle( id ){
  1584. var elem = document.getElementById("elem-container");
  1585. var theCSSprop;
  1586. theCSSprop = window.getComputedStyle(elem, null).getPropertyValue("height");
  1587. document.getElementById("output").innerHTML = theCSSprop;
  1588. }
  1589. function obj2Str( obj ){
  1590. var objArr = $.makeArray(obj);
  1591. return objArr[0].outerHTML;
  1592. }
  1593. function orderBy(key, reverse){
  1594. return function (a, b) {
  1595. return ( reverse || false ) ? b[ key ] - a[ key ] : a[ key ] - b[ key ];
  1596. };
  1597. }
  1598. function sortBy(key, reverse){
  1599. var R = reverse || false;
  1600. return function (a, b) {
  1601. var A = a[ key ], B = b[ key ];
  1602. return A < B ? R ? 1 : -1 : A > B ? R ? -1 : 1 : 0;
  1603. };
  1604. }
  1605. function sortByOLD(key, reverse){
  1606. // Usage: array.sort( sortBy( key, reverse ) )
  1607. // Move smaller items towards the front
  1608. // or back of the array depending on if
  1609. // we want to sort the array in reverse
  1610. // order or not.
  1611. var moveSmaller = reverse ? 1 : -1;
  1612. // Move larger items towards the front
  1613. // or back of the array depending on if
  1614. // we want to sort the array in reverse
  1615. // order or not.
  1616. var moveLarger = reverse ? -1 : 1;
  1617. /**
  1618. * @param {*} a
  1619. * @param {*} b
  1620. * @return {Number}
  1621. */
  1622. return function (a, b) {
  1623. if (a[key] < b[key]) {
  1624. return moveSmaller;
  1625. }
  1626. if (a[key] > b[key]) {
  1627. return moveLarger;
  1628. }
  1629. return 0;
  1630. };
  1631. }
  1632.  
  1633. /**
  1634. @function sec2timeFormat
  1635. @description convert second to time format in 4+ different ways into @example DD:HH:MM:SS.ms
  1636. @param {(string|Number)} totalSeconds - @desc it will convert to millisecond inside of @function
  1637. @param {Boolean} [complete] - @example true 02:45:05 or 02h 45m 05s false 2:45:05 or 2h 45m 05s
  1638. @param {(string|Boolean)} [divider] - @example common ':' or '-' or '/'
  1639. @param {Number} [toFix] - @desc millisecond after second - @default 2 - @example 45:05.44 or 5.44s
  1640. @return {string}
  1641. @copyright May 2017 - Magnus Fohlström
  1642. @license MIT
  1643. */
  1644. function sec2timeFormat( totalSeconds, complete, divider, toFix ){
  1645. totalSeconds = typeof totalSeconds === 'string' ? parseInt(totalSeconds) : totalSeconds;
  1646. toFix = toFix !== undefined ? ( toFix === 0 ? 0 : toFix ) : 2;
  1647. var bFull = complete !== undefined ? complete && true : false,
  1648. div = divider !== undefined ? divider !== false : false,
  1649.  
  1650. date = new Date( totalSeconds * 1000 ),
  1651. d = Math.floor( totalSeconds / 3600 / 24 ),
  1652. // d = date.getUTCDate() - 1,
  1653. h = date.getUTCHours(),
  1654. m = date.getUTCMinutes(),
  1655. s = date.getSeconds(),
  1656. ms = totalSeconds - Math.floor( totalSeconds ),
  1657.  
  1658. preD = div ? divider : 'd ', dPreD = d + preD,
  1659. dd = bFull
  1660. ? d === 0 ? '00' + preD : (d < 10 ? '0':'') + dPreD
  1661. : d === 0 ? '' : dPreD,
  1662.  
  1663. preH = div ? divider : 'h ', hPreH = h + preH,
  1664. hh = dd.length > 0
  1665. ? h === 0 ? '00' + preH : (h < 10 ? '0':'') + hPreH
  1666. : h === 0 ? bFull ? h < 10 ? '0' + hPreH : hPreH : '' : hPreH,
  1667.  
  1668. preM = div ? divider : 'm ', mPreM = m + preM,
  1669. mm = hh.length > 0
  1670. ? m === 0 ? '00' + preM : (m < 10 ? '0':'') + mPreM
  1671. : m === 0 ? bFull ? m < 10 ? '0' + mPreM : mPreM : '' : mPreM,
  1672.  
  1673. preMS = ( s + ms ).toFixed( toFix ),
  1674. preS = div ? '' : 's', sPreS = preMS + preS,
  1675. ss = mm.length > 0
  1676. ? s === 0 ? '00' + preS : (s < 10 ? '0':'') + sPreS
  1677. : sPreS;
  1678.  
  1679. return ( dd + hh + mm + ss ).toString();
  1680. }
  1681.  
  1682. function VideoTitleA( elem , state ){
  1683. //VideoTitleA("div.thumb .title a",'on');
  1684. $( elem ).each(function(){
  1685. var $this = $(this),
  1686. strTitle = $this.attr('title'),
  1687. strText = $this.attr('data-text'),
  1688. strHtml = $this.text();
  1689. state === 'on' ? $this.text(strTitle).attr('data-text',strHtml) : $this.text(strText);
  1690. });
  1691. }
  1692. /**
  1693. * @return {string}
  1694. */
  1695. function MultiString( f ){
  1696. return f.toString().split('\n').slice(1, -1).join('\n');
  1697. }
  1698. function wrapWithTag( tag, text, selection ){
  1699. var thisAttr = selection != undefined && selection.startsWith('.') ? 'class' : selection.startsWith('#') && 'id',
  1700. thisTag = $('<' + tag + '/>', { text: text });
  1701. return thisAttr.length ? thisTag.attr( thisAttr, selection.splice( 1 ) ) : thisTag;
  1702. }
  1703.  
  1704. function clean( node ) {
  1705. /*
  1706. So to clean those unwanted nodes from inside the <body> element, you would simply do this:
  1707.  
  1708. clean(document.body);
  1709. Alternatively, to clean the entire document, you could do this:
  1710.  
  1711. clean(document);
  1712. */
  1713. for( var n = 0; n < node.childNodes.length; n ++ ){
  1714. var child = node.childNodes[ n ];
  1715. ( child.nodeType === 8 || ( child.nodeType === 3 && !/\S/.test( child.nodeValue ) ) )
  1716. ? (
  1717. node.removeChild( child ),
  1718. n --
  1719. )
  1720. : child.nodeType === 1 && clean( child );
  1721. }
  1722. }
  1723. function commentsCleaner( array ){
  1724. array = array === undefined ? [ '*', document, 'html' ] : array;
  1725.  
  1726. // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
  1727. // http://stackoverflow.com/a/2364760
  1728. $.each( array, function( i, e ) {
  1729. $( e ).contents().each( function() {
  1730. this.nodeType === Node.COMMENT_NODE && $( this ).remove(); }); });
  1731. }
  1732. function clearSelection() {
  1733. var sel;
  1734. if ( (sel = document.selection) && sel.empty ) {
  1735. sel.empty();
  1736. } else {
  1737. if (window.getSelection) {
  1738. window.getSelection().removeAllRanges();
  1739. }
  1740. var activeEl = document.activeElement;
  1741. if (activeEl) {
  1742. var tagName = activeEl.nodeName.toLowerCase();
  1743. if ( tagName == "textarea" ||
  1744. (tagName == "input" && activeEl.type == "text") ) {
  1745. // Collapse the selection to the end
  1746. activeEl.selectionStart = activeEl.selectionEnd;
  1747. }
  1748. }
  1749. }
  1750. }
  1751. function newUrlNoReload( title, url ){
  1752. window.history.pushState("string", title, url );
  1753. }
  1754. function inURLo( search, exact ){
  1755. exact = exact || false;
  1756. var winLoc = window.location.href;
  1757. return exact ? winLoc === search : winLoc.search( search ) !== -1;
  1758. }
  1759. function inURLe( search, exact ){
  1760. exact = exact || false;
  1761. var inArr,
  1762. winLoc = window.location.href,
  1763. tiA = function( search ){
  1764. inArr = false;
  1765. $.each( search, function(i,e){
  1766. if( winLoc.search( search ) !== -1 ){
  1767. inArr = true;
  1768. return false;
  1769. }
  1770. });
  1771. return inArr;
  1772. };
  1773. return exact ? winLoc === search : $.isArray( search ) ? tiA( search ) : winLoc.search( search ) !== -1;
  1774. }
  1775. function inURL( search, exact ){
  1776.  
  1777. var isAll,isNone,inArr,checkInArr,
  1778. winLoc = window.location.href,
  1779. countAll = 0, countNone = 0;
  1780.  
  1781. exact = exact || false;
  1782. isAll = exact === 'all';
  1783. isNone = exact === 'none';
  1784. exact = isNone || isAll ? false : exact;
  1785.  
  1786. checkInArr = function( search, all ){
  1787. inArr = false;
  1788. $.each( search, function( i, e ){
  1789. if(winLoc.search( e ) !== -1 || winLoc.search( e ) === -1){
  1790. inArr = true;
  1791. if( all ) winLoc.search( e ) !== -1 ? countAll++ : winLoc.search( e ) === -1 && countNone++;
  1792. else return false;
  1793. }
  1794. /*
  1795. if( winLoc.search( e ) !== -1 ){
  1796. inArr = true;
  1797. if( all ) countAll++; else return false;
  1798. }
  1799. else if( winLoc.search( e ) === -1 ){
  1800. inArr = true;
  1801. if( all ) countNone++; else return false;
  1802. }
  1803. */
  1804. });
  1805. return all ? inArr && ( search.length === countAll || search.length === countNone ) : inArr;
  1806. };
  1807.  
  1808. return exact
  1809. ? winLoc === search
  1810. : $.isArray( search )
  1811. ? checkInArr( search, isAll || isNone )
  1812. : isNone
  1813. ? winLoc.search( search ) === -1
  1814. : winLoc.search( search ) !== -1;
  1815. }
  1816. function loadDoc( href ){
  1817. $( location ).attr('href', href );
  1818. }
  1819.  
  1820. function isPrimitiveType( value ){
  1821. // will return true if the value is a primitive value
  1822. switch ( typeof value ) {
  1823. case 'string': case 'number': case 'boolean': case 'undefined': {
  1824. return true;
  1825. }
  1826. case 'object': {
  1827. return !value;
  1828. }
  1829. }
  1830. return false;
  1831. }
  1832. function checkDividedIsInteger( num, div ){
  1833. return ( num % div === 0 );
  1834. }
  1835. function isEven( value ){
  1836. return ( value % 2 === 0 );
  1837. }
  1838. function inDom( array, onElement ) {
  1839. var found = false,
  1840. isArrayFN = function(){
  1841. $.each( array, function( i, value ){
  1842.  
  1843. value = onElement !== undefined
  1844. ? onElement + value
  1845. : value;
  1846.  
  1847. if( $( value ).length ){
  1848. found = true;
  1849. return false;
  1850. }
  1851. });
  1852. };
  1853.  
  1854. $.isArray( array )
  1855. ? isArrayFN()
  1856. : $( array ).length && ( found = true );
  1857.  
  1858. /**
  1859. * @return {boolean}
  1860. */
  1861. return found;
  1862. }
  1863. function isHTMLObject( obj ){
  1864. obj = typeof obj == 'string' ? obj : $( obj );
  1865. return obj.length
  1866. ? !!~( obj instanceof HTMLElement || obj[0] instanceof HTMLElement)
  1867. : !!( obj && ( obj.nodeName || ( obj.prop && obj.attr && obj.find ) ) );
  1868. }
  1869.  
  1870. function isFunction( functionToCheck ){
  1871. var getType = {};
  1872. return functionToCheck && getType.toString.call( functionToCheck ) === '[object Function]';
  1873. }
  1874. function isNumeric( value ){
  1875. return /^\d+$/.test( value );
  1876. }
  1877. function is_Numeric(n) {
  1878. return !isNaN(parseFloat(n)) && isFinite(n);
  1879. }
  1880.  
  1881. function parse_Boolean( Boolean, onNull, nullIs ) {
  1882. var falsely = /^(?:f(?:alse)?|no?|off?|n?|failure?|sudumoo?|0+)$/i,
  1883. truely = /^(?:t(?:rue)?|yes?|on?|y?|success?|yabbdoo?|1+)$/i;
  1884.  
  1885. //noinspection JSUnresolvedVariable
  1886. return truely.test( Boolean ) === !!Boolean ? true : falsely.test( Boolean ) === !!Boolean ? false
  1887. : !isNaN(parseFloat( Boolean )) && isFinite( Boolean ) ? true
  1888. : ( onNull || false ) ? bool == null ? nullIs : false : null;
  1889. }
  1890. function parseBoolean( Boolean , Type ) {
  1891. // http://stackoverflow.com/a/24744599
  1892. Type = Type || false;
  1893. var falsely = /^(?:f(?:alse)?|no?|0+)$/i,
  1894. truely = /^(?:t(?:rue)?|yes?|1+)$/i;
  1895. return Type ? !truely.test( Boolean ) && !!Boolean : !falsely.test( Boolean ) && !!Boolean;
  1896. }
  1897. function parseBooleanStyle( str, onNull, nullIs ){
  1898. onNull = onNull || false;
  1899. var bool, $this = this.toString().toLowerCase();
  1900. switch( $this ){
  1901. case 'true':
  1902. case '1':
  1903. case 'on':
  1904. case 'y':
  1905. case 'yes':
  1906. bool = true;
  1907. break;
  1908. case 'false':
  1909. case '0':
  1910. case 'off':
  1911. case 'n':
  1912. case 'no':
  1913. bool = false;
  1914. break;
  1915. default:
  1916. bool = typeof bool === 'boolean' ? bool : null;
  1917. break;
  1918. }
  1919. return ( onNull || false ) && ( bool == null && nullIs || false ) || parseInt( $this ) !== 0 || bool;
  1920. }
  1921.  
  1922. /**
  1923. * Search for correct object in array and return it.
  1924. * @function getObjKeyVal
  1925. * @param {Array} array - The array you wanna search trough
  1926. * @param {string} findKey - The key to search for
  1927. * @param {string} exactValue - Check correct key is found
  1928. * @param {string} [getObjKeyVal] - get a key value in that object
  1929. */
  1930. function getObjKeyVal( array, findKey, exactValue, getObjKeyVal ){
  1931. var obj, node;
  1932. for( node in array )
  1933. for( findKey in obj = array[ node ] )
  1934. if( obj.hasOwnProperty( findKey ) && obj[ findKey ] == exactValue )
  1935. return getObjKeyVal || false ? obj[ getObjKeyVal ] : obj;
  1936. return false;
  1937. }
  1938. /**
  1939. * Search for all matched objects in array and return those.
  1940. * @function getAllMatchedObj
  1941. * @param {Array} array - The array you wanna search trough
  1942. * @param {string} findKey - The key to search for
  1943. * @param {string} exactValue - Check correct key found
  1944. */
  1945. function getAllMatchedObj( array, findKey, exactValue ){
  1946. var newArr = [], obj, node;
  1947. for( node in array )
  1948. for( findKey in obj = array[ node ] )
  1949. if( obj.hasOwnProperty( findKey ) && obj[ findKey ] == exactValue ) newArr.push( obj );
  1950. return newArr;
  1951. }
  1952. /**
  1953. * Search for all matched objects in array and return those.
  1954. * @function getAllMatchedObjByObject
  1955. * @param {Array} mainArray - The array you wanna search trough
  1956. * @param {Array} filterObject - Is one array object to match object in main array,
  1957. * this object has multiple keys one each for a search criteria example "{ joined:'2012', rank:5, gender:'female' }"
  1958. */
  1959. function getAllMatchedObjByObject( mainArray, filterObject ){
  1960. var newArr = [], objectCount = 0, mainLen = mainArray.length, mainObj, filterLen;
  1961. for ( objectCount; objectCount != mainLen; objectCount++ ){
  1962.  
  1963. mainObj = mainArray[ objectCount ];
  1964. filterLen = Object.keys( filterObject ).length;
  1965.  
  1966. Object.keys( filterObject ).forEach( function( filterKey, index ){
  1967. mainObj.hasOwnProperty( filterKey ) && mainObj[ filterKey ] == filterObject[ filterKey ] && ++index === filterLen && newArr.push( mainObj );
  1968. });
  1969. }
  1970. return newArr;
  1971. }
  1972. /**
  1973. * Do something with an array then return it
  1974. * @function arrayDo
  1975. * @param {string} what - what function is going to be used on an array
  1976. * @param {(string|string[])} array - The array you wanna search trough
  1977. * @param {string} findKey - The key to search for
  1978. * @param {string} [keyValue] - Check correct key found
  1979. * @param {string} [getKeyVal] - Get a key value from correct object found, or add in conjunction with newVal
  1980. * @param {string} [newVal] - Set a new Value to a key
  1981. */
  1982. function arrayDo( what, array, findKey, keyValue, getKeyVal, newVal) {
  1983.  
  1984. what = what === 'newKey' ? 'updateKey' : what;
  1985. /*
  1986. index = array.findIndex( function( obj ){
  1987. return obj.hasOwnProperty( findKey ) && obj[ findKey ] === keyValue;
  1988. })
  1989. */
  1990. var index = -1, i=0, len = array.length;
  1991.  
  1992. // if( !!~$.inArray( doWhat, ['allMatched','add','sort'] ) === true )
  1993. for ( i; i != len ; i++ ) {
  1994. var obj = array[ i ];
  1995. if( obj.hasOwnProperty( findKey ) && obj[ findKey ] === keyValue ){
  1996. c.i('inArray',obj[ findKey ]);
  1997. index = i;
  1998. break;
  1999. }
  2000. }
  2001.  
  2002. var object = array[ index ],
  2003. doWhat = {
  2004. find : function(){
  2005. array = object;
  2006. },
  2007. remove : function(){
  2008. index !== -1 && array.splice( index, 1 );
  2009. },
  2010. keyVal : function(){
  2011. var obj = object[ getKeyVal ];
  2012. array = obj !== undefined ? obj : '';
  2013. },
  2014. updateKey : function(){ //newKey
  2015. /* c.i('updateKey array ', JSON.stringify( array ) )
  2016. c.i('updateKey index ', index )
  2017. c.i('updateKey Value ', keyValue)
  2018. c.i('updateKey newVal', newVal )
  2019. c.i('getKeyVal before', array[ index ] )
  2020. c.i('updateKey', '____________________')
  2021. */
  2022. index !== -1 && ( array[ index ][ getKeyVal ] = newVal );
  2023. // c.i('getKeyVal after ', array[ index ] )
  2024. },
  2025. deleteKey : function(){
  2026. index !== -1 && delete array[ index ][ getKeyVal ];
  2027. },
  2028. add : function(){
  2029. array.push( newVal );
  2030. },
  2031. sort : function(){
  2032. array.sort( sortBy( findKey, keyValue ) );
  2033. },
  2034. allMatched : function(){
  2035. var newArr = [], i = 0,
  2036. secondMatch = ( getKeyVal !== undefined && newVal !== undefined );
  2037.  
  2038. for ( i; i != len; i++ ) {
  2039. var obj = array[ i ];
  2040. ( obj.hasOwnProperty( findKey ) && obj[ findKey ] === keyValue )
  2041. && ( secondMatch ? ( obj.hasOwnProperty( getKeyVal ) && obj[ getKeyVal ] === newVal ) : true )
  2042. && newArr.push( obj );
  2043. }
  2044.  
  2045. array = newArr;
  2046. }
  2047. };
  2048.  
  2049. doWhat[ what ]();
  2050. return array;
  2051. }
  2052.  
  2053. function getsComputedStyle( style, elem ) {
  2054. elem = elem || 'body';
  2055. return window.getComputedStyle( document[ elem ] )[ style ] !== undefined;
  2056. }
  2057. function isPropertySupported( property, elem ){
  2058. elem = elem || 'body';
  2059. return property in document[ elem ].style;
  2060. }
  2061. function cssPropertyValueSupported( prop, value, elem ) {
  2062. //cssPropertyValueSupported('width', '1px');
  2063. elem = elem || 'div';
  2064. var d = document.createElement( elem );
  2065. d.style[ prop ] = value;
  2066. return d.style[ prop ] === value;
  2067. }
  2068.  
  2069. var cssSupports = (function(){
  2070. // http://code.tutsplus.com/tutorials/quick-tip-detect-css3-support-in-browsers-with-javascript--net-16444
  2071. /*
  2072. if ( supports('textShadow') ) {
  2073. document.documentElement.className += ' textShadow';
  2074. }
  2075. */
  2076. var div = document.createElement('div'),
  2077. vendors = 'Khtml Ms O Moz Webkit'.split(' '),
  2078. len = vendors.length;
  2079.  
  2080. return function(prop) {
  2081. if ( prop in div.style ) return true;
  2082.  
  2083. prop = prop.replace(/^[a-z]/, function(val) {
  2084. return val.toUpperCase();
  2085. });
  2086.  
  2087. while(len--) {
  2088. if ( vendors[len] + prop in div.style ) {
  2089. // browser supports box-shadow. Do what you need.
  2090. // Or use a bang (!) to test if the browser doesn't.
  2091. return true;
  2092. }
  2093. }
  2094. return false;
  2095. };
  2096. })();
  2097.  
  2098. function toggleClassState( config, Class, state, elem ){
  2099. config === undefined ? window.config = {} : config;
  2100. config = config || ( window.config = {} );
  2101.  
  2102. config[ Class ] = typeof state === 'string' ? !config[ Class ] : state;
  2103. $( elem || 'html' )[ config[ Class ] ? 'addClass' : 'removeClass' ]( Class );
  2104. $( elem || 'html' ).attr('class');
  2105. }
  2106. function filterClick( e, $this ){
  2107. return e.which == 1 && e.target == $this;
  2108. }
  2109. function dispatchEventResize() {
  2110. //noinspection JSClosureCompilerSyntax,JSUnresolvedFunction
  2111. window.dispatchEvent(new Event('resize'));
  2112. }
  2113.  
  2114. /**
  2115. * @return {string}
  2116. */
  2117. function Undefined( check, replace ){
  2118. return check === undefined ? replace.toString() : check.toString();
  2119. }
  2120. function checkJqueryUI( maxCount, timeout, module ){
  2121. //noinspection JSUnresolvedVariable
  2122. if( typeof jQuery.ui != 'undefined' ){
  2123. //noinspection JSUnresolvedVariable
  2124. return module != undefined ? typeof jQuery.ui[ module ] != 'undefined' : true; }
  2125. else
  2126. setTimeout(function(){
  2127. if( counter.setGet('chkJQ') > maxCount ){
  2128. counter.del('chkJQ');
  2129. return false;
  2130. }
  2131. else checkJqueryUI( maxCount, timeout );
  2132. }, timeout );
  2133. }
  2134.  
  2135. function getGlobal(){
  2136. return (function(){
  2137. return this;
  2138. })();
  2139. }
  2140. function GM_lister( remove, item ){
  2141. var keys = GM_listValues();
  2142. for (var i = 0, key = null; key = keys[i]; i++) {
  2143. GM_listValues()[i] !== undefined && (
  2144. c.i('GM_ListItem: ' + GM_listValues()[i] + ':', GM_getValue(key)),
  2145. ( ( item !== undefined && GM_listValues()[i].inElem( item ) ) || item === undefined )
  2146. && ( remove === true || remove === 'yes' || remove === 1 ) && GM_deleteValue(key));
  2147. }
  2148. }
  2149.  
  2150. function roundFloat( num, dec ){
  2151. var d = 1;
  2152. for ( var i=0; i<dec; i++ ){
  2153. d += "0";
  2154. }
  2155. return Math.round(num * d) / d;
  2156. }
  2157. function randomFloatBetween( min, max, dec ){
  2158. dec = typeof( dec ) == 'undefined' ? 2 : dec;
  2159. return parseFloat( Math.min( min + ( Math.random() * ( max - min ) ), max ).toFixed( dec ) );
  2160. }
  2161. function random( max ) {
  2162. var min = 1,
  2163. rand = function(){
  2164. return Math.floor( Math.random() * ( max - min + 1 ) + min );
  2165. },
  2166. num1 = rand(),
  2167. num2 = rand();
  2168.  
  2169. return ( num1 > num2 ? num2/num1 : num1/num2 ) * max;
  2170. }
  2171. function roundNearPeace( number, peaces, dec ) {
  2172. return ( Math.round( number * peaces ) / peaces ).toFixed( dec );
  2173. }
  2174.  
  2175. var w = window,
  2176. glob = w,
  2177. $w = $( w ),
  2178. $l = $( location ),
  2179. locDoc = window.location.href,
  2180. d = document,
  2181. $d = $( d ),
  2182.  
  2183. c = {
  2184. defaultState: 3,
  2185. cute : function( type, msg, color ) {
  2186. color = color || "black";
  2187. var newColor, bgc = "White";
  2188. switch ( color ) {
  2189. case "success": newColor = "Green"; bgc = "LimeGreen"; break;
  2190. case "info": newColor = "DodgerBlue"; bgc = "Turquoise"; break;
  2191. case "error": newColor = "Red"; bgc = "Black"; break;
  2192. case "start": newColor = "OliveDrab"; bgc = "PaleGreen"; break;
  2193. case "warning": newColor = "Tomato"; bgc = "Black"; break;
  2194. case "end": newColor = "Orchid"; bgc = "MediumVioletRed"; break;
  2195. default: //noinspection SillyAssignmentJS
  2196. newColor = color;
  2197. }
  2198.  
  2199. typeof msg == "object" ?
  2200. window.console[ type ]( msg )
  2201. : typeof color == "object" ? (
  2202. window.console[ type ]("%c" + msg, "color: PowderBlue;font-weight:bold; background-color: RoyalBlue;"),
  2203. window.console[ type ]( newColor )
  2204. ) :
  2205. window.console[ type ]("%c" + msg, "color:" + newColor + "; background-color: " + bgc + ";");
  2206. },
  2207. show: function( showThis, type ){
  2208. var State = GM_getValue( type + 'StateValue' ) || this.defaultState;
  2209. return showThis !== 0 && State !== 0 && State === ( showThis || State ) || State === 'all';
  2210. },
  2211. pre: function( type, name, fn, line, color ){
  2212. line = line == undefined ? '' : line + ': ';
  2213. /**
  2214. * @return {string}
  2215. */
  2216. var Fn = function(){ return fn !== undefined ? fn : ''; };
  2217. typeof fn == "object"
  2218. ? window.console[ type ]( name, Fn() )
  2219. : c.cute( type, line + name + ': ' + Fn(), color );
  2220. },
  2221. type: function( type, name, fn, line, color, showThis ){
  2222. this.show( showThis, type ) && this.pre( type, name, fn, line, color );
  2223. },
  2224. l: function( name, fn, line, color, showThis ){
  2225. this.type( 'log', name, fn, line, color, showThis );
  2226. },
  2227. h: function( name, fn, line, color, showThis ){
  2228. this.type( 'handled', name, fn, line, color, showThis );
  2229. },
  2230. //c.l('name', 'fn'=='fn', 'line', 'blue')
  2231. i: function( name, fn, line, color, showThis ){
  2232. this.type( 'info', name, fn, line, color, showThis );
  2233. },
  2234. d: function( name, fn, line, color, showThis ){
  2235. this.type( 'debug', name, fn, line, color, showThis );
  2236. }
  2237. },
  2238. localStorageObj = {
  2239. name : 'setName', //important
  2240. localArray : function(){
  2241. return window.localStorage.getItem( this.name );
  2242. },
  2243. getArray : function(){
  2244. return this.localArray() === null ? [] : JSON.parse( this.localArray() );
  2245. },
  2246. removeArray : function(){
  2247. window.localStorage.removeItem( this.name );
  2248. },
  2249. stringify : function( array ){
  2250. c.i('[stringify]', JSON.stringify(array) );
  2251. window.localStorage.setItem( this.name, JSON.stringify(array) );
  2252. },
  2253. check : function( key, value ){
  2254. var array = this.getArray();
  2255. return array.grepArrayObj('find', key, value );
  2256. },
  2257. viewConsole : function( json ){
  2258. var array = this.getArray();
  2259. // $.toJSON() --- https://github.com/Krinkle/jquery-json/blob/master/src/jquery.json.js
  2260. // array.join('\n');
  2261. c.d( this.name, array ); //debug mode important to make this work
  2262. c.i( this.name, json ? isFunction( $.toJSON() ) ? $.toJSON( array ) : JSON.stringify( array ) : array.toSource() );
  2263. },
  2264. addTo : function() {
  2265.  
  2266. },
  2267. add : function( key, value, obj ){
  2268. var array = this.getArray(),
  2269. inA = array.toString();
  2270. c.i('[check array 1]', inA );
  2271. this.check( array, key, value )
  2272. || (
  2273. array.push( obj ),
  2274. c.i('[Added Object into array]', obj ),
  2275. c.i('[check array 2]', array )
  2276. );
  2277. this.stringify( array );
  2278. },
  2279. remove : function( key, value, obj ){
  2280. var array = this.getArray();
  2281. this.check( array, key, value )
  2282. && (
  2283. array = array.grepArrayObj('remove', key, value ),
  2284. c.i('[Removed Object from array]', obj )
  2285. );
  2286. this.stringify( array );
  2287. }
  2288. },
  2289. booleanTimer = {
  2290. timers : [],
  2291. start : function( name, ms ){
  2292. var that = this, value = name,
  2293. stop = setTimeout(function(){
  2294. that.stop( value );
  2295. }, ms );
  2296. this.timers.push( { 'name': value, stop:stop } );
  2297. //setTimeout(function(){that.stop( value );}, ms );
  2298. },
  2299. check : function( value ){
  2300. return this.timers.grepArrayObj( 'find', 'name', value ) !== undefined;
  2301. },
  2302. stop : function( value ){
  2303. this.timers = this.timers.grepArrayObj( 'remove', 'name', value );
  2304. }
  2305. },
  2306. advTimer = {
  2307. timers : [],
  2308. start : function( name, ms ){
  2309. var that = this, value = name,
  2310. stop = setTimeout(function(){
  2311. that.stop( value );
  2312. }, ms );
  2313. //noinspection JSUnresolvedVariable
  2314. this.timers.push({ 'name':value, start:window.performance.now(), timeout:ms, stop:stop });
  2315. },
  2316. check : function( value ){
  2317. var findObj = this.timers.grepArrayObj( 'find', 'name', value );
  2318. //noinspection JSUnresolvedVariable
  2319. return findObj !== undefined
  2320. ? findObj.timeout - ( window.performance.now() - findObj.start )
  2321. : false;
  2322. },
  2323. stop : function( value ){
  2324. this.timers = this.timers.grepArrayObj( 'remove', 'name', value );
  2325. }
  2326. },
  2327. lap = {
  2328. data : {},
  2329. tid : function(){
  2330. //noinspection JSUnresolvedVariable
  2331. return performance.now();
  2332. },
  2333. set : function(name){
  2334. this.data[name] = this.tid();
  2335. },
  2336. get : function(name){
  2337. return this.tid() - this.data[name];
  2338. },
  2339. end : function(name){
  2340. this.print(name);
  2341. this.del(name);
  2342. },
  2343. del : function(name){
  2344. delete this.data[name];
  2345. },
  2346. print: function(name){
  2347. var get = this.get( name );
  2348. c.i( 'Lap: ' + name, isNaN( get ) ? 'There is no such a name ' : get + 'ms' );
  2349. }
  2350. },
  2351. timer = {
  2352. ms : 0,
  2353. set : function(ms){
  2354. var that = this;
  2355. this.ms = ms;
  2356. setTimeout(function(){
  2357. that.ms = 0;
  2358. }, ms );
  2359. }
  2360. },
  2361. counter = {
  2362. data : {},
  2363. setGet : function(name, decrease, reset) {
  2364.  
  2365. this.exists(name) && ( reset || false )
  2366. && this.set(name,0);
  2367.  
  2368. this.exists(name)
  2369. ? this[ ( decrease || false ) ? 'decrease' : 'increase' ](name)
  2370. : this.set(name);
  2371.  
  2372. return this.get(name);
  2373. },
  2374. set : function(name, start, base){
  2375. this.data[name] = start || 0;
  2376. this.data[name+'Default'] = base || 1;
  2377. },
  2378. get : function(name){
  2379. return this.data[name];
  2380. },
  2381. is : function(name, count){
  2382. return this.data[name] === count;
  2383. },
  2384. lessThen: function(name, count, equal ){
  2385. return ( equal || false ) ? this.data[name] <= count : this.data[name] < count;
  2386. },
  2387. moreThen: function(name, count, equal){
  2388. return ( equal || false ) ? this.data[name] >= count : this.data[name] > count;
  2389. },
  2390. del : function(name){
  2391. delete this.data[name];
  2392. },
  2393. exists : function(name) {
  2394. return this.data[name] !== undefined;
  2395. },
  2396. plus : function(name, num){
  2397. this.exists(name) || this.set(name);
  2398. this.data[name] = this.data[name] + ( num === undefined ? this.data[name+'Default'] : num );
  2399. },
  2400. minus : function(name, num){
  2401. this.exists(name) || this.set(name);
  2402. this.data[name] = this.data[name] - ( num === undefined ? this.data[name+'Default'] : num );
  2403. },
  2404. increase: function (name, num) {
  2405. this.plus(name, num);
  2406. },
  2407. decrease: function (name, num) {
  2408. this.minus(name, num);
  2409. },
  2410. '+' : function (name, num) {
  2411. this.plus(name, num);
  2412. },
  2413. '-' : function (name, num) {
  2414. this.minus(name, num);
  2415. },
  2416. up : function (name, num) {
  2417. this.plus(name, num);
  2418. },
  2419. down : function (name, num) {
  2420. this.minus(name, num);
  2421. },
  2422. add : function (name, num) {
  2423. this.plus(name, num);
  2424. },
  2425. subtract: function (name, num) {
  2426. this.minus(name, num);
  2427. },
  2428. withdraw: function (name, num) {
  2429. this.minus(name, num);
  2430. }
  2431. },
  2432. g = {
  2433. locDoc : window.location.href,
  2434. ms : 0,
  2435. timer : function(ms){
  2436. g.ms = ms;
  2437. setTimeout(function(){ g.ms = 0; }, ms );
  2438. },
  2439.  
  2440. GM : {
  2441. engine : function( mode, val, range ){
  2442. switch (mode){
  2443. case 'set': GM_setValue( val.name, val.default );
  2444. break;
  2445. case 'get': range ? config[ val.name ] = GM_getValue( val.name ):
  2446. ui.config[ val.name ] = GM_getValue( val.name );
  2447. break;
  2448. case 'del': GM_deleteValue( val.name );
  2449. }
  2450. },
  2451. manager : function( mode, array, range ){
  2452. $.each( array, function( i, val ){ this.engine( mode, val, range === undefined ); });
  2453. mode === 'del' && ( GM_deleteValue( 'firstRun' ), GM_deleteValue( 'yourVer' ) );
  2454. }
  2455. }
  2456. },
  2457.  
  2458. testPerformance = function( name, fn, testCycles ) {
  2459. lap.set( name );
  2460. var i = 0;
  2461. for ( i ; i < testCycles; i++ ){
  2462. fn();
  2463. }
  2464. lap.end( name );
  2465. },
  2466. perf = function (testName, fn) {
  2467. var startTime = new Date().getTime();
  2468. fn();
  2469. var endTime = new Date().getTime();
  2470. console.log( testName + ": " + ( endTime - startTime ) + "ms" );
  2471. };
  2472.  
  2473. $(document).on('click','*',function(e){
  2474. this == e.target && c.i('target:', $(this)[0] );
  2475. });
  2476.  
  2477. c.i('my Function Library ÖÖö');
  2478. /*
  2479. isScrolledIntoView = (elem) ->
  2480. docViewTop = $(window).scrollTop()
  2481. docViewBottom = docViewTop + $(window).height()
  2482. elemTop = $(elem).offset().top
  2483. elemBottom = elemTop + $(elem).height()
  2484.  
  2485. (elemBottom - 200 < docViewBottom) and (elemBottom + $(elem).height() > docViewBottom )
  2486. */
  2487.  
  2488.