install-hook-greasyfork.js 736 B

123456789101112131415161718192021
  1. /* global API */// msg.js
  2. 'use strict';
  3. // onCommitted may fire twice
  4. // Note, we're checking against a literal `1`, not just `if (truthy)`,
  5. // because <html id="INJECTED"> is exposed per HTML spec as a global variable and `window.INJECTED`.
  6. if (window.INJECTED_GREASYFORK !== 1) {
  7. window.INJECTED_GREASYFORK = 1;
  8. addEventListener('message', async function onMessage(e) {
  9. if (e.origin === location.origin &&
  10. e.data &&
  11. e.data.name &&
  12. e.data.type === 'style-version-query') {
  13. removeEventListener('message', onMessage);
  14. const style = await API.usercss.find(e.data) || {};
  15. const {version} = style.usercssData || {};
  16. postMessage({type: 'style-version', version}, '*');
  17. }
  18. });
  19. }