2021-06-29 09:36:59 +00:00
|
|
|
/* global API */// msg.js
|
2021-04-30 13:39:07 +00:00
|
|
|
'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
|
|
|
|
&& allowedOrigin === event.origin
|
|
|
|
) {
|
2021-07-30 12:52:27 +00:00
|
|
|
switch (event.data.type) {
|
|
|
|
case 'usw-ready': {
|
|
|
|
sendPostMessage({type: 'usw-remove-stylus-button'});
|
2021-06-29 09:36:59 +00:00
|
|
|
|
2021-07-30 12:52:27 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-06-29 09:36:59 +00:00
|
|
|
}
|
2021-04-30 13:39:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', onPageLoaded);
|
|
|
|
})();
|