PageRenderTime 25ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/signet/0.4.5/signet.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 226 lines | 212 code | 14 blank | 0 comment | 36 complexity | f614c000cebdb60c40cdacb1032fdcdb MD5 | raw file
  1. (function() {
  2. var authors, deferConsole, drawLinks, drawSignet, getMetaList, links, measureTextWidth, supportsLogBackgroundImage, textFont, textFontSize, textLineHeight, _ref;
  3. if (((_ref = window.console) != null ? _ref.log : void 0) == null) {
  4. return;
  5. }
  6. getMetaList = function(name) {
  7. var content, element, _ref1;
  8. content = (_ref1 = document.head.querySelector("meta[name='" + name + "']")) != null ? _ref1.content : void 0;
  9. if (content) {
  10. return (function() {
  11. var _i, _len, _ref2, _results;
  12. _ref2 = content.split(',');
  13. _results = [];
  14. for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  15. element = _ref2[_i];
  16. _results.push(element.trim());
  17. }
  18. return _results;
  19. })();
  20. }
  21. return void 0;
  22. };
  23. authors = getMetaList('signet:authors');
  24. links = getMetaList('signet:links');
  25. textFont = '400 12px "Helvetica Neue", Helvetica, Arial, sans-serif';
  26. textFontSize = 12;
  27. textLineHeight = 16;
  28. supportsLogBackgroundImage = (function() {
  29. var isFF, isIE, isOpera, isSafari, operaSupport, safariSupport;
  30. isIE = function() {
  31. return /MSIE/.test(navigator.userAgent);
  32. };
  33. isFF = function() {
  34. return /Firefox/.test(navigator.userAgent);
  35. };
  36. isOpera = function() {
  37. return /OPR/.test(navigator.userAgent) && /Opera/.test(navigator.vendor);
  38. };
  39. isSafari = function() {
  40. return /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
  41. };
  42. safariSupport = function() {
  43. var m;
  44. m = navigator.userAgent.match(/AppleWebKit\/(\d+)\.(\d+)(\.|\+|\s)/);
  45. if (!m) {
  46. return false;
  47. }
  48. return 537.38 <= parseInt(m[1], 10) + (parseInt(m[2], 10) / 100);
  49. };
  50. operaSupport = function() {
  51. var m;
  52. m = navigator.userAgent.match(/OPR\/(\d+)\./);
  53. if (!m) {
  54. return false;
  55. }
  56. return 15 <= parseInt(m[1], 10);
  57. };
  58. return !isIE() && !isFF() && (!isOpera() || operaSupport()) && (!isSafari() || safariSupport());
  59. })();
  60. deferConsole = function(fn) {
  61. var callable, i, messages, old, type, types, _fn, _i, _len;
  62. types = ['log', 'debug', 'warn', 'error'];
  63. old = {};
  64. callable = {};
  65. messages = [];
  66. i = types.length;
  67. _fn = function(type) {
  68. old[type] = console[type];
  69. callable[type] = function() {
  70. return old[type].apply(console, arguments);
  71. };
  72. return console[type] = function() {
  73. messages.push([type, arguments]);
  74. return void 0;
  75. };
  76. };
  77. for (i = _i = 0, _len = types.length; _i < _len; i = ++_i) {
  78. type = types[i];
  79. _fn(type);
  80. }
  81. return setTimeout(function() {
  82. var block, message, _j, _len1, _results;
  83. for (_j = 0, _len1 = types.length; _j < _len1; _j++) {
  84. type = types[_j];
  85. console[type] = old[type];
  86. }
  87. fn();
  88. _results = [];
  89. while (messages.length) {
  90. block = messages.shift();
  91. type = block[0];
  92. message = block[1];
  93. _results.push(console[type].apply(console, message));
  94. }
  95. return _results;
  96. }, 0);
  97. };
  98. drawSignet = function() {
  99. var author, authorHeight, barHeight, barTop, barWidth, canvas, canvasHeight, canvasWidth, colors, context, drawRectangle, drawText, height, hue, i, imageCSS, individualBarLeft, individualBarWidth, j, leftOffsetHack, letter, lineHeightHack, repeatHack, _i, _j, _k, _len, _len1, _len2, _ref1;
  100. if (!(authors != null ? authors.length : void 0)) {
  101. return;
  102. }
  103. if (!supportsLogBackgroundImage) {
  104. console.log("Author" + (authors.length === 1 ? '' : 's') + ":");
  105. for (_i = 0, _len = authors.length; _i < _len; _i++) {
  106. author = authors[_i];
  107. console.log(author);
  108. }
  109. return;
  110. }
  111. canvasHeight = 480;
  112. canvasWidth = ((_ref1 = document.body) != null ? _ref1.clientWidth : void 0) || 480;
  113. authorHeight = 20;
  114. barHeight = authorHeight / 2;
  115. barWidth = 60;
  116. height = authors.length * authorHeight + 25;
  117. repeatHack = 14;
  118. lineHeightHack = -35;
  119. leftOffsetHack = -24;
  120. canvas = document.createElement('canvas');
  121. canvas.height = 1000;
  122. canvas.width = canvasWidth;
  123. context = canvas.getContext('2d');
  124. context.font = textFont;
  125. drawRectangle = function(left, top, width, height, color) {
  126. context.fillStyle = color;
  127. return context.fillRect(left, top + repeatHack, width, height);
  128. };
  129. drawText = function(text, top) {
  130. context.fillStyle = '#444';
  131. return context.fillText(text, barWidth + 10, top + repeatHack);
  132. };
  133. drawRectangle(0, -repeatHack, canvasWidth, height, 'white');
  134. for (i = _j = 0, _len1 = authors.length; _j < _len1; i = ++_j) {
  135. author = authors[i];
  136. drawText(author, (authorHeight * i) + 14);
  137. colors = author.replace(/\s/g, '');
  138. barTop = authorHeight * i + ((authorHeight - barHeight) / 2);
  139. for (j = _k = 0, _len2 = colors.length; _k < _len2; j = ++_k) {
  140. letter = colors[j];
  141. individualBarLeft = Math.floor((barWidth * j) / colors.length);
  142. individualBarWidth = Math.ceil(((barWidth * (j + 1)) / colors.length) - individualBarLeft);
  143. hue = ((letter.toLowerCase().charCodeAt(0) * 2) + (colors.toLowerCase().charCodeAt(0) * 5)) % 256;
  144. drawRectangle(individualBarLeft, barTop, individualBarWidth, barHeight, "hsl(" + hue + ", 80%, 80%)");
  145. }
  146. }
  147. imageCSS = "font-size: 0; line-height: " + (height + lineHeightHack) + "px; padding: " + (Math.floor(height / 2)) + "px " + canvasWidth + "px " + (Math.ceil(height / 2)) + "px 0; background-image: url(\"" + (canvas.toDataURL()) + "\"); margin-left: " + leftOffsetHack + "px";
  148. return console.log('%c ', imageCSS);
  149. };
  150. drawLinks = function() {
  151. var IMAGES, domain, domainPart, domainPartWidth, i, image, img, leftMargin, link, linksArgs, pathPart, pathPartWidth, whiteCoverWidth, _i, _j, _len, _len1;
  152. if (!(links != null ? links.length : void 0)) {
  153. return;
  154. }
  155. if (!supportsLogBackgroundImage) {
  156. for (_i = 0, _len = links.length; _i < _len; _i++) {
  157. link = links[_i];
  158. console.log(link);
  159. }
  160. return;
  161. }
  162. IMAGES = {
  163. 'twitter.com': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAGFBMVEWEu/Tf7fxirPK41vg3nPABj+4omO/+//+b16fMAAAAVklEQVR42lXNQRJEUQRDUSRh/ztu8QZd/46cokrMpz/zMR+CBSwrzFBLlbFDYYbdlLegxFq2crzlTu3MrH6p7hF0onDM4inGtJs+PaK0EdYdA8iD+ekHsEgEIt/uHNUAAAAASUVORK5CYII=',
  164. 'github.com': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAGFBMVEVCQUIsKyu8u7ugn6B7envc29wSERH+/v6nd/awAAAAWklEQVQIHT3BiQ0CQBDEsNkv6b9jEDphR70tqD01Ojyjcfgbc9C9M9sNl4Xz52BTxCdUYH0WAuuzkILz54rKUpnT68Dm2GV0+Lo4TJ820EanqrWhNert6c2pH7EtBBOlbNv9AAAAAElFTkSuQmCC',
  165. 'plus.google.com': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAFVBMVEXic2r88vHLOCDzzMnpoJvVDQDdSzg1eZqZAAAAWklEQVR42lXPORIDQAgDQV3o/082a5x4qhR0QADaajb1hRWy4bhyTEbHMb/rHzHJPIau3bdlG9MDksZSConCRlHFfr7bCTNTerodC+fYmrbTHtUk0I/SfXB9AElwAxEwF7nBAAAAAElFTkSuQmCC'
  166. };
  167. linksArgs = ['%c\n', 'line-height: 0; font-size: 0'];
  168. for (i = _j = 0, _len1 = links.length; _j < _len1; i = ++_j) {
  169. link = links[i];
  170. domainPart = link.replace(/(https?:\/\/[^\/]+(\/|$))(.*)/, '$1');
  171. pathPart = link.substr(domainPart.length);
  172. domainPartWidth = measureTextWidth(domainPart);
  173. pathPartWidth = measureTextWidth(pathPart);
  174. image = null;
  175. for (domain in IMAGES) {
  176. img = IMAGES[domain];
  177. if ((new RegExp("^(https?://)?(www\.)?" + domain + "/", 'i')).test(link)) {
  178. image = img;
  179. break;
  180. }
  181. }
  182. if (image) {
  183. linksArgs[0] += "%c" + link + "%c %c %c\n";
  184. leftMargin = -domainPartWidth;
  185. } else {
  186. linksArgs[0] += "%c" + link + "\n";
  187. leftMargin = 0;
  188. }
  189. linksArgs.push("-webkit-font-smoothing: antialiased; font: " + textFont + "; margin-left: " + leftMargin + "px");
  190. if (image) {
  191. whiteCoverWidth = 42;
  192. leftMargin = -pathPartWidth - whiteCoverWidth;
  193. linksArgs.push("background: #fff; line-height: " + textLineHeight + "px; padding: " + ((textLineHeight / 2) + 2) + "px " + (whiteCoverWidth / 2) + "px " + ((textLineHeight / 2) + 2) + "px " + (whiteCoverWidth / 2) + "px; font-size: 0; margin-left: " + leftMargin + "px");
  194. leftMargin = -(whiteCoverWidth / 2) + 2;
  195. linksArgs.push("background: #fff url(" + image + "); line-height: " + textLineHeight + "px; padding: 11px 14px 3px 0; font-size: 0; margin-left: " + leftMargin + "px");
  196. linksArgs.push('');
  197. }
  198. }
  199. return console.log.apply(console, linksArgs);
  200. };
  201. measureTextWidth = function(text) {
  202. var canvas, context;
  203. canvas = document.createElement('canvas');
  204. context = canvas.getContext('2d');
  205. context.font = textFont;
  206. return context.measureText(text).width;
  207. };
  208. deferConsole(function() {
  209. drawSignet();
  210. return drawLinks();
  211. });
  212. }).call(this);