index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. new Vue({
  2. el: '#pageContainer',
  3. data: {
  4. iframeHtml: '<iframe src="https://www.remove.bg/" frameborder="0" width="100%" height="100%"></iframe>',
  5. enter: false
  6. },
  7. methods: {
  8. permission: function (callback) {
  9. chrome.permissions.request({
  10. permissions: ['webRequest', 'webRequestBlocking']
  11. }, (granted) => {
  12. if (granted) {
  13. callback && callback();
  14. } else {
  15. alert('必须接受授权,才能正常使用!');
  16. }
  17. });
  18. },
  19. loadTools: function () {
  20. if (this.enter) return;
  21. this.permission(() => {
  22. let MSG_TYPE = Tarp.require('../static/js/msg_type');
  23. chrome.runtime.sendMessage({
  24. type: MSG_TYPE.REMOVE_PERSON_IMG_BG
  25. }, () => {
  26. this.enter = true;
  27. this.$refs.btnEnter.innerHTML = '正在进入,请稍后......';
  28. this.$refs.boxIframe.innerHTML = this.iframeHtml;
  29. let opacity = 1;
  30. let intervalId = window.setInterval(() => {
  31. opacity -= 0.02;
  32. if (opacity <= 0) {
  33. window.clearInterval(intervalId);
  34. this.$refs.overlay.remove();
  35. } else {
  36. this.$refs.overlay.style.opacity = opacity;
  37. }
  38. }, 30);
  39. });
  40. });
  41. },
  42. }
  43. });