content.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var port = chrome.runtime.connect({
  2. name: "hello",
  3. });
  4. import {
  5. contentTwitterPinLogin,
  6. renderDom,
  7. showGiveDialogHandler,
  8. showIframeHandler,
  9. hideIframeHandler,
  10. showTwitterPublishDialogHandler,
  11. setIframeRedPacket,
  12. } from "../logic/twitter.js";
  13. import { getChromeStorage } from "../uilts/chromeExtension";
  14. port.onMessage.addListener(function (res) {
  15. switch (res.state) {
  16. case "BACK_TWITTER_LOGIN_SUCCESS":
  17. showGiveDialogHandler();
  18. break;
  19. }
  20. });
  21. chrome.storage.onChanged.addListener(changes => {
  22. if (changes.executeScript) {
  23. let item = JSON.parse(changes.executeScript.newValue)
  24. if (item.executeScript) {
  25. location.reload()
  26. init()
  27. console.log('yeeee')
  28. }
  29. }
  30. })
  31. window.onload = () => {
  32. init()
  33. };
  34. function init() {
  35. contentTwitterPinLogin(port);
  36. renderDom(port);
  37. setIframeRedPacket();
  38. getChromeStorage("popupShowPublishDialog", (res) => {
  39. console.log("popupShowPublishDialog", res);
  40. if (res && res.show) {
  41. setTimeout(() => {
  42. showTwitterPublishDialogHandler({
  43. srcContent: res.srcContent,
  44. postId: res.postId
  45. });
  46. }, 1500);
  47. chrome.storage.local.remove("popupShowPublishDialog");
  48. }
  49. });
  50. }
  51. window.onmessage = (res) => {
  52. if (res.data && res.data.actionType) {
  53. switch (res.data.actionType) {
  54. case "IFRAME_SHOW_IFREME":
  55. showIframeHandler();
  56. break;
  57. case "IFRAME_HIDE_IFREME":
  58. hideIframeHandler();
  59. break;
  60. case "IFRAME_SHOW_TWITTER_PUBLISH_DIALOG":
  61. showTwitterPublishDialogHandler(res.data.publishRes);
  62. break;
  63. }
  64. }
  65. };