From 9b8f01716774a960073e944823ab727cc867a8f6 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Wed, 26 Jul 2023 06:29:03 -0600 Subject: chore: improve lint setup (#397) - update eslint config to closely mirror the ones from ferdium-app - add .eslintignore - opt in to eslint `reportUnusedDisableDirectives` config option - remove `trailingComma: all` from `prettier` config which is default in `prettier` v3 - autofix or disable a lot of lint issues throughout codebase - add `volta` configuration to `package.json` to autoload correct `node` and `pnpm` versions - upgrade all `eslint` and `prettier` related dependencies to latest - update lint:fix npm script - reformat touched files with prettier - bumped up minor version for all recipes that have changes - introduced injection of 'service.css' where it was missing in many recipes --------- Co-authored-by: Vijay A --- recipes/help-scout/package.json | 2 +- recipes/help-scout/webview.js | 235 ++++++++++++++++++++-------------------- 2 files changed, 121 insertions(+), 116 deletions(-) (limited to 'recipes/help-scout') diff --git a/recipes/help-scout/package.json b/recipes/help-scout/package.json index 9048edc..0ff08a3 100644 --- a/recipes/help-scout/package.json +++ b/recipes/help-scout/package.json @@ -1,7 +1,7 @@ { "id": "help-scout", "name": "Help Scout", - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "config": { "serviceURL": "https://www.helpscout.com" diff --git a/recipes/help-scout/webview.js b/recipes/help-scout/webview.js index bd84dd7..c7f7c94 100644 --- a/recipes/help-scout/webview.js +++ b/recipes/help-scout/webview.js @@ -1,9 +1,9 @@ -const _path = _interopRequireDefault(require('path')); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +const _path = _interopRequireDefault(require('path')); + /** * Help Scout integration plugin for Ferdium * @@ -11,110 +11,112 @@ function _interopRequireDefault(obj) { * @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'); - }); - }); - } +const ticketScripts = { + init() { + this.processCopy(); + }, + /** + * Handles clicking the copy link + * + * @since 1.2.0 + * @return {void} + */ + processCopy() { + $('#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); +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 () { + const m = $(this).find('a:nth-child(2)').find('.count').text(); + const 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 * @@ -122,13 +124,16 @@ module.exports = (Ferdium) => { * @return {void} */ function addCopyLink() { - if ($('.convo-toolbar').length > 0 && $('#copyLink').length === 0) { - $('#actions-dd .more').append('
  • Copy Link
  • '); - $('.c-convo-toolbar').after(''); - } + if ($('.convo-toolbar').length > 0 && $('#copyLink').length === 0) { + $('#actions-dd .more').append( + '
  • Copy Link
  • ', + ); + $('.c-convo-toolbar').after( + '', + ); + } } - /** * Process copying URLs to clipboard * @@ -136,28 +141,28 @@ function addCopyLink() { * @return {void} */ function copyToClipboard() { - let targetId = '_hiddenURLField'; - let target = document.querySelector(targetId); + const 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); - } + 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; + target.textContent = window.location.href; - let currentFocus = document.activeElement; + const currentFocus = document.activeElement; - target.focus(); - target.setSelectionRange(0, target.value.length); + target.focus(); + target.setSelectionRange(0, target.value.length); - document.execCommand('copy'); + document.execCommand('copy'); - if(currentFocus && typeof currentFocus.focus === 'function') { - currentFocus.focus(); - } + if (currentFocus && typeof currentFocus.focus === 'function') { + currentFocus.focus(); + } } -- cgit v1.2.3-70-g09d2