common.js 665 B

12345678910111213141516171819202122232425262728293031
  1. /* global API */// msg.js
  2. 'use strict';
  3. /**
  4. * Common stuff that's loaded first so it's immediately available to all background scripts
  5. */
  6. /* exported
  7. addAPI
  8. bgReady
  9. compareRevision
  10. */
  11. const bgReady = {};
  12. bgReady.styles = new Promise(r => (bgReady._resolveStyles = r));
  13. bgReady.all = new Promise(r => (bgReady._resolveAll = r));
  14. function addAPI(methods) {
  15. for (const [key, val] of Object.entries(methods)) {
  16. const old = API[key];
  17. if (old && Object.prototype.toString.call(old) === '[object Object]') {
  18. Object.assign(old, val);
  19. } else {
  20. API[key] = val;
  21. }
  22. }
  23. }
  24. function compareRevision(rev1, rev2) {
  25. return rev1 - rev2;
  26. }