ToolBox.js 3.0 KB

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