From 6a12a29e1224939aa115a14715a4415e14b0b389 Mon Sep 17 00:00:00 2001 From: André Oliveira <37463445+SpecialAro@users.noreply.github.com> Date: Thu, 19 Jan 2023 22:50:09 +0000 Subject: feat: add several recipes (#293) --- recipes/help-scout/webview.js | 163 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 recipes/help-scout/webview.js (limited to 'recipes/help-scout/webview.js') diff --git a/recipes/help-scout/webview.js b/recipes/help-scout/webview.js new file mode 100644 index 0000000..bd84dd7 --- /dev/null +++ b/recipes/help-scout/webview.js @@ -0,0 +1,163 @@ +const _path = _interopRequireDefault(require('path')); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +/** + * Help Scout integration plugin for Ferdium + * + * @summary Integrates Help Scout into the Ferdium application + * @since 1.2.0 + */ + + +/** + * Scripts specific to ticket pages + * + * @since 1.2.0 + */ +let ticketScripts = { + init : function() { + this.processCopy(); + }, + /** + * Handles clicking the copy link + * + * @since 1.2.0 + * @return {void} + */ + processCopy : function() { + $('#copyLink').on('click', function(e) { + e.preventDefault(); + + copyToClipboard(); + + $('.link-copied').fadeIn('fast').css('display', 'block'); + }); + + $('#closeLink').on('click', function(e) { + e.preventDefault(); + + $('.link-copied').fadeOut('fast', function () { + $(this).css('display', 'none'); + }); + }); + } +}; + + +/** + * The core Ferdium message handler + * + * @since 1.0.0 + */ +module.exports = (Ferdium) => { + Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); + + /** + * Get messages for the Ferdium loop + * + * @since 1.0.0 + * @return {void} + */ + function getMessages() { + let mine = ''; + let unassigned = ''; + let total = '0'; + + /** + * Since Help Scout loads things asyncronously, + * we have to trigger everything in the loop for + * it to get recognized. + */ + addCopyLink(); + ticketScripts.init(); + + if ($('.dropdown.mailboxes').length > 0 && $('.dropdown.mailboxes a').hasClass('active')) { + // Individual tickets + mine = $('li.mine a .badge').text(); + unassigned = $('li.unassigned a .badge').text(); + } else if (window.location.href === 'https://secure.helpscout.net/dashboard/') { + // Main dashboard + mine = 0; + unassigned = 0; + + $('.card.mailbox .c-list').each(function() { + let m = $(this).find('a:nth-child(2)').find('.count').text(); + let u = $(this).find('a:first-child').find('.count').text(); + + if ($.isNumeric(m)) { + mine += Number.parseInt(m); + } + + if ($.isNumeric(u)) { + unassigned += Number.parseInt(u); + } + }); + + mine = mine.toString(); + unassigned = unassigned.toString(); + } + + if (mine !== '') { + total = mine; + } + + if (unassigned !== '') { + total = total + '/' + unassigned; + } + + Ferdium.setBadge(total); + } + + Ferdium.loop(getMessages); +}; + + +/** + * Add copy link to the conversation toolbar + * + * @since 1.2.0 + * @return {void} + */ +function addCopyLink() { + if ($('.convo-toolbar').length > 0 && $('#copyLink').length === 0) { + $('#actions-dd .more').append('