Favicon

favicon

目前为 2017-09-27 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果你需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/33559/220795/Favicon.js

  1. // ==UserScript==
  2. // @author Miroslav Magda, http://blog.ejci.net
  3. // @name Favicon
  4. // @namespace http://teknoizdirap.com
  5. // @description favicon
  6. // @include https://teknoseyir.com/*
  7. // @version 1.0
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**
  12. * @license MIT or GPL-2.0
  13. * @fileOverview Favico animations
  14. * @author Miroslav Magda, http://blog.ejci.net
  15. * @source: https://github.com/ejci/favico.js
  16. * @version 0.3.10
  17. */
  18.  
  19. /**
  20. * Create new favico instance
  21. * @param {Object} Options
  22. * @return {Object} Favico object
  23. * @example
  24. * var favico = new Favico({
  25. * bgColor : '#d00',
  26. * textColor : '#fff',
  27. * fontFamily : 'sans-serif',
  28. * fontStyle : 'bold',
  29. * type : 'circle',
  30. * position : 'down',
  31. * animation : 'slide',
  32. * elementId: false,
  33. * element: null,
  34. * dataUrl: function(url){},
  35. * win: window
  36. * });
  37. */
  38. (function () {
  39.  
  40. var Favico = (function (opt) {
  41. 'use strict';
  42. opt = (opt) ? opt : {};
  43. var _def = {
  44. bgColor: '#d00',
  45. textColor: '#fff',
  46. fontFamily: 'sans-serif', //Arial,Verdana,Times New Roman,serif,sans-serif,...
  47. fontStyle: 'bold', //normal,italic,oblique,bold,bolder,lighter,100,200,300,400,500,600,700,800,900
  48. type: 'circle',
  49. position: 'down', // down, up, left, leftup (upleft)
  50. animation: 'slide',
  51. elementId: false,
  52. element: null,
  53. dataUrl: false,
  54. win: window
  55. };
  56. var _opt, _orig, _h, _w, _canvas, _context, _img, _ready, _lastBadge, _running, _readyCb, _stop, _browser, _animTimeout, _drawTimeout, _doc;
  57.  
  58. _browser = {};
  59. _browser.ff = typeof InstallTrigger != 'undefined';
  60. _browser.chrome = !!window.chrome;
  61. _browser.opera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0;
  62. _browser.ie = /*@cc_on!@*/false;
  63. _browser.safari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
  64. _browser.supported = (_browser.chrome || _browser.ff || _browser.opera);
  65.  
  66. var _queue = [];
  67. _readyCb = function () {
  68. };
  69. _ready = _stop = false;
  70. /**
  71. * Initialize favico
  72. */
  73. var init = function () {
  74. //merge initial options
  75. _opt = merge(_def, opt);
  76. _opt.bgColor = hexToRgb(_opt.bgColor);
  77. _opt.textColor = hexToRgb(_opt.textColor);
  78. _opt.position = _opt.position.toLowerCase();
  79. _opt.animation = (animation.types['' + _opt.animation]) ? _opt.animation : _def.animation;
  80.  
  81. _doc = _opt.win.document;
  82.  
  83. var isUp = _opt.position.indexOf('up') > -1;
  84. var isLeft = _opt.position.indexOf('left') > -1;
  85.  
  86. //transform the animations
  87. if (isUp || isLeft) {
  88. for (var a in animation.types) {
  89. for (var i = 0; i < animation.types[a].length; i++) {
  90. var step = animation.types[a][i];
  91.  
  92. if (isUp) {
  93. if (step.y < 0.6) {
  94. step.y = step.y - 0.4;
  95. } else {
  96. step.y = step.y - 2 * step.y + (1 - step.w);
  97. }
  98. }
  99.  
  100. if (isLeft) {
  101. if (step.x < 0.6) {
  102. step.x = step.x - 0.4;
  103. } else {
  104. step.x = step.x - 2 * step.x + (1 - step.h);
  105. }
  106. }
  107.  
  108. animation.types[a][i] = step;
  109. }
  110. }
  111. }
  112. _opt.type = (type['' + _opt.type]) ? _opt.type : _def.type;
  113.  
  114. _orig = link. getIcons();
  115. //create temp canvas
  116. _canvas = document.createElement('canvas');
  117. //create temp image
  118. _img = document.createElement('img');
  119. var lastIcon = _orig[_orig.length - 1];
  120. if (lastIcon.hasAttribute('href')) {
  121. _img.setAttribute('crossOrigin', 'anonymous');
  122. //get width/height
  123. _img.onload = function () {
  124. _h = (_img.height > 0) ? _img.height : 32;
  125. _w = (_img.width > 0) ? _img.width : 32;
  126. _canvas.height = _h;
  127. _canvas.width = _w;
  128. _context = _canvas.getContext('2d');
  129. icon.ready();
  130. };
  131. _img.setAttribute('src', lastIcon.getAttribute('href'));
  132. } else {
  133. _h = 32;
  134. _w = 32;
  135. _img.height = _h;
  136. _img.width = _w;
  137. _canvas.height = _h;
  138. _canvas.width = _w;
  139. _context = _canvas.getContext('2d');
  140. icon.ready();
  141. }
  142.  
  143. };
  144. /**
  145. * Icon namespace
  146. */
  147. var icon = {};
  148. /**
  149. * Icon is ready (reset icon) and start animation (if ther is any)
  150. */
  151. icon.ready = function () {
  152. _ready = true;
  153. icon.reset();
  154. _readyCb();
  155. };
  156. /**
  157. * Reset icon to default state
  158. */
  159. icon.reset = function () {
  160. //reset
  161. if (!_ready) {
  162. return;
  163. }
  164. _queue = [];
  165. _lastBadge = false;
  166. _running = false;
  167. _context.clearRect(0, 0, _w, _h);
  168. _context.drawImage(_img, 0, 0, _w, _h);
  169. //_stop=true;
  170. link.setIcon(_canvas);
  171. //webcam('stop');
  172. //video('stop');
  173. window.clearTimeout(_animTimeout);
  174. window.clearTimeout(_drawTimeout);
  175. };
  176. /**
  177. * Start animation
  178. */
  179. icon.start = function () {
  180. if (!_ready || _running) {
  181. return;
  182. }
  183. var finished = function () {
  184. _lastBadge = _queue[0];
  185. _running = false;
  186. if (_queue.length > 0) {
  187. _queue.shift();
  188. icon.start();
  189. } else {
  190.  
  191. }
  192. };
  193. if (_queue.length > 0) {
  194. _running = true;
  195. var run = function () {
  196. // apply options for this animation
  197. ['type', 'animation', 'bgColor', 'textColor', 'fontFamily', 'fontStyle'].forEach(function (a) {
  198. if (a in _queue[0].options) {
  199. _opt[a] = _queue[0].options[a];
  200. }
  201. });
  202. animation.run(_queue[0].options, function () {
  203. finished();
  204. }, false);
  205. };
  206. if (_lastBadge) {
  207. animation.run(_lastBadge.options, function () {
  208. run();
  209. }, true);
  210. } else {
  211. run();
  212. }
  213. }
  214. };
  215.  
  216. /**
  217. * Badge types
  218. */
  219. var type = {};
  220. var options = function (opt) {
  221. opt.n = ((typeof opt.n) === 'number') ? Math.abs(opt.n | 0) : opt.n;
  222. opt.x = _w * opt.x;
  223. opt.y = _h * opt.y;
  224. opt.w = _w * opt.w;
  225. opt.h = _h * opt.h;
  226. opt.len = ("" + opt.n).length;
  227. return opt;
  228. };
  229. /**
  230. * Generate circle
  231. * @param {Object} opt Badge options
  232. */
  233. type.circle = function (opt) {
  234. opt = options(opt);
  235. var more = false;
  236. if (opt.len === 2) {
  237. opt.x = opt.x - opt.w * 0.4;
  238. opt.w = opt.w * 1.4;
  239. more = true;
  240. } else if (opt.len >= 3) {
  241. opt.x = opt.x - opt.w * 0.65;
  242. opt.w = opt.w * 1.65;
  243. more = true;
  244. }
  245. _context.clearRect(0, 0, _w, _h);
  246. _context.drawImage(_img, 0, 0, _w, _h);
  247. _context.beginPath();
  248. _context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.85 : 1)) + "px " + _opt.fontFamily;
  249. _context.textAlign = 'center';
  250. if (more) {
  251. _context.moveTo(opt.x + opt.w / 2, opt.y);
  252. _context.lineTo(opt.x + opt.w - opt.h / 2, opt.y);
  253. _context.quadraticCurveTo(opt.x + opt.w, opt.y, opt.x + opt.w, opt.y + opt.h / 2);
  254. _context.lineTo(opt.x + opt.w, opt.y + opt.h - opt.h / 2);
  255. _context.quadraticCurveTo(opt.x + opt.w, opt.y + opt.h, opt.x + opt.w - opt.h / 2, opt.y + opt.h);
  256. _context.lineTo(opt.x + opt.h / 2, opt.y + opt.h);
  257. _context.quadraticCurveTo(opt.x, opt.y + opt.h, opt.x, opt.y + opt.h - opt.h / 2);
  258. _context.lineTo(opt.x, opt.y + opt.h / 2);
  259. _context.quadraticCurveTo(opt.x, opt.y, opt.x + opt.h / 2, opt.y);
  260. } else {
  261. _context.arc(opt.x + opt.w / 2, opt.y + opt.h / 2, opt.h / 2, 0, 2 * Math.PI);
  262. }
  263. _context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')';
  264. _context.fill();
  265. _context.closePath();
  266. _context.beginPath();
  267. _context.stroke();
  268. _context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')';
  269. //_context.fillText((more) ? '9+' : opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
  270. if ((typeof opt.n) === 'number' && opt.n > 999) {
  271. _context.fillText(((opt.n > 9999) ? 9 : Math.floor(opt.n / 1000)) + 'k+', Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.2));
  272. } else {
  273. _context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
  274. }
  275. _context.closePath();
  276. };
  277. /**
  278. * Generate rectangle
  279. * @param {Object} opt Badge options
  280. */
  281. type.rectangle = function (opt) {
  282. opt = options(opt);
  283. var more = false;
  284. if (opt.len === 2) {
  285. opt.x = opt.x - opt.w * 0.4;
  286. opt.w = opt.w * 1.4;
  287. more = true;
  288. } else if (opt.len >= 3) {
  289. opt.x = opt.x - opt.w * 0.65;
  290. opt.w = opt.w * 1.65;
  291. more = true;
  292. }
  293. _context.clearRect(0, 0, _w, _h);
  294. _context.drawImage(_img, 0, 0, _w, _h);
  295. _context.beginPath();
  296. _context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.9 : 1)) + "px " + _opt.fontFamily;
  297. _context.textAlign = 'center';
  298. _context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')';
  299. _context.fillRect(opt.x, opt.y, opt.w, opt.h);
  300. _context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')';
  301. //_context.fillText((more) ? '9+' : opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
  302. if ((typeof opt.n) === 'number' && opt.n > 999) {
  303. _context.fillText(((opt.n > 9999) ? 9 : Math.floor(opt.n / 1000)) + 'k+', Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.2));
  304. } else {
  305. _context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
  306. }
  307. _context.closePath();
  308. };
  309.  
  310. /**
  311. * Set badge
  312. */
  313. var badge = function (number, opts) {
  314. opts = ((typeof opts) === 'string' ? {
  315. animation: opts
  316. } : opts) || {};
  317. _readyCb = function () {
  318. try {
  319. if (typeof (number) === 'number' ? (number > 0) : (number !== '')) {
  320. var q = {
  321. type: 'badge',
  322. options: {
  323. n: number
  324. }
  325. };
  326. if ('animation' in opts && animation.types['' + opts.animation]) {
  327. q.options.animation = '' + opts.animation;
  328. }
  329. if ('type' in opts && type['' + opts.type]) {
  330. q.options.type = '' + opts.type;
  331. }
  332. ['bgColor', 'textColor'].forEach(function (o) {
  333. if (o in opts) {
  334. q.options[o] = hexToRgb(opts[o]);
  335. }
  336. });
  337. ['fontStyle', 'fontFamily'].forEach(function (o) {
  338. if (o in opts) {
  339. q.options[o] = opts[o];
  340. }
  341. });
  342. _queue.push(q);
  343. if (_queue.length > 100) {
  344. throw new Error('Too many badges requests in queue.');
  345. }
  346. icon.start();
  347. } else {
  348. icon.reset();
  349. }
  350. } catch (e) {
  351. throw new Error('Error setting badge. Message: ' + e.message);
  352. }
  353. };
  354. if (_ready) {
  355. _readyCb();
  356. }
  357. };
  358.  
  359. /**
  360. * Set image as icon
  361. */
  362. var image = function (imageElement) {
  363. _readyCb = function () {
  364. try {
  365. var w = imageElement.width;
  366. var h = imageElement.height;
  367. var newImg = document.createElement('img');
  368. var ratio = (w / _w < h / _h) ? (w / _w) : (h / _h);
  369. newImg.setAttribute('crossOrigin', 'anonymous');
  370. newImg.onload=function(){
  371. _context.clearRect(0, 0, _w, _h);
  372. _context.drawImage(newImg, 0, 0, _w, _h);
  373. link.setIcon(_canvas);
  374. };
  375. newImg.setAttribute('src', imageElement.getAttribute('src'));
  376. newImg.height = (h / ratio);
  377. newImg.width = (w / ratio);
  378. } catch (e) {
  379. throw new Error('Error setting image. Message: ' + e.message);
  380. }
  381. };
  382. if (_ready) {
  383. _readyCb();
  384. }
  385. };
  386. /**
  387. * Set the icon from a source url. Won't work with badges.
  388. */
  389. var rawImageSrc = function (url) {
  390. _readyCb = function() {
  391. link.setIconSrc(url);
  392. };
  393. if (_ready) {
  394. _readyCb();
  395. }
  396. };
  397. /**
  398. * Set video as icon
  399. */
  400. var video = function (videoElement) {
  401. _readyCb = function () {
  402. try {
  403. if (videoElement === 'stop') {
  404. _stop = true;
  405. icon.reset();
  406. _stop = false;
  407. return;
  408. }
  409. //var w = videoElement.width;
  410. //var h = videoElement.height;
  411. //var ratio = (w / _w < h / _h) ? (w / _w) : (h / _h);
  412. videoElement.addEventListener('play', function () {
  413. drawVideo(this);
  414. }, false);
  415.  
  416. } catch (e) {
  417. throw new Error('Error setting video. Message: ' + e.message);
  418. }
  419. };
  420. if (_ready) {
  421. _readyCb();
  422. }
  423. };
  424. /**
  425. * Set video as icon
  426. */
  427. var webcam = function (action) {
  428. //UR
  429. if (!window.URL || !window.URL.createObjectURL) {
  430. window.URL = window.URL || {};
  431. window.URL.createObjectURL = function (obj) {
  432. return obj;
  433. };
  434. }
  435. if (_browser.supported) {
  436. var newVideo = false;
  437. navigator.getUserMedia = navigator.getUserMedia || navigator.oGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
  438. _readyCb = function () {
  439. try {
  440. if (action === 'stop') {
  441. _stop = true;
  442. icon.reset();
  443. _stop = false;
  444. return;
  445. }
  446. newVideo = document.createElement('video');
  447. newVideo.width = _w;
  448. newVideo.height = _h;
  449. navigator.getUserMedia({
  450. video: true,
  451. audio: false
  452. }, function (stream) {
  453. newVideo.src = URL.createObjectURL(stream);
  454. newVideo.play();
  455. drawVideo(newVideo);
  456. }, function () {
  457. });
  458. } catch (e) {
  459. throw new Error('Error setting webcam. Message: ' + e.message);
  460. }
  461. };
  462. if (_ready) {
  463. _readyCb();
  464. }
  465. }
  466.  
  467. };
  468.  
  469. var setOpt = function (key, value) {
  470. var opts = key;
  471. if (!(value == null && Object.prototype.toString.call(key) == '[object Object]')) {
  472. opts = {};
  473. opts[key] = value;
  474. }
  475.  
  476. var keys = Object.keys(opts);
  477. for (var i = 0; i < keys.length; i++) {
  478. if (keys[i] == 'bgColor' || keys[i] == 'textColor') {
  479. _opt[keys[i]] = hexToRgb(opts[keys[i]]);
  480. } else {
  481. _opt[keys[i]] = opts[keys[i]];
  482. }
  483. }
  484.  
  485. _queue.push(_lastBadge);
  486. icon.start();
  487. };
  488.  
  489. /**
  490. * Draw video to context and repeat :)
  491. */
  492. function drawVideo(video) {
  493. if (video.paused || video.ended || _stop) {
  494. return false;
  495. }
  496. //nasty hack for FF webcam (Thanks to Julian Ćwirko, kontakt@redsunmedia.pl)
  497. try {
  498. _context.clearRect(0, 0, _w, _h);
  499. _context.drawImage(video, 0, 0, _w, _h);
  500. } catch (e) {
  501.  
  502. }
  503. _drawTimeout = setTimeout(function () {
  504. drawVideo(video);
  505. }, animation.duration);
  506. link.setIcon(_canvas);
  507. }
  508.  
  509. var link = {};
  510. /**
  511. * Get icons from HEAD tag or create a new <link> element
  512. */
  513. link.getIcons = function () {
  514. var elms = [];
  515. //get link element
  516. var getLinks = function () {
  517. var icons = [];
  518. var links = _doc.getElementsByTagName('head')[0].getElementsByTagName('link');
  519. for (var i = 0; i < links.length; i++) {
  520. if ((/(^|\s)icon(\s|$)/i).test(links[i].getAttribute('rel'))) {
  521. icons.push(links[i]);
  522. }
  523. }
  524. return icons;
  525. };
  526. if (_opt.element) {
  527. elms = [_opt.element];
  528. } else if (_opt.elementId) {
  529. //if img element identified by elementId
  530. elms = [_doc.getElementById(_opt.elementId)];
  531. elms[0].setAttribute('href', elms[0].getAttribute('src'));
  532. } else {
  533. //if link element
  534. elms = getLinks();
  535. if (elms.length === 0) {
  536. elms = [_doc.createElement('link')];
  537. elms[0].setAttribute('rel', 'icon');
  538. _doc.getElementsByTagName('head')[0].appendChild(elms[0]);
  539. }
  540. }
  541. elms.forEach(function(item) {
  542. item.setAttribute('type', 'image/png');
  543. });
  544. return elms;
  545. };
  546. link.setIcon = function (canvas) {
  547. var url = canvas.toDataURL('image/png');
  548. link.setIconSrc(url);
  549. };
  550. link.setIconSrc = function (url) {
  551. if (_opt.dataUrl) {
  552. //if using custom exporter
  553. _opt.dataUrl(url);
  554. }
  555. if (_opt.element) {
  556. _opt.element.setAttribute('href', url);
  557. _opt.element.setAttribute('src', url);
  558. } else if (_opt.elementId) {
  559. //if is attached to element (image)
  560. var elm = _doc.getElementById(_opt.elementId);
  561. elm.setAttribute('href', url);
  562. elm.setAttribute('src', url);
  563. } else {
  564. //if is attached to fav icon
  565. if (_browser.ff || _browser.opera) {
  566. //for FF we need to "recreate" element, atach to dom and remove old <link>
  567. //var originalType = _orig.getAttribute('rel');
  568. var old = _orig[_orig.length - 1];
  569. var newIcon = _doc.createElement('link');
  570. _orig = [newIcon];
  571. //_orig.setAttribute('rel', originalType);
  572. if (_browser.opera) {
  573. newIcon.setAttribute('rel', 'icon');
  574. }
  575. newIcon.setAttribute('rel', 'icon');
  576. newIcon.setAttribute('type', 'image/png');
  577. _doc.getElementsByTagName('head')[0].appendChild(newIcon);
  578. newIcon.setAttribute('href', url);
  579. if (old.parentNode) {
  580. old.parentNode.removeChild(old);
  581. }
  582. } else {
  583. _orig.forEach(function(icon) {
  584. icon.setAttribute('href', url);
  585. });
  586. }
  587. }
  588. };
  589.  
  590. //http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb#answer-5624139
  591. //HEX to RGB convertor
  592. function hexToRgb(hex) {
  593. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  594. hex = hex.replace(shorthandRegex, function (m, r, g, b) {
  595. return r + r + g + g + b + b;
  596. });
  597. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  598. return result ? {
  599. r: parseInt(result[1], 16),
  600. g: parseInt(result[2], 16),
  601. b: parseInt(result[3], 16)
  602. } : false;
  603. }
  604.  
  605. /**
  606. * Merge options
  607. */
  608. function merge(def, opt) {
  609. var mergedOpt = {};
  610. var attrname;
  611. for (attrname in def) {
  612. mergedOpt[attrname] = def[attrname];
  613. }
  614. for (attrname in opt) {
  615. mergedOpt[attrname] = opt[attrname];
  616. }
  617. return mergedOpt;
  618. }
  619.  
  620. /**
  621. * Cross-browser page visibility shim
  622. * http://stackoverflow.com/questions/12536562/detect-whether-a-window-is-visible
  623. */
  624. function isPageHidden() {
  625. return _doc.hidden || _doc.msHidden || _doc.webkitHidden || _doc.mozHidden;
  626. }
  627.  
  628. /**
  629. * @namespace animation
  630. */
  631. var animation = {};
  632. /**
  633. * Animation "frame" duration
  634. */
  635. animation.duration = 40;
  636. /**
  637. * Animation types (none,fade,pop,slide)
  638. */
  639. animation.types = {};
  640. animation.types.fade = [{
  641. x: 0.4,
  642. y: 0.4,
  643. w: 0.6,
  644. h: 0.6,
  645. o: 0.0
  646. }, {
  647. x: 0.4,
  648. y: 0.4,
  649. w: 0.6,
  650. h: 0.6,
  651. o: 0.1
  652. }, {
  653. x: 0.4,
  654. y: 0.4,
  655. w: 0.6,
  656. h: 0.6,
  657. o: 0.2
  658. }, {
  659. x: 0.4,
  660. y: 0.4,
  661. w: 0.6,
  662. h: 0.6,
  663. o: 0.3
  664. }, {
  665. x: 0.4,
  666. y: 0.4,
  667. w: 0.6,
  668. h: 0.6,
  669. o: 0.4
  670. }, {
  671. x: 0.4,
  672. y: 0.4,
  673. w: 0.6,
  674. h: 0.6,
  675. o: 0.5
  676. }, {
  677. x: 0.4,
  678. y: 0.4,
  679. w: 0.6,
  680. h: 0.6,
  681. o: 0.6
  682. }, {
  683. x: 0.4,
  684. y: 0.4,
  685. w: 0.6,
  686. h: 0.6,
  687. o: 0.7
  688. }, {
  689. x: 0.4,
  690. y: 0.4,
  691. w: 0.6,
  692. h: 0.6,
  693. o: 0.8
  694. }, {
  695. x: 0.4,
  696. y: 0.4,
  697. w: 0.6,
  698. h: 0.6,
  699. o: 0.9
  700. }, {
  701. x: 0.4,
  702. y: 0.4,
  703. w: 0.6,
  704. h: 0.6,
  705. o: 1.0
  706. }];
  707. animation.types.none = [{
  708. x: 0.4,
  709. y: 0.4,
  710. w: 0.6,
  711. h: 0.6,
  712. o: 1
  713. }];
  714. animation.types.pop = [{
  715. x: 1,
  716. y: 1,
  717. w: 0,
  718. h: 0,
  719. o: 1
  720. }, {
  721. x: 0.9,
  722. y: 0.9,
  723. w: 0.1,
  724. h: 0.1,
  725. o: 1
  726. }, {
  727. x: 0.8,
  728. y: 0.8,
  729. w: 0.2,
  730. h: 0.2,
  731. o: 1
  732. }, {
  733. x: 0.7,
  734. y: 0.7,
  735. w: 0.3,
  736. h: 0.3,
  737. o: 1
  738. }, {
  739. x: 0.6,
  740. y: 0.6,
  741. w: 0.4,
  742. h: 0.4,
  743. o: 1
  744. }, {
  745. x: 0.5,
  746. y: 0.5,
  747. w: 0.5,
  748. h: 0.5,
  749. o: 1
  750. }, {
  751. x: 0.4,
  752. y: 0.4,
  753. w: 0.6,
  754. h: 0.6,
  755. o: 1
  756. }];
  757. animation.types.popFade = [{
  758. x: 0.75,
  759. y: 0.75,
  760. w: 0,
  761. h: 0,
  762. o: 0
  763. }, {
  764. x: 0.65,
  765. y: 0.65,
  766. w: 0.1,
  767. h: 0.1,
  768. o: 0.2
  769. }, {
  770. x: 0.6,
  771. y: 0.6,
  772. w: 0.2,
  773. h: 0.2,
  774. o: 0.4
  775. }, {
  776. x: 0.55,
  777. y: 0.55,
  778. w: 0.3,
  779. h: 0.3,
  780. o: 0.6
  781. }, {
  782. x: 0.50,
  783. y: 0.50,
  784. w: 0.4,
  785. h: 0.4,
  786. o: 0.8
  787. }, {
  788. x: 0.45,
  789. y: 0.45,
  790. w: 0.5,
  791. h: 0.5,
  792. o: 0.9
  793. }, {
  794. x: 0.4,
  795. y: 0.4,
  796. w: 0.6,
  797. h: 0.6,
  798. o: 1
  799. }];
  800. animation.types.slide = [{
  801. x: 0.4,
  802. y: 1,
  803. w: 0.6,
  804. h: 0.6,
  805. o: 1
  806. }, {
  807. x: 0.4,
  808. y: 0.9,
  809. w: 0.6,
  810. h: 0.6,
  811. o: 1
  812. }, {
  813. x: 0.4,
  814. y: 0.9,
  815. w: 0.6,
  816. h: 0.6,
  817. o: 1
  818. }, {
  819. x: 0.4,
  820. y: 0.8,
  821. w: 0.6,
  822. h: 0.6,
  823. o: 1
  824. }, {
  825. x: 0.4,
  826. y: 0.7,
  827. w: 0.6,
  828. h: 0.6,
  829. o: 1
  830. }, {
  831. x: 0.4,
  832. y: 0.6,
  833. w: 0.6,
  834. h: 0.6,
  835. o: 1
  836. }, {
  837. x: 0.4,
  838. y: 0.5,
  839. w: 0.6,
  840. h: 0.6,
  841. o: 1
  842. }, {
  843. x: 0.4,
  844. y: 0.4,
  845. w: 0.6,
  846. h: 0.6,
  847. o: 1
  848. }];
  849. /**
  850. * Run animation
  851. * @param {Object} opt Animation options
  852. * @param {Object} cb Callabak after all steps are done
  853. * @param {Object} revert Reverse order? true|false
  854. * @param {Object} step Optional step number (frame bumber)
  855. */
  856. animation.run = function (opt, cb, revert, step) {
  857. var animationType = animation.types[isPageHidden() ? 'none' : _opt.animation];
  858. if (revert === true) {
  859. step = (typeof step !== 'undefined') ? step : animationType.length - 1;
  860. } else {
  861. step = (typeof step !== 'undefined') ? step : 0;
  862. }
  863. cb = (cb) ? cb : function () {
  864. };
  865. if ((step < animationType.length) && (step >= 0)) {
  866. type[_opt.type](merge(opt, animationType[step]));
  867. _animTimeout = setTimeout(function () {
  868. if (revert) {
  869. step = step - 1;
  870. } else {
  871. step = step + 1;
  872. }
  873. animation.run(opt, cb, revert, step);
  874. }, animation.duration);
  875.  
  876. link.setIcon(_canvas);
  877. } else {
  878. cb();
  879. return;
  880. }
  881. };
  882. //auto init
  883. init();
  884. return {
  885. badge: badge,
  886. video: video,
  887. image: image,
  888. rawImageSrc: rawImageSrc,
  889. webcam: webcam,
  890. setOpt: setOpt,
  891. reset: icon.reset,
  892. browser: {
  893. supported: _browser.supported
  894. }
  895. };
  896. });
  897.  
  898. // AMD / RequireJS
  899. if (typeof define !== 'undefined' && define.amd) {
  900. define([], function () {
  901. return Favico;
  902. });
  903. }
  904. // CommonJS
  905. else if (typeof module !== 'undefined' && module.exports) {
  906. module.exports = Favico;
  907. }
  908. // included directly via <script> tag
  909. else {
  910. this.Favico = Favico;
  911. }
  912.  
  913. })();