content.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 此文件不要写具体逻辑,只调用函数
  2. // var port = chrome.runtime.connect({
  3. // name: "hello",
  4. // });
  5. import {
  6. showGiveDialogHandler,
  7. showIframeHandler,
  8. hideIframeHandler,
  9. showTwitterPublishDialogHandler,
  10. showPinTips,
  11. init,
  12. initExecuteScript,
  13. changeQueueNum
  14. } from "@/logic/content/twitter.js";
  15. chrome.storage.onChanged.addListener(changes => {
  16. initExecuteScript(changes)
  17. })
  18. window.onload = () => {
  19. init()
  20. };
  21. window.onmessage = (res) => {
  22. if (res.data && res.data.actionType) {
  23. switch (res.data.actionType) {
  24. case "IFRAME_SHOW_IFREME":
  25. showIframeHandler();
  26. break;
  27. case "IFRAME_HIDE_IFREME":
  28. hideIframeHandler();
  29. break;
  30. case "IFRAME_SHOW_TWITTER_PUBLISH_DIALOG":
  31. showTwitterPublishDialogHandler(res.data.publishRes);
  32. break;
  33. // case "IFRAME_DO_TASK":
  34. // findTweetByIdDoTask(res.data.task_data, res.data.task_type)
  35. // break
  36. }
  37. }
  38. };
  39. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  40. sendResponse('')
  41. switch (req.actionType) {
  42. case 'BG_SHOW_PIN_TIPS':
  43. showPinTips()
  44. break
  45. case "BACK_TWITTER_LOGIN_SUCCESS":
  46. showGiveDialogHandler();
  47. break
  48. case 'BACK_TWITTER_SHORT_URL':
  49. console.log('BACK_TWITTER_SHORT_URL')
  50. changeQueueNum(1)
  51. break
  52. case 'TIME':
  53. alert('time')
  54. break
  55. }
  56. })