From fcc8765fd809ebbd114881083ac5f2ad4a9ba068 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Fri, 24 Apr 2020 16:17:49 +0200 Subject: Update agent agent configuration --- docs/backend_api.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'docs/backend_api.md') diff --git a/docs/backend_api.md b/docs/backend_api.md index dfc9f22..512912b 100644 --- a/docs/backend_api.md +++ b/docs/backend_api.md @@ -44,28 +44,35 @@ module.exports = Ferdi => class RocketChat extends Ferdi { ``` ### overrideUserAgent() -Validate if the given URL is a valid service instance. +Override the user agent used inside the service webview. #### Returns -`Boolean` +`String` #### Usage ```js -// Discord integration module.exports = Ferdi => class Discord extends Ferdi { overrideUserAgent() { - const useragent = window.navigator.userAgent; - - // Quick and dirty hackfix - const parts = useragent.split('(KHTML, like Gecko)'); - - return parts.join('(KHTML, like Gecko) discord/0.0.248').replace('Electron', 'Discord').replace('Ferdi', 'Discord'); + // Remove Ferdi's signature from the user agent + return window.navigator.userAgent.replace( + /(Ferdi|Electron)\/\S+ \([^)]+\)/g, + "" + ); } }; +``` +```js +module.exports = Ferdi => class Example extends Ferdi { + overrideUserAgent() { + // Use a completely different user agent + return "Mozilla/2.02Gold (Win95; I)"; + } +}; ``` + ### Events Ferdi recipes can hook into the [electron webview events](https://electron.atom.io/docs/api/webview-tag/#dom-events) to trigger custom functions. -- cgit v1.2.3-54-g00ecf