aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/discord/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/discord/webview.js')
-rw-r--r--recipes/discord/webview.js61
1 files changed, 35 insertions, 26 deletions
diff --git a/recipes/discord/webview.js b/recipes/discord/webview.js
index c0c764d..ef56336 100644
--- a/recipes/discord/webview.js
+++ b/recipes/discord/webview.js
@@ -1,9 +1,9 @@
1const _path = _interopRequireDefault(require('path'));
2
3function _interopRequireDefault(obj) { 1function _interopRequireDefault(obj) {
4 return obj && obj.__esModule ? obj : { default: obj }; 2 return obj && obj.__esModule ? obj : { default: obj };
5} 3}
6 4
5const _path = _interopRequireDefault(require('path'));
6
7module.exports = (Ferdium, settings) => { 7module.exports = (Ferdium, settings) => {
8 const getMessages = () => { 8 const getMessages = () => {
9 let directCount = 0; 9 let directCount = 0;
@@ -27,30 +27,39 @@ module.exports = (Ferdium, settings) => {
27 Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); 27 Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
28 28
29 // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences 29 // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences
30 document.addEventListener('click', event => { 30 document.addEventListener(
31 const link = event.target.closest('a[href^="http"]'); 31 'click',
32 const button = event.target.closest('button[title^="http"]'); 32 event => {
33 33 const link = event.target.closest('a[href^="http"]');
34 if (link || button) { 34 const button = event.target.closest('button[title^="http"]');
35 const url = link ? link.getAttribute('href') : button.getAttribute('title'); 35
36 const skipDomains = [/^https:\/\/discordapp\.com\/channels\//i, /^https:\/\/discord\.com\/channels\//i]; 36 if (link || button) {
37 37 const url = link
38 let stayInsideDiscord; 38 ? link.getAttribute('href')
39 skipDomains.every(skipDomain => { 39 : button.getAttribute('title');
40 stayInsideDiscord = skipDomain.test(url); 40 const skipDomains = [
41 return !stayInsideDiscord; 41 /^https:\/\/discordapp\.com\/channels\//i,
42 }); 42 /^https:\/\/discord\.com\/channels\//i,
43 43 ];
44 if (!Ferdium.isImage(link) && !stayInsideDiscord) { 44
45 event.preventDefault(); 45 let stayInsideDiscord;
46 event.stopPropagation(); 46 skipDomains.every(skipDomain => {
47 47 stayInsideDiscord = skipDomain.test(url);
48 if (settings.trapLinkClicks === true) { 48 return !stayInsideDiscord;
49 window.location.href = url; 49 });
50 } else { 50
51 Ferdium.openNewWindow(url); 51 if (!Ferdium.isImage(link) && !stayInsideDiscord) {
52 event.preventDefault();
53 event.stopPropagation();
54
55 if (settings.trapLinkClicks === true) {
56 window.location.href = url;
57 } else {
58 Ferdium.openNewWindow(url);
59 }
52 } 60 }
53 } 61 }
54 } 62 },
55 }, true); 63 true,
64 );
56}; 65};