From 793f14c5876770c390c6532de605c68dce0b6954 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 30 Apr 2021 15:08:39 +0200 Subject: [PATCH] Switch to more flexible messaging --- background/navigation-manager.js | 2 +- content/install-hook-userstylesworld.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/background/navigation-manager.js b/background/navigation-manager.js index 78417f15..c9df95e5 100644 --- a/background/navigation-manager.js +++ b/background/navigation-manager.js @@ -78,7 +78,7 @@ bgReady.all.then(() => { }); }, { url: [ - {hostEquals: 'userstyles.world', urlMatches: '/style/\\d+[^/]*/[a-z-0-9]+$'}, + {hostEquals: 'userstyles.world'}, ], }); /* diff --git a/content/install-hook-userstylesworld.js b/content/install-hook-userstylesworld.js index aaa98364..23f7c0d8 100644 --- a/content/install-hook-userstylesworld.js +++ b/content/install-hook-userstylesworld.js @@ -3,12 +3,18 @@ (() => { const allowedOrigin = 'https://userstyles.world'; + const sendPostMessage = message => { + if (allowedOrigin === location.origin) { + window.postMessage(message, location.origin); + } + }; + const onPageLoaded = event => { if (event.data - && event.data.type === 'usw-remove-stylus-button' + && event.data.type === 'usw-ready' && allowedOrigin === event.origin ) { - document.querySelector('a#stylus').remove(); + sendPostMessage({type: 'usw-remove-stylus-button'}); } };