// ==UserScript== // @name u.js // @namespace http://zarjay.net/ // @description Utility functions for browser console ninjas // @include * // @version 0.23 // ==/UserScript== exec(function() { // Current version of u.js var VERSION = '0.22', // Predefined resources to be included via u.include(name) RESOURCES = { // resource: { css: [], js: [], script: [] } // Design - http://www.sprymedia.co.uk/article/Design // Grid layout, measurement, and alignment bookmarklet design: { js: ['http://www.sprymedia.co.uk/design/design/media/js/design-loader.js'] }, // DOM Monster - http://mir.aculo.us/dom-monster/ // Analyzes DOM and gives performance tips 'dom-monster': { js: ['//mir.aculo.us/dom-monster/dommonster.js'] }, // jQuery library - http://jquery.com/ // DOM manipulation, event handling, Ajax, etc. jquery: { js: ['//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'] }, // jQuery UI - http://jqueryui.com/ // UI/effects library 'jquery-ui': { css: ['//ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css'], js: ['//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js'] }, // Katamari Hack - http://kathack.com/ // Turns a webpage into a game of Katamari Damacy. Use your katamari ball to pick up DOM elements. katamari: { js: ['//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', 'http://kathack.com/js/kh.js'] }, // Kickass - https://kickassapp.com/ // Turn a webpage into a game of Asteroids. Use your ship to destroy DOM elements. kickass: { js: ['//hi.kickassapp.com/kickass.js'] }, // Lo-Dash - http://lodash.com/ // Underscore alternative (utility library) lodash: { js: ['//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js'] }, // Markup - http://markup.io // Draw on a webpage and share with others markup: { script: ["(function(){window.add_js=function(s){var k=(document.getElementsByTagName('head')[0]||document.body).appendChild(document.createElement('script'));k.src=s;k.type='text/javascript';k.markup='ea33cdc7-73dd-11e2-9673-fac11f1adc9e'};window.MarkUp=window.MarkUp||{};add_js('http://api.markup.io/bootstrap.js?v=1&'+(+(new Date)))})();"] }, // Moment.js - http://momentjs.com/ // Date library moment: { js: ['//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js'] }, // Raphael // SVG library raphael: { js: ['//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js'] }, // Stats - https://github.com/mrdoob/stats.js/ // FPS counter stats: { js: ['https://github.com/mrdoob/stats.js/raw/master/build/stats.min.js'], script: ['var interval=setInterval(function(){if(typeof Stats==\'function\'){clearInterval(interval);var stats=new Stats();stats.domElement.style.position=\'fixed\';stats.domElement.style.left=\'0px\';stats.domElement.style.top=\'0px\';stats.domElement.style.zIndex=\'10000\';document.body.appendChild(stats.domElement);setInterval(function(){stats.update();},1000/60);}},100);'] }, // Statsy Bookmarklet - http://www.phpied.com/statsy-more-data-points-for-markup-quality/ // Displays some DOM statistics statsy: { js: ['http://phpied.com/files/bookmarklets/somestats.js'] }, // Underscore - http://underscorejs.org/ // Utility library underscore: { js: ['//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js'] }, // What Font Bookmarklet - http://chengyinliu.com/whatfont.html // Identifies fonts whatfont: { js: ['http://chengyinliu.com/wf.js'] } }, // setInterval(function() { u.query('img').effect('rotate'); }, 3000); // u.query('img').effect('spin', 'random'); // They all spin at the same time // u.query('img').each(function(element) { element.effect('spin', 'random', Math.random() + 0.2); } ); // They all spin at different times // u.query('img').each(function(element) { element.effect('tilt', 5, Math.random() * (5 - 0.4 + 1) + 0.4); }); // They all spin at different times EFFECTS = { // u.effect('flip', 'z') flip: function(axis, speed) { // Default to flip on y-axis if undefined axis = axis || 'y'; // If undefined, default to 3s // If number, assume seconds and add 's' unit speed = speed || '3s'; if (!isNaN(speed)) speed += 's'; var transform = 'rotate' + axis.toUpperCase(); this.css('-webkit-transition', 'none'); this.css('-webkit-transform', transform + '(0deg)'); // Wait a bit before updating the same CSS properties setTimeout(function() { this.css('-webkit-transition', '-webkit-transform ' + speed); this.css('-webkit-transform', transform + '(180deg)'); }.bind(this), 0); }, // u.effect('rotate', '60deg', '4s') rotate: function(angle, speed) { // If number, add 'deg' unit // If undefined, default to random angle between -1080 and 1080 angle = !isNaN(angle) && angle !== null ? angle + 'deg' : angle ? angle : ( Math.floor( Math.random() * 1081 ) - 1080 + 'deg' ); // If undefined, default to 2s // If number, assume seconds and add 's' unit speed = speed || '2s'; if (!isNaN(speed)) speed += 's'; this.css('-webkit-transition', '-webkit-transform ' + speed); this.css('-webkit-transform', 'rotate(' + angle + ')'); }, // u.effect('spin', 'random') spin: function(option, speed) { var speedParts = /(\d+\.?\d*)(\D*)/.exec(speed), speedMs = speedParts[2] !== 'ms' ? speedParts[1] * 1000 : speedParts[1], angleIncrement = (option === 'backwards') ? -360 : (option === 'random') ? undefined : 360, angle = angleIncrement; fn = function() { this.effect('rotate', angle, speed); angle += angleIncrement; }, id = setInterval(fn.bind(this), speedMs); }, // u.effect('tilt', 5); // u.effect('tile', '5deg'); tilt: function(range, speed) { // If deg value (e.g., '5deg'), parse out number // If undefined, default to 5 range = parseInt(range || 5, 10); // If undefined, default to 3s // If number, assume seconds and add 's' unit speed = speed || '1s'; if (!isNaN(speed)) speed += 's'; var angleStart = 0 - range, angleEnd = 0 + range; var animation = addAnimation({ '0%': '-webkit-transform:rotate(' + angleStart + 'deg);', '50%': '-webkit-transform:rotate(' + angleEnd + 'deg);', '100%': '-webkit-transform:rotate(' + angleStart + 'deg);' }); this.css('-webkit-animation', animation + ' infinite ' + speed); } }, // Converts array-like objects to arrays slice = Function.prototype.call.bind(Array.prototype.slice), // Copies properties from the second object into the first object extend = function(dest, src) { for (var prop in src) dest[prop] = src[prop]; return dest; }, // Adds a