diff options
Diffstat (limited to 'recipes/discord')
-rw-r--r-- | recipes/discord/index.js | 18 | ||||
-rw-r--r-- | recipes/discord/package.json | 2 | ||||
-rw-r--r-- | recipes/discord/webview.js | 61 |
3 files changed, 46 insertions, 35 deletions
diff --git a/recipes/discord/index.js b/recipes/discord/index.js index cd65352..e47dd76 100644 --- a/recipes/discord/index.js +++ b/recipes/discord/index.js | |||
@@ -1,8 +1,10 @@ | |||
1 | module.exports = Ferdium => class Discord extends Ferdium { | 1 | module.exports = Ferdium => |
2 | overrideUserAgent() { | 2 | class Discord extends Ferdium { |
3 | return window.navigator.userAgent.replace('(KHTML, like Gecko)', '(KHTML, like Gecko) discord/0.0.250') | 3 | overrideUserAgent() { |
4 | .replace('Electron', 'Discord') | 4 | return window.navigator.userAgent |
5 | .replace('Ferdium', 'Discord') | 5 | .replace('(KHTML, like Gecko)', '(KHTML, like Gecko) discord/0.0.250') |
6 | .replace('Apple Mac OS X', 'Intel Mac OS X'); | 6 | .replace('Electron', 'Discord') |
7 | } | 7 | .replace('Ferdium', 'Discord') |
8 | }; | 8 | .replace('Apple Mac OS X', 'Intel Mac OS X'); |
9 | } | ||
10 | }; | ||
diff --git a/recipes/discord/package.json b/recipes/discord/package.json index 59cf22a..aed5e15 100644 --- a/recipes/discord/package.json +++ b/recipes/discord/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "discord", | 2 | "id": "discord", |
3 | "name": "Discord", | 3 | "name": "Discord", |
4 | "version": "1.7.10", | 4 | "version": "1.8.0", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://discord.com/login", | 7 | "serviceURL": "https://discord.com/login", |
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 @@ | |||
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 | module.exports = (Ferdium, settings) => { | 7 | module.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 | }; |