popup.js 661 B

123456789101112131415161718192021222324252627
  1. function initPopup(res) {
  2. document.body.style.width = res.width
  3. document.body.style.height = res.height
  4. }
  5. window.onload = () => {
  6. chrome.storage.sync.get({ config: '' }, (item) => {
  7. if (item.config) {
  8. let config = JSON.parse(item.config)
  9. initPopup(config.popup)
  10. }
  11. })
  12. updateConfig()
  13. window.addEventListener('message', function (e) {
  14. chrome.storage.sync.set({ iframe: e.data });
  15. }, false)
  16. chrome.storage.sync.get({ iframe: '' }, (item) => {
  17. if (item.iframe) {
  18. document.querySelector('iframe').contentWindow.postMessage(item.iframe, '*')
  19. }
  20. });
  21. }