|
@@ -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) });
|
|
|
+ }
|
|
|
+}
|