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/icon.svg | 682 ++++++++++++++++++++++++++++++++++++++++ recipes/help-scout/index.js | 1 + recipes/help-scout/package.json | 9 + recipes/help-scout/webview.js | 163 ++++++++++ 4 files changed, 855 insertions(+) create mode 100644 recipes/help-scout/icon.svg create mode 100644 recipes/help-scout/index.js create mode 100644 recipes/help-scout/package.json create mode 100644 recipes/help-scout/webview.js (limited to 'recipes/help-scout') diff --git a/recipes/help-scout/icon.svg b/recipes/help-scout/icon.svg new file mode 100644 index 0000000..8343e51 --- /dev/null +++ b/recipes/help-scout/icon.svg @@ -0,0 +1,682 @@ + + + + + + diff --git a/recipes/help-scout/index.js b/recipes/help-scout/index.js new file mode 100644 index 0000000..dd41f72 --- /dev/null +++ b/recipes/help-scout/index.js @@ -0,0 +1 @@ +module.exports = Ferdium => Ferdium; diff --git a/recipes/help-scout/package.json b/recipes/help-scout/package.json new file mode 100644 index 0000000..9048edc --- /dev/null +++ b/recipes/help-scout/package.json @@ -0,0 +1,9 @@ +{ + "id": "help-scout", + "name": "Help Scout", + "version": "1.2.0", + "license": "MIT", + "config": { + "serviceURL": "https://www.helpscout.com" + } +} 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('
  • Copy Link
  • '); + $('.c-convo-toolbar').after(''); + } +} + + +/** + * Process copying URLs to clipboard + * + * @since 1.1. + * @return {void} + */ +function copyToClipboard() { + let targetId = '_hiddenURLField'; + let target = document.querySelector(targetId); + + if(!target) { + target = document.createElement('textarea'); + target.style.position = 'absolute'; + target.style.left = '-9999px'; + target.style.top = '0'; + target.id = targetId; + document.body.append(target); + } + + target.textContent = window.location.href; + + let currentFocus = document.activeElement; + + target.focus(); + target.setSelectionRange(0, target.value.length); + + document.execCommand('copy'); + + if(currentFocus && typeof currentFocus.focus === 'function') { + currentFocus.focus(); + } +} -- cgit v1.2.3-70-g09d2