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
|
|
|
|
&& event.data.type === 'usw-ready'
|
|
|
|
&& allowedOrigin === event.origin
|
|
|
|
) {
|
|
|
|
sendPostMessage({type: 'usw-remove-stylus-button'});
|
2021-06-29 09:36:59 +00:00
|
|
|
|
2021-07-02 00:12:24 +00:00
|
|
|
if (location.pathname === '/api/oauth/style/new') {
|
2021-06-29 09:36:59 +00:00
|
|
|
API.styles.find({_isUswLinked: true}).then(style => {
|
2021-07-07 14:07:29 +00:00
|
|
|
style.sourceCode = style.tmpSourceCode;
|
2021-06-29 09:36:59 +00:00
|
|
|
sendPostMessage({type: 'usw-fill-new-style', data: style});
|
|
|
|
});
|
|
|
|
}
|
2021-04-30 13:39:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', onPageLoaded);
|
|
|
|
})();
|