|
@@ -1,71 +1,17 @@
|
|
|
// 此文件不要写具体逻辑,只调用函数
|
|
|
-import { pageUrl } from '@/http/configAPI'
|
|
|
import {
|
|
|
twitterShortUrl,
|
|
|
twitterPinLoginToken,
|
|
|
twitterPinLoginCode,
|
|
|
onInstalledMid,
|
|
|
- onInstalledUserSet
|
|
|
+ onInstalledUserSet,
|
|
|
+ onInstalledCreateTab,
|
|
|
+ checkPined,
|
|
|
+ popupRePublish,
|
|
|
+ setBadgeInfo,
|
|
|
+ hideBadge
|
|
|
} from "@/logic/background/twitter";
|
|
|
|
|
|
-import { setChromeStorage, getChromeCookie , removeChromeCookie } from "@/uilts/chromeExtension";
|
|
|
-
|
|
|
-
|
|
|
-chrome.runtime.onInstalled.addListener(onInstalledMethod);
|
|
|
-
|
|
|
-chrome.runtime.onMessage.addListener(onMessageMethod);
|
|
|
-
|
|
|
-function onInstalledMethod() {
|
|
|
- let cookiesParams = {
|
|
|
- name: 'pickup_info',
|
|
|
- url: pageUrl
|
|
|
- }
|
|
|
- getChromeCookie(cookiesParams, (res) => {
|
|
|
- let { postNickName, srcContentId } = res;
|
|
|
- if (res && postNickName && srcContentId) {
|
|
|
- let url = `https://twitter.com/${postNickName}/status/${srcContentId}`
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- removeChromeCookie(cookiesParams)
|
|
|
- } else {
|
|
|
- chrome.tabs.create({
|
|
|
- url: "https://twitter.com",
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- onInstalledMid()
|
|
|
- onInstalledUserSet()
|
|
|
-}
|
|
|
-
|
|
|
-function onMessageMethod(req, sender, sendResponse) {
|
|
|
- if (req) {
|
|
|
- switch (req.method) {
|
|
|
- case "POPUP_LOGIN":
|
|
|
- popupLogin(sendResponse);
|
|
|
- break;
|
|
|
- case "POPUP_PUBLISH_TWITTER_RED_PACK":
|
|
|
- setChromeStorage({
|
|
|
- popupShowPublishDialog: JSON.stringify({
|
|
|
- show: true,
|
|
|
- srcContent: req.data.srcContent,
|
|
|
- postId: req.data.postId
|
|
|
- }),
|
|
|
- });
|
|
|
- chrome.tabs.create({
|
|
|
- url: "https://twitter.com",
|
|
|
- });
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return true; // remove this line to make the call sync!
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-function popupLogin() {
|
|
|
- twitterPinLoginToken();
|
|
|
-}
|
|
|
-
|
|
|
// 消息通讯
|
|
|
chrome.runtime.onConnect.addListener(function (port) {
|
|
|
port.onMessage.addListener(function (res) {
|
|
@@ -83,33 +29,35 @@ chrome.runtime.onConnect.addListener(function (port) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
|
|
|
- sendResponse('');
|
|
|
- switch (req.actionType) {
|
|
|
- case 'CONTENT_GET_PINED':
|
|
|
- chrome.action.getUserSettings(res => {
|
|
|
- let { isOnToolbar } = res;
|
|
|
- console.log('isOnToolbar', isOnToolbar)
|
|
|
- if (!isOnToolbar) {
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BG_SHOW_PIN_TIPS'
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- break;
|
|
|
- }
|
|
|
-})
|
|
|
+chrome.runtime.onInstalled.addListener(onInstalledMethod);
|
|
|
|
|
|
+chrome.runtime.onMessage.addListener(onMessageMethod);
|
|
|
|
|
|
-function sendActivetabMessage(message = {}) {
|
|
|
- chrome.tabs.query({
|
|
|
- active: true,
|
|
|
- currentWindow: true
|
|
|
- }, (tabs) => {
|
|
|
- chrome.tabs.sendMessage(tabs[0].id, message, res => {
|
|
|
- console.log(res)
|
|
|
- })
|
|
|
- })
|
|
|
+function onInstalledMethod() {
|
|
|
+ onInstalledCreateTab()
|
|
|
+ onInstalledMid()
|
|
|
+ onInstalledUserSet()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|