123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // 此文件不要写具体逻辑,只调用函数
- import {
- twitterShortUrl,
- twitterPinLoginToken,
- twitterPinLoginCode,
- onInstalledMid,
- onInstalledUserSet,
- onInstalledCreateTab,
- checkPined,
- popupRePublish,
- setBadgeInfo,
- hideBadge,
- setMessageCount,
- discordLoginCode,
- saveDiscordAuthWindowId,
- onDisconnectHandler,
- getMessageInfo
- } from "@/logic/background/twitter";
- import { PingPong } from "@/logic/background/help";
- import {
- facebookShareSuccess
- } from "@/logic/background/facebook";
- //加载bg.js 执行
- setMessageCount();
- // 消息通讯
- chrome.runtime.onConnect.addListener(function (port) {
- port.onDisconnect.addListener(function () {
- onDisconnectHandler(port);
- });
- });
- // 当有可用更新时触发
- chrome.runtime.onUpdateAvailable.addListener(() => {
- chrome.runtime.reload()
- })
- chrome.runtime.onInstalled.addListener(onInstalledMethod);
- chrome.runtime.onMessage.addListener(onMessageMethod);
- // 定时器
- chrome.alarms.onAlarm.addListener(function (alarm) {
- // console.log("onAlarm-", alarm);
- switch (alarm.name) {
- case 'denetChromeAlarm':
- getMessageInfo();
- break
- case 'PingPong':
- PingPong()
- break;
- }
- });
- function onInstalledMethod() {
- onInstalledCreateTab()
- onInstalledMid()
- onInstalledUserSet()
-
- // pingpang
- chrome.alarms.create('PingPong', {
- //1分鐘之後開始(該值不能小於1)
- delayInMinutes: 2,
- //開始後每一分鐘執行一次(該值不能小于1)
- periodInMinutes: 4
- });
- }
- function onMessageMethod(req, sender, sendResponse) {
- sendResponse('')
- if (req) {
- switch (req.actionType) {
- case "POPUP_LOGIN":
- twitterPinLoginToken();
- break;
- case "POPUP_PUBLISH_TWITTER_RED_PACK":
- popupRePublish(req);
- break;
- case 'CONTENT_GET_PINED':
- checkPined();
- break;
- case 'CONTENT_SET_BADGE':
- setBadgeInfo(req);
- break;
- case 'CONTENT_HIDE_BADGE':
- hideBadge();
- break
- case 'CONTENT_SEND_CODE':
- twitterPinLoginCode(sender, req.code);
- case 'CONTENT_TWITTER_LOGIN':
- if (req.data) {
- twitterPinLoginToken()
- }
- break
- case 'CONTENT_TWITTER_SHORT_LINK':
- req.arr_url.forEach(item => {
- if (item) {
- twitterShortUrl(sender, item)
- }
- });
- break
- case "CONTENT_SEND_DISCORD_AUTH_CODE":
- discordLoginCode(req, sender);
- break
- case 'RED_PACKET_SAVE_DISCORD_AUTH_WINDOW_ID':
- saveDiscordAuthWindowId(req);
- break;
- case 'CONTENT_FACEBOOK_SHARE_SUCCESS':
- facebookShareSuccess(req, sender);
- break;
- case 'CONTENT_PONG':
- console.log('CONTENT_PONG')
- break
- }
- }
- }
|