Send requested info

Add the "architecture" for style-request which currently only is "installed" but and probably will expand in the future. 

The "installed" message is now used to add the "Write a review" button and to change the "Install" button's text to "Reinstall".

Related USw commit: 2d3b0e0281


Refactor code 


Apply suggested changes
This commit is contained in:
Gusted 2021-07-28 15:45:15 +02:00
parent 6650a37194
commit b49f542742
No known key found for this signature in database
GPG Key ID: FD821B732837125F

View File

@ -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;
}
}
}
};