* API.styles.* * API.usercss.* * API.sync.* * API.worker.* * API.updater.* * simplify db: resolve with result * remove API.download * simplify download() * remove noCode param as it wastes more time/memory on copying * styleManager: switch style<->data names to reflect their actual contents * inline method bodies to avoid indirection and enable better autocomplete/hint/jump support in IDE
22 lines
727 B
JavaScript
22 lines
727 B
JavaScript
/* global API */
|
|
'use strict';
|
|
|
|
// onCommitted may fire twice
|
|
// Note, we're checking against a literal `1`, not just `if (truthy)`,
|
|
// because <html id="INJECTED"> is exposed per HTML spec as a global variable and `window.INJECTED`.
|
|
|
|
if (window.INJECTED_GREASYFORK !== 1) {
|
|
window.INJECTED_GREASYFORK = 1;
|
|
addEventListener('message', async function onMessage(e) {
|
|
if (e.origin === location.origin &&
|
|
e.data &&
|
|
e.data.name &&
|
|
e.data.type === 'style-version-query') {
|
|
removeEventListener('message', onMessage);
|
|
const style = await API.usercss.find(e.data) || {};
|
|
const {version} = style.usercssData || {};
|
|
postMessage({type: 'style-version', version}, '*');
|
|
}
|
|
});
|
|
}
|