stylus/content/install-hook-userstylesworld.js

31 lines
802 B
JavaScript
Raw Normal View History

/* 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') {
2021-07-20 12:56:45 +00:00
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);
})();