From e1b65ae21f18ed42096b47f651977d1a99decb16 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 30 Jul 2021 14:52:27 +0200 Subject: [PATCH] Send requested info (#1294) --- content/install-hook-userstylesworld.js | 33 +++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/content/install-hook-userstylesworld.js b/content/install-hook-userstylesworld.js index 9aa3430c..59a3ee68 100644 --- a/content/install-hook-userstylesworld.js +++ b/content/install-hook-userstylesworld.js @@ -12,16 +12,35 @@ const onPageLoaded = event => { if (event.data - && event.data.type === 'usw-ready' && allowedOrigin === event.origin ) { - sendPostMessage({type: 'usw-remove-stylus-button'}); + switch (event.data.type) { + case 'usw-ready': { + sendPostMessage({type: 'usw-remove-stylus-button'}); - if (location.pathname === '/api/oauth/style/new') { - const styleId = Number(new URLSearchParams(location.search).get('vendor_data')); - API.data.pop('usw' + styleId).then(data => { - sendPostMessage({type: 'usw-fill-new-style', data}); - }); + if (location.pathname === '/api/oauth/style/new') { + const styleId = Number(new URLSearchParams(location.search).get('vendor_data')); + API.data.pop('usw' + styleId).then(data => { + sendPostMessage({type: 'usw-fill-new-style', data}); + }); + } + break; + } + case 'usw-style-info-request': { + switch (event.data.requestType) { + case 'installed': { + API.styles.find({updateUrl: `https://userstyles.world/api/style/${event.data.styleID}.user.css`}) + .then(style => { + sendPostMessage({ + type: 'usw-style-info-response', + data: {installed: Boolean(style), requestType: 'installed'}, + }); + }); + break; + } + } + break; + } } } };