소스 검색

[edit] fid v2

wenliming 2 년 전
부모
커밋
16e512e6dc
7개의 변경된 파일848개의 추가작업 그리고 1086개의 파일을 삭제
  1. 172 1065
      package-lock.json
  2. 3 2
      src/entry/background.js
  3. 6 0
      src/entry/content.js
  4. 9 1
      src/logic/background/twitter.js
  5. 51 9
      src/logic/content/help/twitter.js
  6. 6 0
      src/uilts/chromeExtension.js
  7. 601 9
      yarn.lock

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 172 - 1065
package-lock.json


+ 3 - 2
src/entry/background.js

@@ -21,7 +21,8 @@ import {
     getTwitterNftPostPre,
     nftTxtPublish,
     getSysMessage,
-    checkShowPublishDialog
+    checkShowPublishDialog,
+    cacheFID
 } from "@/logic/background/twitter";
 import Report from "@/log-center/log"
 import { PingPong, httpNetWork, httpContentToBack } from "@/logic/background/help";
@@ -147,7 +148,7 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
 
 function thenInstalledMethod({ reason }) {
     try {
-
+        cacheFID();
         onInstalledCreateTab({ reason })
         onInstalledUserSet()
         // pingpang

+ 6 - 0
src/entry/content.js

@@ -38,6 +38,9 @@ import {
     showPublishDialog,
     getExtensionStorgeDataForIframe
 } from "@/logic/content/twitter.js";
+
+import { setFId } from '@/logic/content/help/twitter'
+
 import denet from '@/denet'
 import { httpBackToContentCallBack } from '@/uilts/chromeExtension.js'
 import {
@@ -145,6 +148,9 @@ const newOnMessageMethod = (res) => {
         case 'IFRAME_DOM_GET_TWEET_TEXT':
             dom.getContentByTwitterID({info, data})
             break;
+        case 'WEB_CREATE_FID_FINISH':
+            setFId(res.data);
+            break;
     }
 }
 

+ 9 - 1
src/logic/background/twitter.js

@@ -1,5 +1,5 @@
 import { fetchTtwitterRequestToken, fetchTwitterLogin, fetchTwitterShortUrl, fetchAllMessageInfo, fetchReadTaskAllMsg, getDiscordUserInfo, fetchGetTwitterNftPostPre, fetchPublish, fetchGetAllUnReadNotices } from '@/logic/background/fetch/twitter.js'
-import { LANDING_PAGE, WEBSITE_USER_INFO, LANDING_PAGE_MID, setChromeStorage, setChromeCookie, getChromeCookie, getChromeStorage, removeChromeCookie, LANDING_PAGE_JUMP_INFO } from '@/uilts/chromeExtension.js'
+import { LANDING_PAGE, WEBSITE_USER_INFO, LANDING_PAGE_MID, setChromeStorage, setChromeCookie, getChromeCookie, getChromeStorage, removeChromeCookie, LANDING_PAGE_JUMP_INFO, LANDING_PAGE_FID } from '@/uilts/chromeExtension.js'
 import { guid } from '@/uilts/help.js'
 import { discordAuthRedirectUri } from '@/http/configAPI'
 import { setContentMessage } from '@/logic/background/help.js'
@@ -220,6 +220,14 @@ export function twitterShortUrl(sender, url) {
     }
 }
 
+export function cacheFID() {
+  getChromeCookie(LANDING_PAGE_FID, (res) => {
+    if (res) {
+      setChromeStorage({ fid: JSON.stringify({fid: res})})
+    }
+  })
+}
+
 
 // 安装插件后获取mid
 export function onInstalledMid(cb) {

+ 51 - 9
src/logic/content/help/twitter.js

@@ -1,5 +1,6 @@
 import { getStorage, setStorage, getVisitorId, setCookie, getCookie, guid } from '@/uilts/help'
 import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
+import { pageUrl } from "@/http/configAPI.js"
 
 // 根据提示dom 跳转到推文详情页面
 export const jumpTwitterDetailByAlert = () => {
@@ -44,11 +45,41 @@ export const showEditTweet = (callback) => {
   }, 500);
 }
 
-export const setDeviceInfo = async () => {
-  const deviceStorageParams = {
-    name: 'de_net_device_id_1'
+export const addFIdIframe = (cb) => {
+  let fidIframe = document.getElementById('denet-fid-iframe');
+  if(!fidIframe) {
+    let iframe = document.createElement('iframe');
+    iframe.src = `${pageUrl}/getFId`
+    iframe.id = 'denet-fid-iframe'
+    iframe.style.cssText = 'display:none;'
+    document.querySelector('body').appendChild(iframe);
+    cb && cb(iframe);
+  }
+};
+
+const deviceStorageParams = {
+  name: 'de_net_device_id_1'
+}
+
+export const setFId = async (params) => {
+  let id = ''
+  if(params && params.data && params.data.id) {
+    id = `p_${params.data.id}`;
+  } else {
+    let res = await getVisitorId();
+    id = res && res.visitorId ? `c_${res.visitorId}` : '';
+  }
+  setStorage(deviceStorageParams.name, id);
+
+  let deviceInfo = await getChromeStorage('deviceInfo') || null;
+  if(deviceInfo) {
+    setChromeStorage({ 'deviceInfo': JSON.stringify({...deviceInfo, deviceId1: id}) });
+  } else {
+    setChromeStorage({ 'deviceInfo': JSON.stringify({ deviceId1: id}) });
   }
+};
 
+export const setDeviceInfo = async () => {
   const deviceCookieParams = {
     url: 'https://twitter.com/',
     name: 'de_net_device_id_2'
@@ -61,10 +92,13 @@ export const setDeviceInfo = async () => {
 
   let storageDeviceInfo = getStorage(deviceStorageParams.name);
   if (!storageDeviceInfo) {
-    let res = await getVisitorId();
-    let id = res && res.visitorId || '';
-    setStorage(deviceStorageParams.name, id);
-    deviceInfo.deviceId1 = id;
+    let fidRes = await getChromeStorage('fid') || {};
+    if(fidRes.fid) {
+      deviceInfo.deviceId1 = `p_${fidRes.fid}`;
+      setStorage(deviceStorageParams.name, `p_${fidRes.fid}`);
+    } else {
+      addFIdIframe()
+    }
   } else {
     deviceInfo.deviceId1 = storageDeviceInfo;
   }
@@ -78,5 +112,13 @@ export const setDeviceInfo = async () => {
     deviceInfo.deviceId2 = cookieDeviceInfo;
   }
 
-  setChromeStorage({ 'deviceInfo': JSON.stringify(deviceInfo) });
-}
+  let cacheDeviceInfo = await getChromeStorage('deviceInfo') || null;
+  if(cacheDeviceInfo) {
+    setChromeStorage({ 'deviceInfo': JSON.stringify({
+      ...cacheDeviceInfo,
+      deviceId2: deviceInfo.deviceId2
+    }) });
+  } else {
+    setChromeStorage({ 'deviceInfo': JSON.stringify(deviceInfo) });
+  }
+}

+ 6 - 0
src/uilts/chromeExtension.js

@@ -11,6 +11,12 @@ export const LANDING_PAGE_MID = {
     url: pageUrl
 }
 
+export const LANDING_PAGE_FID = {
+  name: 'fid',
+  url: pageUrl,
+  return_type: 'str'
+}
+
 export const LANDING_PAGE_JUMP_INFO = {
     name: 'jump_info',
     url: pageUrl

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 601 - 9
yarn.lock


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.