diff --git a/background/navigation-manager.js b/background/navigation-manager.js index 932dca48..c9df95e5 100644 --- a/background/navigation-manager.js +++ b/background/navigation-manager.js @@ -66,6 +66,21 @@ bgReady.all.then(() => { {hostEquals: 'sleazyfork.org', urlMatches}, ], }); + + /* + * Removes the Get Stylus button on style pages. + * Not using manifest.json as adding a content script disables the extension on update. + */ + chrome.webNavigation.onCommitted.addListener(({tabId}) => { + chrome.tabs.executeScript(tabId, { + file: '/content/install-hook-userstylesworld.js', + runAt: 'document_start', + }); + }, { + url: [ + {hostEquals: 'userstyles.world'}, + ], + }); /* * FF misses some about:blank iframes so we inject our content script explicitly */ diff --git a/content/install-hook-userstylesworld.js b/content/install-hook-userstylesworld.js new file mode 100644 index 00000000..23f7c0d8 --- /dev/null +++ b/content/install-hook-userstylesworld.js @@ -0,0 +1,22 @@ +'use strict'; + +(() => { + 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-ready' + && allowedOrigin === event.origin + ) { + sendPostMessage({type: 'usw-remove-stylus-button'}); + } + }; + + window.addEventListener('message', onPageLoaded); +})();