diff options
Diffstat (limited to 'recipes/help-scout')
-rw-r--r-- | recipes/help-scout/package.json | 2 | ||||
-rw-r--r-- | recipes/help-scout/webview.js | 235 |
2 files changed, 121 insertions, 116 deletions
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 @@ | |||
1 | { | 1 | { |
2 | "id": "help-scout", | 2 | "id": "help-scout", |
3 | "name": "Help Scout", | 3 | "name": "Help Scout", |
4 | "version": "1.2.0", | 4 | "version": "1.3.0", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://www.helpscout.com" | 7 | "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 @@ | |||
1 | const _path = _interopRequireDefault(require('path')); | ||
2 | |||
3 | function _interopRequireDefault(obj) { | 1 | function _interopRequireDefault(obj) { |
4 | return obj && obj.__esModule ? obj : { default: obj }; | 2 | return obj && obj.__esModule ? obj : { default: obj }; |
5 | } | 3 | } |
6 | 4 | ||
5 | const _path = _interopRequireDefault(require('path')); | ||
6 | |||
7 | /** | 7 | /** |
8 | * Help Scout integration plugin for Ferdium | 8 | * Help Scout integration plugin for Ferdium |
9 | * | 9 | * |
@@ -11,110 +11,112 @@ function _interopRequireDefault(obj) { | |||
11 | * @since 1.2.0 | 11 | * @since 1.2.0 |
12 | */ | 12 | */ |
13 | 13 | ||
14 | |||
15 | /** | 14 | /** |
16 | * Scripts specific to ticket pages | 15 | * Scripts specific to ticket pages |
17 | * | 16 | * |
18 | * @since 1.2.0 | 17 | * @since 1.2.0 |
19 | */ | 18 | */ |
20 | let ticketScripts = { | 19 | const ticketScripts = { |
21 | init : function() { | 20 | init() { |
22 | this.processCopy(); | 21 | this.processCopy(); |
23 | }, | 22 | }, |
24 | /** | 23 | /** |
25 | * Handles clicking the copy link | 24 | * Handles clicking the copy link |
26 | * | 25 | * |
27 | * @since 1.2.0 | 26 | * @since 1.2.0 |
28 | * @return {void} | 27 | * @return {void} |
29 | */ | 28 | */ |
30 | processCopy : function() { | 29 | processCopy() { |
31 | $('#copyLink').on('click', function(e) { | 30 | $('#copyLink').on('click', function (e) { |
32 | e.preventDefault(); | 31 | e.preventDefault(); |
33 | 32 | ||
34 | copyToClipboard(); | 33 | copyToClipboard(); |
35 | 34 | ||
36 | $('.link-copied').fadeIn('fast').css('display', 'block'); | 35 | $('.link-copied').fadeIn('fast').css('display', 'block'); |
37 | }); | 36 | }); |
38 | 37 | ||
39 | $('#closeLink').on('click', function(e) { | 38 | $('#closeLink').on('click', function (e) { |
40 | e.preventDefault(); | 39 | e.preventDefault(); |
41 | 40 | ||
42 | $('.link-copied').fadeOut('fast', function () { | 41 | $('.link-copied').fadeOut('fast', function () { |
43 | $(this).css('display', 'none'); | 42 | $(this).css('display', 'none'); |
44 | }); | 43 | }); |
45 | }); | 44 | }); |
46 | } | 45 | }, |
47 | }; | 46 | }; |
48 | 47 | ||
49 | |||
50 | /** | 48 | /** |
51 | * The core Ferdium message handler | 49 | * The core Ferdium message handler |
52 | * | 50 | * |
53 | * @since 1.0.0 | 51 | * @since 1.0.0 |
54 | */ | 52 | */ |
55 | module.exports = (Ferdium) => { | 53 | module.exports = Ferdium => { |
56 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | 54 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); |
57 | 55 | ||
58 | /** | 56 | /** |
59 | * Get messages for the Ferdium loop | 57 | * Get messages for the Ferdium loop |
60 | * | 58 | * |
61 | * @since 1.0.0 | 59 | * @since 1.0.0 |
62 | * @return {void} | 60 | * @return {void} |
63 | */ | 61 | */ |
64 | function getMessages() { | 62 | function getMessages() { |
65 | let mine = ''; | 63 | let mine = ''; |
66 | let unassigned = ''; | 64 | let unassigned = ''; |
67 | let total = '0'; | 65 | let total = '0'; |
68 | 66 | ||
69 | /** | 67 | /** |
70 | * Since Help Scout loads things asyncronously, | 68 | * Since Help Scout loads things asyncronously, |
71 | * we have to trigger everything in the loop for | 69 | * we have to trigger everything in the loop for |
72 | * it to get recognized. | 70 | * it to get recognized. |
73 | */ | 71 | */ |
74 | addCopyLink(); | 72 | addCopyLink(); |
75 | ticketScripts.init(); | 73 | ticketScripts.init(); |
76 | 74 | ||
77 | if ($('.dropdown.mailboxes').length > 0 && $('.dropdown.mailboxes a').hasClass('active')) { | 75 | if ( |
78 | // Individual tickets | 76 | $('.dropdown.mailboxes').length > 0 && |
79 | mine = $('li.mine a .badge').text(); | 77 | $('.dropdown.mailboxes a').hasClass('active') |
80 | unassigned = $('li.unassigned a .badge').text(); | 78 | ) { |
81 | } else if (window.location.href === 'https://secure.helpscout.net/dashboard/') { | 79 | // Individual tickets |
82 | // Main dashboard | 80 | mine = $('li.mine a .badge').text(); |
83 | mine = 0; | 81 | unassigned = $('li.unassigned a .badge').text(); |
84 | unassigned = 0; | 82 | } else if ( |
85 | 83 | window.location.href === 'https://secure.helpscout.net/dashboard/' | |
86 | $('.card.mailbox .c-list').each(function() { | 84 | ) { |
87 | let m = $(this).find('a:nth-child(2)').find('.count').text(); | 85 | // Main dashboard |
88 | let u = $(this).find('a:first-child').find('.count').text(); | 86 | mine = 0; |
89 | 87 | unassigned = 0; | |
90 | if ($.isNumeric(m)) { | 88 | |
91 | mine += Number.parseInt(m); | 89 | $('.card.mailbox .c-list').each(function () { |
92 | } | 90 | const m = $(this).find('a:nth-child(2)').find('.count').text(); |
93 | 91 | const u = $(this).find('a:first-child').find('.count').text(); | |
94 | if ($.isNumeric(u)) { | 92 | |
95 | unassigned += Number.parseInt(u); | 93 | if ($.isNumeric(m)) { |
96 | } | 94 | mine += Number.parseInt(m); |
97 | }); | 95 | } |
98 | 96 | ||
99 | mine = mine.toString(); | 97 | if ($.isNumeric(u)) { |
100 | unassigned = unassigned.toString(); | 98 | unassigned += Number.parseInt(u); |
101 | } | 99 | } |
102 | 100 | }); | |
103 | if (mine !== '') { | 101 | |
104 | total = mine; | 102 | mine = mine.toString(); |
105 | } | 103 | unassigned = unassigned.toString(); |
106 | 104 | } | |
107 | if (unassigned !== '') { | 105 | |
108 | total = total + '/' + unassigned; | 106 | if (mine !== '') { |
109 | } | 107 | total = mine; |
110 | 108 | } | |
111 | Ferdium.setBadge(total); | 109 | |
112 | } | 110 | if (unassigned !== '') { |
113 | 111 | total = `${total}/${unassigned}`; | |
114 | Ferdium.loop(getMessages); | 112 | } |
113 | |||
114 | Ferdium.setBadge(total); | ||
115 | } | ||
116 | |||
117 | Ferdium.loop(getMessages); | ||
115 | }; | 118 | }; |
116 | 119 | ||
117 | |||
118 | /** | 120 | /** |
119 | * Add copy link to the conversation toolbar | 121 | * Add copy link to the conversation toolbar |
120 | * | 122 | * |
@@ -122,13 +124,16 @@ module.exports = (Ferdium) => { | |||
122 | * @return {void} | 124 | * @return {void} |
123 | */ | 125 | */ |
124 | function addCopyLink() { | 126 | function addCopyLink() { |
125 | if ($('.convo-toolbar').length > 0 && $('#copyLink').length === 0) { | 127 | if ($('.convo-toolbar').length > 0 && $('#copyLink').length === 0) { |
126 | $('#actions-dd .more').append('<li class="actions-dd"><a id="copyLink" class="actions-dd">Copy Link</a></li>'); | 128 | $('#actions-dd .more').append( |
127 | $('.c-convo-toolbar').after('<div class="link-copied" style="display: none">Ticket URL copied to clipboard!<a id="closeLink">x</a></div>'); | 129 | '<li class="actions-dd"><a id="copyLink" class="actions-dd">Copy Link</a></li>', |
128 | } | 130 | ); |
131 | $('.c-convo-toolbar').after( | ||
132 | '<div class="link-copied" style="display: none">Ticket URL copied to clipboard!<a id="closeLink">x</a></div>', | ||
133 | ); | ||
134 | } | ||
129 | } | 135 | } |
130 | 136 | ||
131 | |||
132 | /** | 137 | /** |
133 | * Process copying URLs to clipboard | 138 | * Process copying URLs to clipboard |
134 | * | 139 | * |
@@ -136,28 +141,28 @@ function addCopyLink() { | |||
136 | * @return {void} | 141 | * @return {void} |
137 | */ | 142 | */ |
138 | function copyToClipboard() { | 143 | function copyToClipboard() { |
139 | let targetId = '_hiddenURLField'; | 144 | const targetId = '_hiddenURLField'; |
140 | let target = document.querySelector(targetId); | 145 | let target = document.querySelector(targetId); |
141 | 146 | ||
142 | if(!target) { | 147 | if (!target) { |
143 | target = document.createElement('textarea'); | 148 | target = document.createElement('textarea'); |
144 | target.style.position = 'absolute'; | 149 | target.style.position = 'absolute'; |
145 | target.style.left = '-9999px'; | 150 | target.style.left = '-9999px'; |
146 | target.style.top = '0'; | 151 | target.style.top = '0'; |
147 | target.id = targetId; | 152 | target.id = targetId; |
148 | document.body.append(target); | 153 | document.body.append(target); |
149 | } | 154 | } |
150 | 155 | ||
151 | target.textContent = window.location.href; | 156 | target.textContent = window.location.href; |
152 | 157 | ||
153 | let currentFocus = document.activeElement; | 158 | const currentFocus = document.activeElement; |
154 | 159 | ||
155 | target.focus(); | 160 | target.focus(); |
156 | target.setSelectionRange(0, target.value.length); | 161 | target.setSelectionRange(0, target.value.length); |
157 | 162 | ||
158 | document.execCommand('copy'); | 163 | document.execCommand('copy'); |
159 | 164 | ||
160 | if(currentFocus && typeof currentFocus.focus === 'function') { | 165 | if (currentFocus && typeof currentFocus.focus === 'function') { |
161 | currentFocus.focus(); | 166 | currentFocus.focus(); |
162 | } | 167 | } |
163 | } | 168 | } |