ToolBox.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { $ } from "@/uilts/help";
  2. import { chromeExtensionUrl } from '@/uilts/chromeExtension'
  3. export let toolbox_fixed_tweetId = ''
  4. export const toolBox = new class ToolBox {
  5. constructor() {
  6. }
  7. // 加载组件
  8. initFull() {
  9. const iframe = document.createElement('iframe')
  10. iframe.id = 'denet-tool-box-fixed'
  11. iframe.style.cssText = `
  12. width: 505px;
  13. height: 545px;
  14. position: fixed;
  15. right: 10px;
  16. top: 10px;
  17. display:none;
  18. border:medium none; filter: drop-shadow(rgba(0, 0, 0, 0.2) 0px 4px 20px);
  19. `
  20. iframe.src = chromeExtensionUrl + ('iframe/tool-box.html') + `?page_type=${'full'}`;
  21. iframe.allow = "camera *;microphone *"
  22. document.body.append(iframe)
  23. }
  24. // 切换状态
  25. switchStatus(req) {
  26. toolbox_fixed_tweetId = req.data.tweetId
  27. let dom_fixed = $('#denet-tool-box-fixed')
  28. switch (req.data.type) {
  29. case '全屏':
  30. dom_fixed.style.cssText = `
  31. display:block;
  32. width: 100%;
  33. height: 100%;
  34. position: fixed;
  35. left: 0;
  36. top: 0;
  37. border:medium none; filter: drop-shadow(rgba(0, 0, 0, 0.2) 0px 4px 20px);
  38. `
  39. break;
  40. case '固定右上角':
  41. dom_fixed.style.cssText = `
  42. display:block;
  43. width: 505px;
  44. height: 545px;
  45. position: fixed;
  46. right: 10px;
  47. top: 10px;
  48. border:medium none; filter: drop-shadow(rgba(0, 0, 0, 0.2) 0px 4px 20px);
  49. `
  50. break
  51. case '关闭':
  52. dom_fixed.style.cssText = `display:none;`
  53. toolbox_fixed_tweetId = ''
  54. break
  55. }
  56. }
  57. // 购买NFT
  58. buyNft(req) {
  59. let iframe = document.createElement('iframe')
  60. iframe.src = chromeExtensionUrl + ('iframe/tool-box-buy-nft.html') + `?postId=${req.data.postId}`;
  61. let ifAppend = document.querySelector('#denet-tool-box-buy-nft')
  62. if (ifAppend) return;
  63. let div = document.createElement(`div`);
  64. div.id = 'denet-tool-box-buy-nft';
  65. div.innerHTML = `
  66. ${iframe.outerHTML}
  67. <div class="mask_bg"></div>
  68. <style>
  69. #denet-tool-box-buy-nft { position:fixed; width:100%; height:100%; top:0; left:0; }
  70. #denet-tool-box-buy-nft iframe { position:absolute; z-index:33; top:0; left:0; width:100%; height:100%; border:medium none; }
  71. #denet-tool-box-buy-nft .mask_bg{ position:absolute; z-index:32; width:100%; height:100%; top:0; left:0; background-color:rgba(0,0,0,.5); }
  72. </style>
  73. `
  74. document.body.append(div)
  75. }
  76. hideBuyNft() {
  77. let node = document.querySelector('#denet-tool-box-buy-nft')
  78. node && node.remove()
  79. }
  80. }