From 890f1832a352192608441a3f848cc7e5a1946a81 Mon Sep 17 00:00:00 2001 From: keplyx Date: Thu, 8 Aug 2019 22:07:49 +0200 Subject: [PATCH] Inject custom css in webview --- screens/PlanexScreen.js | 15 +++++++++++++++ screens/SelfMenuScreen.js | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/screens/PlanexScreen.js b/screens/PlanexScreen.js index f34db8e..29eb6d9 100644 --- a/screens/PlanexScreen.js +++ b/screens/PlanexScreen.js @@ -16,6 +16,8 @@ type Props = { const PLANEX_URL = 'http://planex.insa-toulouse.fr/'; +const CUSTOM_CSS_LINK = 'https://srv-falcon.etud.insa-toulouse.fr/~vergnet/appli-amicale/planex/generalCustom.css'; + /** * Class defining the app's planex screen. * This screen uses a webview to render the planex page @@ -23,6 +25,17 @@ const PLANEX_URL = 'http://planex.insa-toulouse.fr/'; export default class PlanningScreen extends React.Component { webview: WebView; + customInjectedJS: string; + + constructor() { + super(); + this.customInjectedJS = + 'document.querySelector(\'head\').innerHTML += \'\';' + + 'document.querySelector(\'head\').innerHTML += \'\';'; + if (ThemeManager.getNightMode()) + this.customInjectedJS += 'document.querySelector(\'head\').innerHTML += \'\';'; + } + getRefreshButton() { return ( @@ -52,6 +65,8 @@ export default class PlanningScreen extends React.Component { height: '100%', }} startInLoadingState={true} + injectedJavaScript={this.customInjectedJS} + javaScriptEnabled={true} renderLoading={() => { webview: WebView; + customInjectedJS: string; + + constructor() { + super(); + this.customInjectedJS = + 'document.querySelector(\'head\').innerHTML += \'\';' + + 'document.querySelector(\'head\').innerHTML += \'\';'; + if (!ThemeManager.getNightMode()) + this.customInjectedJS += 'document.querySelector(\'head\').innerHTML += \'\';'; + } getRefreshButton() { return ( @@ -43,6 +53,7 @@ export default class SelfMenuScreen extends React.Component { render() { const nav = this.props.navigation; + console.log(this.customInjectedJS); return ( { height: '100%', }} startInLoadingState={true} + injectedJavaScript={this.customInjectedJS} + javaScriptEnabled={true} renderLoading={() =>