background.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // 此文件不要写具体逻辑,只调用函数
  2. import {
  3. twitterShortUrl,
  4. twitterPinLoginToken,
  5. twitterPinLoginCode,
  6. onInstalledMid,
  7. onInstalledUserSet,
  8. onInstalledCreateTab,
  9. checkPined,
  10. popupRePublish,
  11. setBadgeInfo,
  12. hideBadge,
  13. setMessageCount,
  14. getMessageInfo,
  15. readTaskAllMsg
  16. } from "@/logic/background/twitter";
  17. //加载bg.js 执行
  18. setMessageCount();
  19. // 消息通讯
  20. chrome.runtime.onConnect.addListener(function (port) {
  21. if (port.name === "popup") {
  22. port.onDisconnect.addListener(function() {
  23. readTaskAllMsg(() => {
  24. getMessageInfo();
  25. })
  26. });
  27. }
  28. });
  29. chrome.runtime.onInstalled.addListener(onInstalledMethod);
  30. chrome.runtime.onMessage.addListener(onMessageMethod);
  31. function onInstalledMethod() {
  32. onInstalledCreateTab()
  33. onInstalledMid()
  34. onInstalledUserSet()
  35. }
  36. function onMessageMethod(req, sender, sendResponse) {
  37. sendResponse('')
  38. if (req) {
  39. switch (req.actionType) {
  40. case "POPUP_LOGIN":
  41. twitterPinLoginToken();
  42. break;
  43. case "POPUP_PUBLISH_TWITTER_RED_PACK":
  44. popupRePublish(req);
  45. break;
  46. case 'CONTENT_GET_PINED':
  47. checkPined();
  48. break;
  49. case 'CONTENT_SET_BADGE':
  50. setBadgeInfo(req);
  51. break;
  52. case 'CONTENT_HIDE_BADGE':
  53. hideBadge();
  54. break
  55. case 'CONTENT_SEND_CODE':
  56. twitterPinLoginCode(sender, req.code);
  57. case 'CONTENT_TWITTER_LOGIN':
  58. if(req.data){
  59. twitterPinLoginToken()
  60. }
  61. break
  62. case 'CONTENT_TWITTER_SHORT_LINK':
  63. req.arr_url.forEach(item => {
  64. if (item) {
  65. twitterShortUrl(sender, item)
  66. }
  67. });
  68. break
  69. }
  70. }
  71. }