GitHub Custom Emojis

Add custom emojis from json source

目前为 2016-03-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Custom Emojis
  3. // @version 0.1.6
  4. // @description Add custom emojis from json source
  5. // @namespace https://github.com/StylishThemes
  6. // @include /https?://((gist)\.)?github\.com/
  7. // @grant GM_addStyle
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_info
  12. // @run-at document-end
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
  14. // @require https://greasyfork.org/scripts/16936-ichord-caret-js/code/ichord-Caretjs.js?version=106431
  15. // @require https://greasyfork.org/scripts/16996-ichord-at-js-mod/code/ichord-Atjs-mod.js?version=109194
  16. // @require https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.2/js/ion.rangeSlider.min.js
  17. // ==/UserScript==
  18. /* global jQuery, GM_addStyle, GM_getValue, GM_setValue, GM_xmlhttpRequest, GM_info */
  19. /* eslint-disable indent, quotes */
  20. (function($) {
  21. 'use strict';
  22.  
  23. var ghe = {
  24.  
  25. version : GM_info.script.version,
  26.  
  27. vars : {
  28. // delay until package.json allowed to load
  29. delay : 8.64e7, // 24 hours in milliseconds
  30.  
  31. // base url to fetch package.json
  32. root : 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/',
  33. emojiClass : 'ghe-custom-emoji',
  34. emojiTemplate : ':_${name}:',
  35. maxEmojiZoom : 3,
  36. maxEmojiHeight : 150,
  37.  
  38. // Keyboard shortcut to open panel
  39. keyboardOpen : 'g+=',
  40. keyboardDelay : 1000
  41. },
  42.  
  43. regex : {
  44. // nodes to skip while traversing the dom
  45. skipElm : /^(script|style|svg|iframe|br|meta|link|textarea|input|code|pre)$/i,
  46. // emoji template
  47. template : /\$\{name\}/,
  48. // character to escape in regex
  49. charsToEsc : /[-\/\\^$*+?.()|[\]{}]/g
  50. },
  51.  
  52. defaults : {
  53. activeZoom : 1.8,
  54. caseSensitive : false,
  55. rangeHeight : '20;40', // min;max as set by ion.rangeSlider
  56. insertAsImage : false,
  57. // emoji json sources
  58. sources : [
  59. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-custom.json',
  60. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-crazy-rabbit.json',
  61. 'https://raw.githubusercontent.com/StylishThemes/GitHub-Custom-Emojis/master/collections/emoji-onion-head.json'
  62. ]
  63. },
  64.  
  65. // emoji json stored here
  66. collections : {},
  67.  
  68. // GitHub ajax containers
  69. containers : [
  70. '#js-pjax-container',
  71. '#js-repo-pjax-container',
  72. '.js-contribution-activity',
  73. '.more-repos'
  74. ],
  75.  
  76. // mutant observers to disconnect after ajax load
  77. previewObserver : [],
  78. // promises used when loading JSON
  79. promises : {},
  80.  
  81. getStoredValues : function() {
  82. var defaults = this.defaults;
  83. this.settings = {
  84. rangeHeight : GM_getValue('rangeHeight', defaults.rangeHeight),
  85. activeZoom : GM_getValue('activeZoom', defaults.activeZoom),
  86. caseSensitive : GM_getValue('caseSensitive', defaults.caseSensitive),
  87. insertAsImage : GM_getValue('insertAsImage', defaults.insertAsImage),
  88. sources : GM_getValue('sources', defaults.sources),
  89.  
  90. date : GM_getValue('date', 0)
  91. };
  92.  
  93. this.collections = GM_getValue('collections', {});
  94.  
  95. debug('Retrieved stored values', this.settings);
  96. },
  97.  
  98. storeVal : function(key, set, $el) {
  99. var tmp,
  100. val = set[key];
  101. GM_setValue(key, val);
  102. if (typeof val === 'boolean') {
  103. $el.prop('checked', val);
  104. } else {
  105. $el.val(val);
  106. }
  107. // update sliders
  108. if ($el.hasClass('ghe-height')) {
  109. tmp = val.split(';');
  110. $el.data('ionRangeSlider').update({
  111. from: tmp[0],
  112. to: tmp[1]
  113. });
  114. } else if ($el.hasClass('ghe-zoom')) {
  115. $el.data('ionRangeSlider').update({
  116. from: val
  117. });
  118. }
  119. },
  120.  
  121. setStoredValues : function(reset) {
  122. var $el, tmp, len, indx,
  123. s = ghe.settings,
  124. d = ghe.defaults,
  125. $panel = $('#ghe-settings-inner');
  126.  
  127. ghe.busy = true;
  128. ghe.storeVal('caseSensitive', reset ? d : s, $panel.find('.ghe-case'));
  129. ghe.storeVal('insertAsImage', reset ? d : s, $panel.find('.ghe-image'));
  130. ghe.storeVal('activeZoom', reset ? d : s, $panel.find('.ghe-zoom'));
  131. ghe.storeVal('rangeHeight', reset ? d : s, $panel.find('.ghe-height'));
  132.  
  133. GM_setValue('collections', this.collections);
  134. GM_setValue('date', s.date);
  135.  
  136. if (reset) {
  137. // add defaults back into source list; but don't remove any new stuff
  138. len = d.sources.length;
  139. for (indx = 0; indx < len; indx++) {
  140. if (s.sources.indexOf(d.sources[indx]) < 0) {
  141. s.sources[s.sources.length] = d.sources[indx];
  142. }
  143. }
  144. }
  145. tmp = s.sources;
  146. len = tmp.length;
  147. GM_setValue('sources', tmp);
  148. for (indx = 0; indx < len; indx++) {
  149. if ($panel.find('.ghe-source').eq(indx).length) {
  150. $el = $panel
  151. .find('.ghe-source-input')
  152. .eq(indx)
  153. .attr('data-url', tmp[indx]);
  154. } else {
  155. $el = $(ghe.sourceHTML)
  156. .appendTo($panel.find('.ghe-sources'))
  157. .find('.ghe-source-input')
  158. .attr('data-url', tmp[indx]);
  159. }
  160. // only show file name when not focused
  161. ghe.showFileName($el);
  162. }
  163. // remove extras
  164. $panel.find('.ghe-source').filter(':gt(' + len + ')').remove();
  165. if (reset) {
  166. this.updateSettings();
  167. }
  168.  
  169. debug((reset ? 'Resetting' : 'Saving') + ' current values & updating panel', s);
  170. ghe.busy = false;
  171. },
  172.  
  173. updateSettings : function() {
  174. this.isUpdating = true;
  175. var settings = this.settings,
  176. $panel = $('#ghe-settings-inner');
  177. settings.rangeHeight = $panel.find('.ghe-height').val();
  178. settings.activeZoom = $panel.find('.ghe-zoom').val();
  179. settings.insertAsImage = $panel.find('.ghe-image').is(':checked');
  180. settings.caseSensitive = $panel.find('.ghe-case').is(':checked');
  181. settings.sources = $panel.find('.ghe-source-input').map(function(){
  182. return $(this).attr('data-url');
  183. }).get();
  184.  
  185. // update case-sensitive regex
  186. this.setRegex();
  187.  
  188. debug('Updating user settings', settings);
  189. this.updateStyleSheet();
  190. this.isUpdating = false;
  191. },
  192.  
  193. loadEmojiJson : function(update) {
  194. // only load emoji.json once a day, or after a forced update
  195. if (update || (new Date().getTime() > this.settings.date + this.vars.delay)) {
  196. var indx,
  197. promises = [],
  198. sources = this.settings.sources,
  199. len = sources.length;
  200. for (indx = 0; indx < len; indx++) {
  201. promises[promises.length] = this.fetchCustomEmojis(sources[indx]);
  202. }
  203. $.when.apply(null, promises).done(function(){
  204. ghe.checkPage();
  205. ghe.promises = [];
  206. ghe.settings.date = new Date().getTime();
  207. GM_setValue('date', ghe.settings.date);
  208. GM_setValue('collections', ghe.collections);
  209. });
  210. }
  211. },
  212.  
  213. fetchCustomEmojis : function(url) {
  214. if (!this.promises[url]) {
  215. this.promises[url] = $.Deferred(function(defer) {
  216. debug('Fetching custom emoji list', url);
  217. GM_xmlhttpRequest({
  218. method : 'GET',
  219. url : url,
  220. onload : function(response) {
  221. var json = false;
  222. try {
  223. json = JSON.parse(response.responseText);
  224. } catch (err) {
  225. debug('Invalid JSON', url);
  226. return defer.reject();
  227. }
  228. if (json && json[0].name) {
  229. // save url to make removing the entry easier
  230. json[0].url = url;
  231. ghe.collections[json[0].name] = json;
  232. debug('Adding "' + json[0].name + '" Emoji Collection');
  233. }
  234. return defer.resolve();
  235. }
  236. });
  237. }).promise();
  238. }
  239. return this.promises[url];
  240. },
  241.  
  242. // Using: document.evaluate('//*[text()[contains(.,":_")]]', document.body, null,
  243. // XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  244. // to find matching content as it is much faster than scanning each node
  245. // sometimes it misses things...
  246. checkPage : function(node) {
  247. this.isUpdating = true;
  248. // not sure why but document evaluate doesn't work on wiki page
  249. // preview tab, so we need to search the entire document
  250. if ($('#wiki-wrapper').length) {
  251. node = null;
  252. }
  253. var indx = 0,
  254. parts = this.vars.emojiTemplate.split('${name}'), // parts = [':_', ':']
  255. // adding "//" starts from document, so if node is defined, don't
  256. // include it so the search starts from the node
  257. path = (node ? '' : '//') + '//*[text()[contains(.,"' + parts[0] + '")]]',
  258. nodes = document.evaluate(path, node || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null),
  259. len = nodes.snapshotLength;
  260. try {
  261. node = nodes.snapshotItem(indx);
  262. while (node && indx++ < len) {
  263. if (!ghe.regex.skipElm.test(node.nodeName)) {
  264. ghe.findEmoji(node);
  265. }
  266. node = nodes.snapshotItem(indx);
  267. }
  268. } catch (e) {
  269. debug('Nothing to replace!', e);
  270. }
  271. this.isUpdating = false;
  272. },
  273.  
  274. findEmoji : function(node) {
  275. var indx, len, group, match, matchesLen, name,
  276. regex = ghe.regex.nameRegex,
  277. matches = [],
  278. emojis = this.collections,
  279. str = node.textContent;
  280. while ((match = regex.exec(str)) !== null) {
  281. matches[matches.length] = match[1];
  282. }
  283. if (matches && matches[0]) {
  284. matchesLen = matches.length;
  285. for (group in emojis) {
  286. if (emojis.hasOwnProperty(group)) {
  287. len = emojis[group].length;
  288. for (indx = 1; indx < len; indx++) {
  289. name = emojis[group][indx].name;
  290. for (match = 0; match < matchesLen; match++) {
  291. if (name === matches[match]) {
  292. debug('found "' + matches[match] + '" in "' + node.textContent + '"');
  293. ghe.replaceText(node, emojis[group][indx]);
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. },
  301.  
  302. replaceText : function(node, emoji) {
  303. var data, pos, imgnode, middlebit, endbit,
  304. isCased = this.settings.caseSensitive,
  305. name = this.vars.emojiTemplate.replace(ghe.regex.template, emoji.name),
  306. skip = 0;
  307. name = isCased ? name : name.toUpperCase();
  308. // Code modified from highlight-5 (MIT license)
  309. // http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
  310. if (node.nodeType === 3) {
  311. data = isCased ? node.data : node.data.toUpperCase();
  312. pos = data.indexOf(name);
  313. pos -= (data.substr(0, pos).length - node.data.substr(0, pos).length);
  314. if (pos >= 0) {
  315. imgnode = ghe.createEmoji(emoji);
  316. middlebit = node.splitText(pos);
  317. endbit = middlebit.splitText(name.length);
  318. middlebit.parentNode.replaceChild(imgnode, middlebit);
  319. skip = 1;
  320. }
  321. } else if (node.nodeType === 1 && node.childNodes) {
  322. for (var i = 0; i < node.childNodes.length; ++i) {
  323. i += ghe.replaceText(node.childNodes[i], emoji);
  324. }
  325. }
  326. return skip;
  327. },
  328.  
  329. // This function does the surrounding for every matched piece of text
  330. // and can be customized to do what you like
  331. // <img class="emoji" title=":smile:" alt=":smile:" src="x.png" height="20" width="20" align="absmiddle">
  332. createEmoji : function(emoji) {
  333. var el = document.createElement('img');
  334. el.src = emoji.url;
  335. el.className = ghe.vars.emojiClass + ' emoji';
  336. el.title = el.alt = ghe.vars.emojiTemplate.replace(ghe.regex.template, emoji.name);
  337. // el.align = 'absmiddle'; // deprecated attribute
  338. return el;
  339. },
  340.  
  341. // used by autocomplete (atwho) filter function
  342. matches : function(query, labels) {
  343. if (query === '') {
  344. return 1;
  345. }
  346. labels = labels || '';
  347. var i, partial,
  348. count = 0,
  349. isCS = this.settings.caseSensitive,
  350. arry = (isCS ? labels : labels.toUpperCase()).split(/[\s,_]+/),
  351. parts = (isCS ? query : query.toUpperCase()).split(/[,_]/),
  352. len = parts.length;
  353. for (i = 0; i < len; i++) {
  354. // full match or partial
  355. partial = arry.join('_').indexOf(parts.join('_'));
  356. if (arry.indexOf(parts[i]) > -1 || partial > -1) {
  357. count++;
  358. }
  359. // give more weight to results with indexOf closer to zero
  360. if (partial > -1 && partial < len / 2) {
  361. count++;
  362. }
  363. }
  364. // return fraction of query matches
  365. return count / len;
  366. },
  367.  
  368. // init when comment textarea is focused
  369. initAutocomplete : function($el) {
  370. if (!$el.data('atwho')) {
  371. var indx, len, name, group,
  372. data = [];
  373. // combine data
  374. for (name in ghe.collections) {
  375. if (ghe.collections.hasOwnProperty(name)) {
  376. group = ghe.collections[name].slice(1);
  377. data = data.concat(group);
  378. }
  379. }
  380. len = data.length;
  381. // alphabetic sort
  382. data = data.sort(function(a, b) {
  383. return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;
  384. });
  385. // add prepend name to labels
  386. for (indx = 0; indx < len; indx++) {
  387. data[indx].labels = data[indx].name.replace(/_/g, ' ') + ' ' + data[indx].labels;
  388. }
  389. // add emoji autocomplete to comment textareas
  390. $el.atwho({
  391. at : ':_', // first two characters from emojiTemplate
  392. data : data,
  393. searchKey: 'labels',
  394. displayTpl : '<li><span><img src="${url}" height="30" /></span>${name}</li>',
  395. insertTpl : ghe.vars.emojiTemplate,
  396. delay : 400,
  397. callbacks : {
  398. matcher: function(flag, subtext) {
  399. var regexp = ghe.regex.emojiFilter,
  400. match = regexp.exec(subtext);
  401. // this next line does some magic...
  402. // for some reason, without it, moving the caret from "p" to "r" in
  403. // ":_people,fear," opens & closes the popup with each letter typed
  404. subtext.match(regexp);
  405. if (match) {
  406. return match[2] || match[1];
  407. } else {
  408. return null;
  409. }
  410. },
  411. filter: function(query, data, searchKey) {
  412. var i, item,
  413. len = data.length,
  414. _results = [];
  415. for (i = 0; i < len; i++) {
  416. item = data[i];
  417. item.atwho_order = ghe.matches(query, item[searchKey]);
  418. if (item.atwho_order > 0.9) {
  419. _results[_results.length] = item;
  420. }
  421. }
  422. return query === '' ? _results : _results.sort(function(a, b) {
  423. // descending sort
  424. return b.atwho_order - a.atwho_order;
  425. });
  426. },
  427. sorter: function(query, items) {
  428. // sorted by filter
  429. return items;
  430. },
  431. // event parameter adding in atwho.js mod
  432. beforeInsert: function(value, $li, event) {
  433. if (event.shiftKey || ghe.settings.insertAsImage) {
  434. // add image tag directly if shift is held
  435. return '<img title="' +
  436. ghe.vars.emojiTemplate.replace(ghe.regex.template, $li.text()) +
  437. '" src="' + $li.find('img').attr('src') + '">';
  438. }
  439. return value;
  440. }
  441. }
  442. });
  443. // use classes from GitHub-Dark to make theme match GitHub-Dark
  444. $('.atwho-view').addClass('popover suggester');
  445. }
  446. },
  447.  
  448. setupPreviews : function() {
  449. // Add mutant observer to previews
  450. var previews = document.querySelectorAll('.preview-content .comment-body');
  451. if (ghe.previewObserver.length) {
  452. // disconnect previous observers
  453. $.each(ghe.previewObserver, function() {
  454. this.disconnect();
  455. });
  456. ghe.previewObserver = [];
  457. }
  458. Array.prototype.forEach.call(previews, function(target) {
  459. var obs = new MutationObserver(function(mutations) {
  460. mutations.forEach(function(mutation) {
  461. // preform checks before adding code wrap to minimize function calls
  462. if (mutation.target === target && !ghe.isUpdating) {
  463. ghe.checkPage(target);
  464. }
  465. });
  466. });
  467. obs.observe(target, {
  468. childList : true,
  469. subtree : false
  470. });
  471. ghe.previewObserver[ghe.previewObserver.length] = obs;
  472. });
  473. },
  474.  
  475. addToolbarIcon : function() {
  476. // add Emoji setting icons
  477. var indx, $el,
  478. $toolbars = $('.toolbar-commenting'),
  479. len = $toolbars.length;
  480. for (indx = 0; indx < len; indx++) {
  481. $el = $toolbars.eq(indx);
  482. if (!$el.find('.ghe-settings-icon').length) {
  483. $el.prepend([
  484. '<button type="button" class="ghe-settings-open toolbar-item tooltipped tooltipped-n tooltipped-multiline" aria-label="Browse collections & Set Emojis Options" tabindex="-1">',
  485. '<svg class="ghe-settings-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor">',
  486. '<path d="M7.205 3.233c0 .952-.753 1.73-1.722 1.73-.953 0-1.707-.793-1.707-1.73 0-.937.762-1.73 1.707-1.73.97 0 1.73.793 1.73 1.73h-.008zm6.904 0c0 .952-.794 1.73-1.747 1.73-.95 0-1.722-.793-1.722-1.73 0-.937.795-1.73 1.73-1.73.938 0 1.747.793 1.747 1.73h-.008zM7.204 10.1v5.19c0 1.728 6.904 1.728 6.904 0V10.1M10.642 10.1v3.46"/>',
  487. '<path d="M.878 8.777s3.167 1.893 8.002 1.92c4.365.02 8.135-1.92 8.135-1.92"/>',
  488. '</svg>',
  489. '</button>'
  490. ].join(''));
  491. }
  492. }
  493. },
  494.  
  495. // dynamic stylesheet
  496. updateStyleSheet : function() {
  497. var range = this.settings.rangeHeight.split(';');
  498. ghe.$style.text([
  499. // img styling - vertically center with set height range
  500. '.atwho-view li img, #ghe-popup .select-menu-item img, img[alt="ghe-emoji"], .' +
  501. this.vars.emojiClass + ' { ' +
  502. 'margin-bottom:.25em; vertical-align:middle; ' +
  503. 'min-height: ' + (range[0] || 'none') + 'px;' +
  504. 'max-height: ' + (range[1] || 'none') + 'px }',
  505. // click (make active) on image to zoom
  506. '.' + this.vars.emojiClass + ':active, a:active img[alt="ghe-emoji"] { zoom:' +
  507. this.settings.activeZoom + ' }'
  508. ].join(''));
  509. },
  510.  
  511. addBindings : function() {
  512. var lastKey,
  513. $popup = $('#ghe-popup'),
  514. $settings = $('#ghe-settings');
  515. // Delegated bindings
  516. $('body')
  517. .on('click', '.ghe-settings-open', function() {
  518. // open all collections panel
  519. ghe.openCollections($(this));
  520. return false;
  521. })
  522. .on('click', '.ghe-collection', function() {
  523. // open targeted collection
  524. var name = $(this).attr('data-group');
  525. ghe.showCollection(name);
  526. })
  527. .on('click', '.ghe-emoji', function(e) {
  528. // click on emoji in collection to add to textarea
  529. ghe.addEmoji(e, $(this));
  530. })
  531. .on('click keypress keydown', function(e) {
  532. clearTimeout(ghe.timer);
  533. var panelVisible = $popup.hasClass('in') || $settings.hasClass('in'),
  534. openPanel = ghe.vars.keyboardOpen.split('+'),
  535. key = String.fromCharCode(e.which).toLowerCase();
  536. // press escape or click outside to close the panel
  537. if (panelVisible && e.which === 27 || e.type === 'click' && !$(e.target).closest('#ghe-wrapper').length) {
  538. ghe.closePanels();
  539. return;
  540. }
  541. // keydown is only needed for escape key detection
  542. if (e.type === 'keydown' || /(input|textarea)/i.test(document.activeElement.nodeName)) {
  543. return;
  544. }
  545. // shortcut keys need keypress
  546. if (lastKey === openPanel[0] && key === openPanel[1]) {
  547. if ($settings.hasClass('in')) {
  548. ghe.closePanels();
  549. } else {
  550. ghe.openSettings();
  551. }
  552. }
  553. lastKey = key;
  554. ghe.timer = setTimeout(function() {
  555. lastKey = null;
  556. }, ghe.vars.keyboardDelay);
  557.  
  558. // add shortcut to help menu
  559. if (key === '?') {
  560. // table doesn't exist until user presses "?"
  561. setTimeout(function() {
  562. if (!$('.ghe-shortcut').length) {
  563. $('.keyboard-mappings:eq(0) tbody:eq(0)').append([
  564. '<tr class="ghe-shortcut">',
  565. '<td class="keys">',
  566. '<kbd>' + openPanel[0] + '</kbd> <kbd>' + openPanel[1] + '</kbd>',
  567. '</td>',
  568. '<td>GitHub Emojis: open settings</td>',
  569. '</tr>'
  570. ].join(''));
  571. }
  572. }, 300);
  573. }
  574. });
  575.  
  576. // popup & settings interactions
  577. $('#ghe-popup .octicon-gear').on('click keyup', function(e) {
  578. if (e.type === 'keyup' && e.which !== 13) {
  579. return;
  580. }
  581. ghe.openSettings();
  582. });
  583. $('#ghe-settings, #ghe-settings-close, #ghe-settings-inner').on('click', function(e) {
  584. if (this.id === 'ghe-settings-inner') {
  585. e.stopPropagation();
  586. } else {
  587. ghe.closePanels();
  588. }
  589. });
  590. // ghe-checkbox added to checkboxes
  591. $('.ghe-checkbox').on('change', function() {
  592. ghe.updateSettings();
  593. });
  594. // go back - switch from single collection to showing all collections
  595. $('#ghe-popup .ghe-back').on('click', function(){
  596. $('.ghe-single-collection, .ghe-back').hide();
  597. $('.ghe-all-collections').show();
  598. });
  599.  
  600. // add new source input
  601. $('#ghe-add-source').on('click', function() {
  602. var $panel = $('#ghe-settings-inner');
  603. // lets not get crazy!
  604. if ($panel.find('.ghe-source').length < 20) {
  605. $(ghe.sourceHTML).appendTo($panel.find('.ghe-sources'));
  606. }
  607. return false;
  608. });
  609. $('#ghe-refresh-sources, #ghe-restore').on('click', function() {
  610. // update sources from settings panel
  611. ghe.setStoredValues(this.id === 'ghe-restore');
  612. // load json files
  613. ghe.loadEmojiJson(true);
  614. return false;
  615. });
  616.  
  617. // Init range slider
  618. $('.ghe-height')
  619. .val(ghe.settings.rangeHeight)
  620. .ionRangeSlider({
  621. type : 'double',
  622. min : 0,
  623. max : ghe.vars.maxEmojiHeight,
  624. onChange : function() {
  625. ghe.updateSettings();
  626. },
  627. force_edges : true,
  628. hide_min_max : true
  629. });
  630. $('.ghe-zoom')
  631. .val(ghe.settings.activeZoom)
  632. .ionRangeSlider({
  633. min : 0,
  634. max : ghe.vars.maxEmojiZoom,
  635. step : 0.1,
  636. onChange : function() {
  637. ghe.updateSettings();
  638. },
  639. force_edges : true,
  640. hide_min_max : true
  641. });
  642.  
  643. // Remove source input - delegated binding
  644. $('.ghe-settings-wrapper')
  645. .on('click', '.ghe-remove', function(e) {
  646. var $wrapper = $(this).closest('.ghe-source'),
  647. url = $wrapper.find('.ghe-source-input').attr('data-url');
  648. ghe.removeSource(url);
  649. $wrapper.remove();
  650. ghe.setStoredValues();
  651. return false;
  652. })
  653. .on('focus blur input change', '.ghe-source-input', function(e) {
  654. if (ghe.busy) { return; }
  655. ghe.busy = true;
  656. var val,
  657. $this = $(this);
  658. switch (e.type) {
  659. case 'focus':
  660. case 'focusin':
  661. // show entire url when focused
  662. $this.val( $this.attr('data-url') );
  663. break;
  664. case 'blur':
  665. case 'focusout':
  666. ghe.showFileName($this);
  667. break;
  668. default:
  669. $this.attr('data-url', $this.val());
  670. }
  671. if (e.type === 'change' || e.which === 13) {
  672. val = $this.val();
  673. $this.attr('data-url', val);
  674. ghe.fetchCustomEmojis(val);
  675. }
  676. ghe.busy = false;
  677. });
  678.  
  679. // initialize autocomplete that add emojis, but only on focus
  680. // since every comment has a hidden textarea
  681. $('body').on('focus', '.comment-form-textarea', function() {
  682. ghe.initAutocomplete($(this));
  683. });
  684. },
  685.  
  686. showFileName : function($el) {
  687. var str = $el.attr('data-url'),
  688. v = str.substring( str.lastIndexOf('/') + 1, str.length );
  689. // show only the file name in the input when blurred
  690. // unless there is no file name
  691. $el.val(v === '' ? str : '...' + v);
  692. },
  693.  
  694. closePanels : function() {
  695. $('#ghe-popup').removeClass('in');
  696. $('#ghe-settings').removeClass('in');
  697. ghe.$currentInput = null;
  698. },
  699.  
  700. openSettings : function() {
  701. $('.modal-backdrop').click();
  702. $('#ghe-settings').addClass('in');
  703. },
  704.  
  705. openCollections : function($el) {
  706. ghe.addCollections();
  707. var pos = $el.offset();
  708. $('#ghe-settings').removeClass('in');
  709. $('#ghe-popup')
  710. .addClass('in')
  711. .css({
  712. left: pos.left + 25,
  713. top: pos.top
  714. });
  715. ghe.$currentInput = $el.closest('.previewable-comment-form').find('.comment-form-textarea');
  716. },
  717.  
  718. addCollections : function() {
  719. var indx, len, key, group, img,
  720. collections = ghe.collections,
  721. range = ghe.settings.rangeHeight.split(';'),
  722. list = [],
  723. items = [];
  724. // build collections list -
  725. for (key in collections) {
  726. if (collections.hasOwnProperty(key)) {
  727. list[list.length] = key;
  728. }
  729. }
  730. list = list.sort(function(a, b) {
  731. return a > b ? 1 : (a < b ? -1 : 0);
  732. });
  733. len = list.length;
  734. // add random image from group
  735. for (indx = 0; indx < len; indx++) {
  736. group = collections[list[indx]];
  737. // random image (skip first entry)
  738. img = Math.round(Math.random() * (group.length - 2)) + 1;
  739. items[items.length] = '<div class="select-menu-item js-navigation-item ghe-collection" ' +
  740. 'data-group="' + list[indx] + '">' +
  741. // collection info stored in first entry
  742. group[0].name + ' <span class="ghe-right"><img src="' +
  743. group[img].url + '" title="' +
  744. ghe.vars.emojiTemplate.replace(ghe.regex.template, group[img].name) + '" style="' +
  745. 'min-height:' + (range[0] || 'none') + 'px;' +
  746. 'max-height:' + (range[1] || 'none') + 'px;">' +
  747. '</span></div>';
  748. }
  749. $('.ghe-single-collection, .ghe-back').hide();
  750. $('.ghe-all-collections').html(items.join('')).show();
  751. },
  752.  
  753. showCollection : function(name) {
  754. var indx,
  755. range = ghe.settings.rangeHeight.split(';'),
  756. group = ghe.collections[name].sort(function(a, b) {
  757. return a.name > b.name ? 1 : ( a.name < b.name ? -1 : 0 );
  758. }),
  759. list = [],
  760. len = group.length;
  761. for (indx = 1; indx < len; indx++) {
  762. list[indx - 1] = '<div class="select-menu-item js-navigation-item ghe-emoji" ' +
  763. 'data-name="' + group[indx].name + '">' +
  764. group[indx].name + '<span class="ghe-right"><img src="' +
  765. group[indx].url + '" style="min-height:' + (range[0] || 'none') + 'px;' +
  766. 'max-height:' + (range[1] || 'none') + 'px"></span></div>';
  767. }
  768. $('.ghe-all-collections').hide();
  769. $('.ghe-single-collection').html(list.join('')).show();
  770. $('.ghe-back').show();
  771. },
  772.  
  773. // add emoji from collection
  774. addEmoji : function(e, $el) {
  775. var val, emoji,
  776. name = $el.attr('data-name'),
  777. caretPos = ghe.$currentInput.caret('pos');
  778. // insert into textarea
  779. if (e.shiftKey || ghe.settings.insertAsImage) {
  780. // add image tag directly if shift is held;
  781. // GitHub does NOT allow class names so we are forced to use alt
  782. emoji = '<img alt="ghe-emoji" title="' +
  783. ghe.vars.emojiTemplate.replace(ghe.regex.template, name) +
  784. '" src="' + $el.find('img').attr('src') + '">';
  785. } else {
  786. emoji = ghe.vars.emojiTemplate.replace(ghe.regex.template, name);
  787. }
  788. val = ghe.$currentInput.val();
  789. ghe.$currentInput
  790. .val(val.slice(0, caretPos) + emoji + ' ' + val.slice(caretPos))
  791. .focus()
  792. .caret('pos', caretPos + emoji.length + 1);
  793. ghe.closePanels();
  794. },
  795.  
  796. removeSource : function(url) {
  797. var indx,
  798. list = [],
  799. collections = this.collections,
  800. sources = this.settings.sources,
  801. len = sources.length;
  802. // remove from source
  803. for (indx = 0; indx < len; indx++) {
  804. if (sources[indx] !== url) {
  805. list[list.length] = sources[indx];
  806. }
  807. }
  808. this.settings.sources = list;
  809. for (indx in collections) {
  810. if (collections.hasOwnProperty(indx) && collections[indx][0].url === url) {
  811. delete collections[indx];
  812. debug('Removing "' + indx + '" collection', collections);
  813. }
  814. }
  815. },
  816.  
  817. update : function(target) {
  818. this.isUpdating = true;
  819. this.setupPreviews();
  820. this.addToolbarIcon();
  821. // checkPage clears isUpdating flag
  822. this.checkPage(target);
  823. },
  824.  
  825. addPanels : function() {
  826. /* https://github.com/ichord/At.js styles for autocomplete */
  827. GM_addStyle([
  828. // settings panel
  829. '#ghe-menu:hover { cursor:pointer }',
  830. '#ghe-settings { position:fixed; z-index:65535; top:0; bottom:0; left:0; right:0; opacity:0; visibility:hidden }',
  831. '#ghe-settings.in { opacity:1; visibility:visible; background:rgba(0,0,0,.5) }',
  832. '#ghe-settings-inner { position:fixed; left:50%; top:50%; transform:translate(-50%,-50%); width:25rem; box-shadow:0 .5rem 1rem #111; color:#c0c0c0 }',
  833. '#ghe-settings label { margin-left:.5rem; position:relative; top:-1px }',
  834. '#ghe-settings .ghe-remove { float:right; margin-top:2px; padding:4px; cursor:pointer }',
  835. '#ghe-settings .ghe-remove-icon { position:relative; top:3px }',
  836. '#ghe-settings-close { fill:#666; float:right; cursor:pointer }',
  837. '#ghe-settings-close:hover { fill:#ccc }',
  838. '#ghe-settings .ghe-settings-wrapper { max-height:60vh; overflow-y:auto; padding: 1px 10px }',
  839. '#ghe-settings .ghe-right, #ghe-popup .ghe-right { float:right }',
  840. '#ghe-settings p { line-height:25px; }',
  841. '#ghe-settings .checkbox input { margin-top:.35em }',
  842. '#ghe-settings input[type="checkbox"] { width:16px !important; height:16px !important; border-radius:3px !important }',
  843. '#ghe-settings .boxed-group-inner { padding:0; }',
  844. '#ghe-settings .ghe-footer { padding: 10px; border-top: #555 solid 1px; }',
  845. '#ghe-settings .ghe-min-height, #ghe-settings .ghe-max-height, .ghe-zoom { width: 5em; }',
  846. '#ghe-settings .ghe-source-input { width: 90%; }',
  847. '#ghe-settings .ghe-slider-wrapper { height:40px; }',
  848. '#ghe-settings .ghe-slider-wrapper label { position:relative; top:22px }',
  849. '#ghe-settings .ghe-range-slider, #ghe-settings .ghe-zoom-slider { position:relative; height:40px; width:250px; float:right }',
  850.  
  851. // show emoji collections
  852. '#ghe-popup { display:none }',
  853. '#ghe-popup .ghe-content, #ghe-popup .ghe-content > div { max-height: 200px }',
  854. '#ghe-popup .octicon-gear { margin-left:4px }',
  855. '#ghe-popup .ghe-back svg { height:20px; padding:4px 14px 4px 4px }',
  856. '#ghe-popup .select-menu-item { font-size:1.1em; font-weight:bold; line-height:40px; padding:8px }',
  857. '.ghe-settings-icon, #ghe-popup.in { display:inline-block }',
  858.  
  859. // autocomplete popup in comment
  860. '.atwho-view { position:absolute; top:0; left:0; display:none; margin-top:18px; background:#fff; color:#000; border:1px solid #ddd; border-radius:3px; box-shadow:0 0 5px rgba(0,0,0,.1); min-width:300px; max-width:none!important; max-height:225px; overflow:auto; z-index:11110!important }',
  861. '.atwho-view .navigation-focus { background:#36f; color:#fff }',
  862. '.atwho-view .navigation-focus small { color:#fff }',
  863. '.atwho-view strong { color:#36F }',
  864. '.atwho-view .navigation-focus strong { color:#fff; font:700 }',
  865. '.atwho-view ul { list-style:none; padding:0; margin:auto }',
  866. '.atwho-view ul li { display:block; padding:5px 10px; border-bottom:1px solid #ddd; cursor:pointer }',
  867. '.atwho-view li span { display:inline-block; min-width:60px; padding-right:4px }',
  868. '.atwho-view small { font-size:smaller; color:#777; font-weight:400 }',
  869.  
  870. // rangeSlider
  871. '.irs{position:relative;display:block;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}',
  872. '.irs-line{position:relative;display:block;overflow:hidden;outline:none !important}.irs-line-left,.irs-line-mid,.irs-line-right{position:absolute;display:block;top:0}',
  873. '.irs-line-left{left:0;width:9%}.irs-line-mid{left:9%;width:82%}.irs-line-right{right:0;width:9%}.irs-bar{position:absolute;display:block;left:0;width:0}.irs-bar-edge{position:absolute;display:block;top:0;left:0}',
  874. '.irs-shadow{position:absolute;display:none;left:0;width:0}.irs-slider{position:absolute;display:block;cursor:default;z-index:1}.irs-slider.type_last{z-index:2}.irs-min{position:absolute;display:block;left:0;cursor:default}',
  875. '.irs-max{position:absolute;display:block;right:0;cursor:default}.irs-from,.irs-to,.irs-single{position:absolute;display:block;top:0;left:0;cursor:default;white-space:nowrap}.irs-grid{position:absolute;display:none;bottom:0;left:0;width:100%;height:20px}',
  876. '.irs-with-grid .irs-grid{display:block}.irs-grid-pol{position:absolute;top:0;left:0;width:1px;height:8px;background:#000}.irs-grid-pol.small{height:4px}.irs-grid-text{position:absolute;bottom:0;left:0;white-space:nowrap;text-align:center;font-size:9px;line-height:9px;padding:0 3px;color:#000}',
  877. '.irs-disable-mask{position:absolute;display:block;top:0;left:-1%;width:102%;height:100%;cursor:default;background:rgba(0,0,0,0.0);z-index:2}.lt-ie9 .irs-disable-mask{background:#000;filter:alpha(opacity=0);cursor:not-allowed}.irs-disabled{opacity:0.4}',
  878. '.irs-hidden-input{position:absolute !important;display:block !important;top:0 !important;left:0 !important;width:0 !important;height:0 !important;font-size:0 !important;line-height:0 !important;padding:0 !important;margin:0 !important;outline:none !important;z-index:-9999 !important;background:none !important;border-style:solid !important;border-color:transparent !important}',
  879. '.irs-line-mid,.irs-line-left,.irs-line-right,.irs-bar,.irs-bar-edge,.irs-slider{background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAAC0BAMAAACAm0/4AAAAHlBMVEUAAADh5OlIPakuJnU8MZzh5Onh5Onlt8BIPamDg6ND+SBkAAAACnRSTlMAgMzMzHlXE4oe0nCEQQAAAMJJREFUeNrt1qENAkEQhtENkBDkCtCECiiBFjCgEXgMDVwJVEzGQ7KnZnJ5r4JP7E7+1tNJkCBBgoSqCQAAjNg+e6rbq717snt79GSHdu3J9hVGfE8nIVR4jgU+ZYHTVOBAAwAw4pROggQJEiRUTQAAYMRuSl9Rn/whN+UnFJizEiQUSijwKQucpgIHGgCAQatjy7a5tJkkBAlBQpAQJAQJQUJYYkKByQIA/6zPbSYJQUKQECQECUFCkBAkhCUmAMAvX+TSxQIIIKq9AAAAAElFTkSuQmCC") repeat-x}',
  880. '.irs{height:40px}.irs-with-grid{height:60px}.irs-line{height:12px;top:25px}.irs-line-left{height:12px;background-position:0 -30px}',
  881. '.irs-line-mid{height:12px;background-position:0 0}.irs-line-right{height:12px;background-position:100% -30px}.irs-bar{height:12px;top:25px;background-position:0 -60px}',
  882. '.irs-bar-edge{top:25px;height:12px;width:9px;background-position:0 -90px}.irs-shadow{height:3px;top:34px;background:#000;opacity:.25}',
  883. '.lt-ie9 .irs-shadow{filter:alpha(opacity=25)}.irs-slider{width:16px;height:18px;top:22px;background-position:0 -120px}',
  884. '.irs-slider.state_hover,.irs-slider:hover{background-position:0 -150px}.irs-min,.irs-max{color:#fff;font-size:10px;line-height:1.333;text-shadow:none;top:0;padding:1px 3px;background:#7D7E81;-moz-border-radius:4px;border-radius:4px}',
  885. '.irs-from,.irs-to,.irs-single{color:#fff;font-size:10px;line-height:1.333;text-shadow:none;padding:1px 5px;background:#534AA1;-moz-border-radius:4px;border-radius:4px}',
  886. '.irs-from:after,.irs-to:after,.irs-single:after{position:absolute;display:block;content:"";bottom:-6px;left:50%;width:0;height:0;margin-left:-3px;overflow:hidden;border:3px solid transparent;border-top-color:#534AA1}',
  887. '.irs-grid-pol{background:#e1e4e9}.irs-grid-text{color:#999}'
  888. ].join(''));
  889.  
  890. // Settings panel markup
  891. $('body').append([
  892. '<div id="ghe-wrapper">',
  893. '<div id="ghe-popup" class="select-menu-modal-holder js-menu-content js-navigation-container js-active-navigation-container">',
  894. '<div class="select-menu-modal">',
  895. '<div class="select-menu-header">',
  896. '<span class="select-menu-title">',
  897. '<text>Emoji Collections</text>',
  898. '<span class="octicon tooltipped tooltipped-w" aria-label="Change GitHub Custom Emoji Settings">',
  899. '<svg class="octicon-gear" viewBox="0 0 16 14" style="height: 16px; width: 14px;"><path d="M14 8.77V7.17l-1.94-0.64-0.45-1.09 0.88-1.84-1.13-1.13-1.81 0.91-1.09-0.45-0.69-1.92H6.17l-0.63 1.94-1.11 0.45-1.84-0.88-1.13 1.13 0.91 1.81-0.45 1.09L0 7.23v1.59l1.94 0.64 0.45 1.09-0.88 1.84 1.13 1.13 1.81-0.91 1.09 0.45 0.69 1.92h1.59l0.63-1.94 1.11-0.45 1.84 0.88 1.13-1.13-0.92-1.81 0.47-1.09 1.92-0.69zM7 11c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z"/></svg>',
  900. '</span>',
  901. '<span class="octicon tooltipped tooltipped-w ghe-back" aria-label="Go back to see all collections">',
  902. '<svg xmlns="http://www.w3.org/2000/svg" width="6.5" height="10" viewBox="0 0 6.5 10"><path d="M5.008 0l1.497 1.504-3.76 3.49 3.743 3.51L4.984 10l-4.99-5.013L5.01 0z"/></svg>',
  903. '</span>',
  904. '</span>',
  905. '</div>',
  906. '<div class="js-select-menu-deferred-content ghe-content">',
  907. '<div class="select-menu-list ghe-all-collections"></div>',
  908. '<div class="select-menu-list ghe-single-collection"></div>',
  909. '</div>',
  910. '</div>',
  911. '</div>',
  912. '<div id="ghe-settings">',
  913. '<div id="ghe-settings-inner" class="boxed-group">',
  914. '<h3>GitHub Custom Emoji Settings',
  915. '<svg id="ghe-settings-close" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="160 160 608 608"><path d="M686.2 286.8L507.7 465.3l178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"/></svg>',
  916. '</h3>',
  917. '<div class="boxed-group-inner">',
  918. '<form>',
  919. '<div class="ghe-settings-wrapper">',
  920. '<p>',
  921. '<label>Insert as Image:',
  922. '<sup class="tooltipped tooltipped-e" aria-label="Or Shift + select the emoji">?</sup>',
  923. '<input class="ghe-image ghe-checkbox ghe-right" type="checkbox">',
  924. '</label>',
  925. '</p>',
  926. '<p class="checkbox">',
  927. '<label>Case Sensitive <input class="ghe-case ghe-checkbox ghe-right" type="checkbox"></label>',
  928. '</p>',
  929. '<div class="ghe-slider-wrapper">',
  930. '<div class="ghe-range-slider">',
  931. '<input type="text" class="ghe-height" value="" />',
  932. '</div>',
  933. '<label>Emoji Height',
  934. '<sup class="tooltipped tooltipped-e" aria-label="Set emoji minimum & maximum&#10;height in pixels">?</sup>',
  935. '</label>',
  936. '</div>',
  937. '<div class="ghe-slider-wrapper">',
  938. '<div class="ghe-zoom-slider">',
  939. '<input class="ghe-zoom ghe-right" type="text">',
  940. '</div>',
  941. '<label>Emoji Zoom',
  942. '<sup class="tooltipped tooltipped-e" aria-label="Set Emoji zoom factor&#10;while actively clicked">?</sup>',
  943. '</label>',
  944. '</div>',
  945. '<p>',
  946. '<hr>',
  947. '<h3>Sources',
  948. '<a href="https://github.com/StylishThemes/GitHub-Custom-Emojis/wiki/Add-Emojis" class="tooltipped tooltipped-e tooltipped-multiline" aria-label="Click to get more details on how to set up an Emoji source JSON file">',
  949. '<sup>?</sup>',
  950. '</a>',
  951. '</h3>',
  952. '<div class="ghe-sources"></div>',
  953. '</p>',
  954. '</div>',
  955. '<div class="ghe-footer">',
  956. '<div class="btn-group">',
  957. '<a href="#" id="ghe-add-source" class="btn btn-sm">Add Source</a>',
  958. '<a href="#" id="ghe-refresh-sources" class="btn btn-sm">Refresh Sources</a>&nbsp;',
  959. '</div>',
  960. '<a href="#" id="ghe-restore" class="btn btn-sm btn-danger tooltipped tooltipped-n ghe-right" aria-label="Default sources are restored;&#10;other source will remain">Restore Defaults</a>',
  961. '</div>',
  962. '</form>',
  963. '</div>',
  964. '</div>',
  965. '</div>',
  966. '</div>'
  967. ].join(''));
  968. },
  969.  
  970. // JSON source inputs
  971. sourceHTML : [
  972. '<div class="ghe-source">',
  973. '<input class="ghe-source-input" type="text" value="" placeholder="Add JSON sources only">',
  974. '<a href="#" class="ghe-remove btn btn-sm btn-danger">',
  975. '<svg class="ghe-remove-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="160 160 608 608" fill="currentColor"><path d="M686.2 286.8L507.7 465.3l178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"/></svg>',
  976. '</a>',
  977. '</div>'
  978. ].join(''),
  979.  
  980. setRegex : function() {
  981. var isCS = this.settings.caseSensitive,
  982. // parts = [':_', ':']
  983. parts = this.vars.emojiTemplate.split('${name}');
  984.  
  985. // emojiFilter = /:_([a-zA-Z\u00c0-\u00ff0-9_,'.+-]*)$|:_([^\x00-\xff]*)$/gi
  986. // used by atwho.js autocomplete
  987. this.regex.emojiFilter = new RegExp(
  988. parts[0] + '([a-zA-Z\u00c0-\u00ff0-9_,\'\.\+\-]*)$|' +
  989. parts[0] + '([^\\x00-\\xff]*)$',
  990. (isCS ? 'g' : 'gi')
  991. );
  992.  
  993. this.regex.nameRegex = new RegExp(
  994. parts[0] + '([\\w_]+)' + parts[1],
  995. (isCS ? 'g' : 'gi')
  996. );
  997. },
  998.  
  999. init : function() {
  1000. debug('GitHub-Emoji Script initializing!');
  1001.  
  1002. // add style tag to head
  1003. this.$style = $('<style class="ghe-style">').appendTo('head');
  1004.  
  1005. this.getStoredValues();
  1006. this.loadEmojiJson();
  1007. this.updateStyleSheet();
  1008. this.isUpdating = true;
  1009. // regex based on case sensitive setting
  1010. this.setRegex();
  1011.  
  1012. var targets = document.querySelectorAll(this.containers.join(','));
  1013. Array.prototype.forEach.call(targets, function(target) {
  1014. new MutationObserver(function(mutations) {
  1015. mutations.forEach(function(mutation) {
  1016. // preform checks before adding code wrap to minimize function calls
  1017. if (mutation.target === target && !$.isEmptyObject(ghe.collections) &&
  1018. !(ghe.isUpdating || target.querySelector('.ghe-processed'))) {
  1019. ghe.update(target);
  1020. }
  1021. });
  1022. }).observe(target, {
  1023. childList : true,
  1024. subtree : true
  1025. });
  1026. });
  1027.  
  1028. this.addPanels();
  1029.  
  1030. // Add emoji autocomplete & watch for preview rendering
  1031. this.setupPreviews();
  1032. this.addToolbarIcon();
  1033. this.addBindings();
  1034. // update panel values after bindings (rangeslider)
  1035. this.setStoredValues();
  1036.  
  1037. // checkPage clears isUpdating flag
  1038. this.checkPage();
  1039. }
  1040. };
  1041.  
  1042. // add style at document-start
  1043. ghe.init();
  1044.  
  1045. // include a "?debug" anywhere in the browser URL to enable debugging
  1046. function debug() {
  1047. if (/\?debug/.test(window.location.href)) {
  1048. console.log.apply(console, arguments);
  1049. }
  1050. }
  1051. })(jQuery.noConflict(true));