From 11f9e880b4edc51bf0f4e9c536f9e6dc24ba2815 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sun, 30 Jul 2023 15:10:46 +0530 Subject: [PATCH] Update google-calendar recipe to load external scripts to fix CSP error https://github.com/ferdium/ferdium-app/issues/1086\#issuecomment-1656926137 --- recipes/google-calendar/package.json | 2 +- recipes/google-calendar/webview.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/recipes/google-calendar/package.json b/recipes/google-calendar/package.json index 79e94fe36..a7dc23a0a 100644 --- a/recipes/google-calendar/package.json +++ b/recipes/google-calendar/package.json @@ -1,7 +1,7 @@ { "id": "google-calendar", "name": "Google Calendar", - "version": "2.4.0", + "version": "2.4.1", "license": "MIT", "aliases": [ "google-calendar", diff --git a/recipes/google-calendar/webview.js b/recipes/google-calendar/webview.js index 3921dea98..7a8ae59e3 100644 --- a/recipes/google-calendar/webview.js +++ b/recipes/google-calendar/webview.js @@ -7,12 +7,31 @@ const _path = _interopRequireDefault(require('path')); module.exports = Ferdium => { // if the user is on googlecalendar landing page, go to the login page. if ( - location.hostname === 'workspace.google.com' && + location.hostname == 'workspace.google.com' && location.href.includes('products/calendar/') ) { location.href = 'https://accounts.google.com/AccountChooser?continue=https://calendar.google.com/u/0/'; } - Ferdium.injectCSS(_path.default.join(__dirname, 'calendar.css')); - Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); + Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); + Ferdium.injectCSS( + 'https://cdn.statically.io/gh/ferdium/ferdium-recipes/main/recipes/google-calendar/calendar.css', + ); + Ferdium.injectJSUnsafe( + 'https://cdn.statically.io/gh/ferdium/ferdium-recipes/main/recipes/google-calendar/webview-unsave.js', + ); + + // Workaround for loading darkmode.css + const cssId = 'cssDarkModeWorkaround'; + if (!document.querySelector(cssId)) { + const head = document.querySelectorAll('head')[0]; + const link = document.createElement('link'); + link.id = cssId; + link.rel = 'stylesheet'; + link.type = 'text/css'; + link.href = + 'https://cdn.statically.io/gh/ferdium/ferdium-recipes/main/recipes/google-calendar/darkmode.css'; + link.media = 'all'; + head.append(link); + } };