stylus/content/install-hook-userstylesworld.js
tophf 6650a37194
tidy up USW-related UI and code (#1285)
* shortened the title to "Publish" and fixed the compact mode
* made collapsed <details> share the same line in compact mode
* made hard-coded strings localizable
* IIFE modules instead of generically named globals
* unified and sorted the names of localized messages
* adjusted spacing of header items
* center auth popup to current window

Co-authored-by: Gusted <williamzijl7@hotmail.com>
2021-07-30 15:44:06 +03:00

31 lines
802 B
JavaScript

/* global API */// msg.js
'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'});
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});
});
}
}
};
window.addEventListener('message', onPageLoaded);
})();