From 6f5e4a00588aefdda7a5a1cfe70935870e7e234a Mon Sep 17 00:00:00 2001 From: Bennett Date: Tue, 22 Sep 2020 20:56:48 +0200 Subject: Unpack recipes and update recipes icons (#292) Co-authored-by: Amine Mouafik --- recipes/lastpass/webview.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 recipes/lastpass/webview.js (limited to 'recipes/lastpass/webview.js') diff --git a/recipes/lastpass/webview.js b/recipes/lastpass/webview.js new file mode 100644 index 0000000..4fdd007 --- /dev/null +++ b/recipes/lastpass/webview.js @@ -0,0 +1,50 @@ +"use strict"; + +const { + remote +} = require('electron'); + +const path = require('path'); + +const webContents = remote.getCurrentWebContents(); +const { + session +} = webContents; +setTimeout(() => { + if (document.querySelector('body').innerHTML.includes('Google Chrome 36+')) { + window.location.reload(); + } +}, 1000); +window.addEventListener('beforeunload', async () => { + try { + session.flushStorageData(); + session.clearStorageData({ + storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'] + }); + const registrations = await window.navigator.serviceWorker.getRegistrations(); + registrations.forEach(r => { + r.unregister(); + console.log('ServiceWorker unregistered'); + }); + } catch (err) { + console.err(err); + } +}); + +module.exports = Franz => { + const getMessages = function getMessages() { + const elements = document.querySelectorAll('.CxUIE, .unread'); + let count = 0; + + for (let i = 0; i < elements.length; i += 1) { + if (elements[i].querySelectorAll('*[data-icon="muted"]').length === 0) { + count += 1; + } + } + + Franz.setBadge(count); + }; + + Franz.injectCSS(path.join(__dirname, 'service.css')); + Franz.loop(getMessages); +}; \ No newline at end of file -- cgit v1.2.3-70-g09d2