twitter.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  1. import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
  2. import { throttle, getQueryString, getCookie, nextTick, getQueryStringByUrl } from '@/uilts/help'
  3. import { discordAuthRedirectUri } from '@/http/configAPI'
  4. import { reportSrcPublishEvent } from '@/http/publishApi'
  5. import Report from "@/log-center/log"
  6. import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook';
  7. import { showNFTGroupIcon, hideNFTGroupList, checkUserJoinGroup, elemAddEventListener, addJoinedGroupList } from '@/logic/content/nft';
  8. import { jumpTwitterDetailByAlert, showEditTweet } from '@/logic/content/help/twitter.js'
  9. import { clearPostContent, setGroupIconStatus } from '@/logic/content/nft.js'
  10. import { toolBox } from '@/logic/content/ToolBox'
  11. import axios from 'axios';
  12. let dom = {};
  13. let tweetAccountBindGroupInfo = {
  14. isBind: false,
  15. groupInfo: null,
  16. isInit: false
  17. }
  18. let systemInfo = {
  19. theme: 'light'
  20. }
  21. let fixProfileTabAutoTimer = null;
  22. let pin_login = false
  23. function twitterPinLogin() {
  24. if (pin_login) {
  25. return
  26. }
  27. pin_login = true
  28. if (window.location.href == 'https://api.twitter.com/oauth/authorize') {
  29. let code = document.querySelector('code')
  30. if (code) {
  31. chrome.runtime.sendMessage({ actionType: "CONTENT_SEND_CODE", code: code.innerText }, () => { })
  32. // port.postMessage({ state: 'CONTENT_SEND_CODE', code: code.innerText })
  33. }
  34. }
  35. }
  36. function getDiscordAuthCode() {
  37. if (window.location.href.indexOf(discordAuthRedirectUri) > -1) {
  38. const urlParams = new URLSearchParams(window.location.search);
  39. const code = urlParams.get('code');
  40. if (code) {
  41. chrome.runtime.sendMessage({ actionType: "CONTENT_SEND_DISCORD_AUTH_CODE", code }, () => { })
  42. }
  43. }
  44. };
  45. /**
  46. * 渲染要插入的dom,初始化逻辑
  47. * @param port
  48. */
  49. function renderDom() {
  50. if (window.location.href.indexOf('https://twitter.com') > -1) {
  51. _createBtnDom();
  52. onWindowResize();
  53. checkHasDeBtn();
  54. setTimeout(() => {
  55. _addIframe();
  56. _addDeNetBtn();
  57. _getSliderTwitterBtn();
  58. }, 800)
  59. }
  60. }
  61. /**
  62. * 展示give弹窗
  63. */
  64. export function showGiveDialogHandler(params) {
  65. let iframe = document.getElementById('iframe-content');
  66. if (iframe) {
  67. iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG', data: params }, '*');
  68. } else {
  69. _addIframe();
  70. let iframe = document.getElementById('iframe-content');
  71. iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG', data: params }, '*');
  72. }
  73. }
  74. export function showIframeHandler() {
  75. document.getElementById('iframe-content').style.display = 'block';
  76. }
  77. export function hideIframeHandler() {
  78. document.getElementById('iframe-content').style.display = 'none';
  79. }
  80. /**
  81. * 展示twitter原生发布框
  82. */
  83. let tweetPublishStore = {
  84. showPublishDialog: false
  85. }
  86. export function showTwitterPublishDialogHandler(publishRes) {
  87. let bigBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  88. if (bigBtn) {
  89. bigBtn.click();
  90. tweetPublishStore.showPublishDialog = true;
  91. } else {
  92. let smallBtn = document.querySelector('a[href="/compose/tweet"]')
  93. smallBtn && smallBtn.click();
  94. tweetPublishStore.showPublishDialog = true;
  95. }
  96. setChromeStorage({ publishData: JSON.stringify(publishRes) })
  97. addPublishTipsIframe()
  98. // _setPublishContent(publishRes.srcContent);
  99. setDialogPublishContent(publishRes.srcContent);
  100. _publishTweetEvent(publishRes, bindTwitterArtMethod);
  101. }
  102. export function twitterPublishHandler(res) {
  103. let bigBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  104. if (bigBtn) {
  105. bigBtn.click();
  106. } else {
  107. let smallBtn = document.querySelector('a[href="/compose/tweet"]')
  108. smallBtn && smallBtn.click();
  109. }
  110. nextTick(() => {
  111. document.execCommand('selectAll');
  112. }, 100).then(() => {
  113. _setPublishContent(res.srcContent, 500);
  114. })
  115. }
  116. export function showPinTips() {
  117. hidePopupPage();
  118. hideNoticeBindTweet();
  119. getChromeStorage('pinData', (res) => {
  120. if (!res || res.show) {
  121. let domPop = document.getElementById('de-pin-pop');
  122. domPop.style.display = 'block';
  123. }
  124. })
  125. }
  126. export function hidePinTips() {
  127. let pop = document.querySelector('#de-pin-pop');
  128. if (pop) {
  129. pop.style.display = 'none';
  130. }
  131. }
  132. function addPinedPop() {
  133. let domPop = document.getElementById('de-pin-pop');
  134. if (domPop) {
  135. return;
  136. }
  137. let popWrapper = document.createElement('div');
  138. popWrapper.style.cssText = 'position: fixed; height: 400px;width: 300px;top: 12px;right: 20px;border-radius: 12px;border: 0.5px solid #919191;box-sizing: border-box;padding: 20px;background: #fff;display:none';
  139. popWrapper.id = 'de-pin-pop'
  140. let img = document.createElement('img');
  141. img.src = require("@/assets/img/img-pined-guide.png");
  142. img.width = 253;
  143. let contentDom = document.createElement('div');
  144. contentDom.innerHTML = "<div style='font-weight: 500;font-size: 18px;margin-top: 20px;margin-bottom: 20px'>📌 Pin an Extension is more convenient to open😄</div><div style='display: flex; align-items: center; justify-content: space-between;'><div style='display: flex; align-items: center; font-size: 14px; color: #899099; cursor: pointer;' id='de-remind'><input id='de-check' type='checkbox'/> Don't remind</div><div class='de-pin-skip' style='font-weight: 500; font-size: 16px; color: #1D9BF0;cursor: pointer;'>Skip</div></div>"
  145. popWrapper.appendChild(img);
  146. popWrapper.appendChild(contentDom);
  147. document.querySelector('body').appendChild(popWrapper);
  148. let deCheck = document.querySelector('#de-check');
  149. let deRemind = document.querySelector('#de-remind');
  150. deCheck.onclick = function (e) {
  151. e && e.stopPropagation && e.stopPropagation();
  152. setChromeStorage({ pinData: JSON.stringify({ show: !this.checked }) })
  153. }
  154. deRemind.onclick = function () {
  155. deCheck.checked = !deCheck.checked;
  156. setChromeStorage({ pinData: JSON.stringify({ show: !deCheck.checked }) })
  157. }
  158. document.querySelector('.de-pin-skip').onclick = function () {
  159. document.querySelector('#de-pin-pop').style.display = 'none';
  160. }
  161. }
  162. function getUserInfo(cb) {
  163. getChromeStorage('userInfo', (res) => {
  164. cb && cb(res);
  165. })
  166. }
  167. // 绑定推文id所需参数
  168. export let bindTwitterArt = {
  169. needBind: false,
  170. postId: '',
  171. isBindIng: false
  172. };
  173. /**
  174. * 监听dialog内点击原生发布按钮事件
  175. * @private
  176. */
  177. function _publishTweetEvent(params, cb) {
  178. setTimeout(() => {
  179. let publishTweetBtn;
  180. let dialog = document.querySelector('div[role="dialog"]');
  181. if (dialog) {
  182. publishTweetBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  183. onClosePublishDialogHandle(dialog, params)
  184. } else {
  185. let domMain = document.querySelector('main[role="main"]');
  186. publishTweetBtn = domMain && domMain.querySelector('div[data-testid="tweetButton"]');
  187. }
  188. publishTweetBtn && publishTweetBtn.addEventListener('click', function () {
  189. bindTwitterArt.needBind = true;
  190. bindTwitterArt.postId = params.postId;
  191. tweetPublishStore.showPublishDialog = false;
  192. // checkIsShowReSend(dialog, params);
  193. cb && cb()
  194. });
  195. }, 800)
  196. }
  197. function onClosePublishDialogHandle(dom, params) {
  198. // 如果是 Tool box
  199. if (params.postType == 3) {
  200. return;
  201. }
  202. dom.querySelector('div[role="group"]').addEventListener('click', function () {
  203. setTimeout(() => {
  204. let parent = document.querySelector('div[data-testid="confirmationSheetDialog"]');
  205. if (parent) {
  206. let btnArr = parent.querySelectorAll('div[role=button]')
  207. for (let i = 0; i < btnArr.length; i++) {
  208. let btn = btnArr[i];
  209. btn.addEventListener('click', function () {
  210. tweetPublishStore.showPublishDialog = false;
  211. let taskLuckdropId = JSON.parse(params.postBizData).taskLuckdropId;
  212. noticeBindTweet({ postId: params.postId, taskLuckdropId });
  213. })
  214. }
  215. } else {
  216. setTimeout(() => {
  217. let dialog = document.querySelector('div[role="dialog"]');
  218. if (!dialog) {
  219. tweetPublishStore.showPublishDialog = false;
  220. }
  221. }, 800)
  222. }
  223. }, 1000)
  224. })
  225. }
  226. function checkIsShowReSend(dom, params) {
  227. let str = dom.querySelector('div[data-contents="true"]').innerHTML;
  228. if (str.indexOf(params.postId) < 0) {
  229. let taskLuckdropId = JSON.parse(params.postBizData).taskLuckdropId;
  230. noticeBindTweet({ postId: params.postId, taskLuckdropId });
  231. }
  232. }
  233. /**
  234. * 在输入推文区插入deNet按钮
  235. * @param parent
  236. * @param dom
  237. * @param isClick
  238. * @private
  239. */
  240. function _addDeNetEditBtn(params = {}) {
  241. let toolElem = document.querySelector('div[data-testid="toolBar"]');
  242. if (toolElem) {
  243. Report.reportLog({
  244. pageSource: Report.pageSource.mainPage,
  245. businessType: Report.businessType.buttonView,
  246. objectType: Report.objectType.buttonSecond
  247. });
  248. let innerDeIcon = toolElem.querySelector('#de-btn1');
  249. if (!innerDeIcon) {
  250. toolElem.firstChild.appendChild(createTweetToolbarDenet());
  251. popupShowGiveawayDialog();
  252. }
  253. let innerToolBoxIcon = toolElem.querySelector('#de-tool-box-btn-01');
  254. if (!innerToolBoxIcon) {
  255. toolElem.firstChild.appendChild(createTweetToolbarToolBox())
  256. }
  257. } else {
  258. setTimeout(() => {
  259. let toolElem = document.querySelector('div[data-testid="toolBar"]');
  260. if (toolElem) {
  261. Report.reportLog({
  262. pageSource: Report.pageSource.mainPage,
  263. businessType: Report.businessType.buttonView,
  264. objectType: Report.objectType.buttonSecond
  265. });
  266. let innerDeIcon = toolElem.querySelector('#de-btn1');
  267. if (!innerDeIcon) {
  268. toolElem.firstChild.appendChild(createTweetToolbarDenet());
  269. popupShowGiveawayDialog();
  270. }
  271. let innerToolBoxIcon = toolElem.querySelector('#de-tool-box-btn-01');
  272. if (!innerToolBoxIcon) {
  273. toolElem.firstChild.appendChild(createTweetToolbarToolBox())
  274. }
  275. }
  276. }, 1000)
  277. }
  278. }
  279. const popupShowGiveawayDialog = async () => {
  280. let { show = false } = await getChromeStorage('showGiveawayData') || {};
  281. if (show) {
  282. chrome.storage.local.remove("showGiveawayData");
  283. showPublishDialog()
  284. }
  285. }
  286. /**
  287. * 获取左侧twitter按钮
  288. * @private
  289. */
  290. function _getSliderTwitterBtn() {
  291. dom.tweetBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  292. dom.tweetBtn && dom.tweetBtn.addEventListener('click', function () {
  293. // _addDeNetBtnToDialog();
  294. })
  295. }
  296. /**
  297. * 添加deNet按钮
  298. * @private
  299. */
  300. function _addDeNetBtn() {
  301. setTimeout(() => {
  302. let navWidth = document.querySelector('nav[role="navigation"]').offsetWidth;
  303. addSliderNavDeBtn(navWidth < 245);
  304. let innerDeIcon = document.getElementById('de-btn1');
  305. let innerToolBoxIcon = document.getElementById('de-tool-box-btn-01');
  306. if (!innerDeIcon || !innerToolBoxIcon) {
  307. _addDeNetEditBtn();
  308. }
  309. }, 800)
  310. }
  311. /**
  312. * 获取推文输入框内dom,用于插入deNet
  313. * @param isDialogInner
  314. * @returns {Element}
  315. * @private
  316. */
  317. function _getScheduleDom(isDialogInner = false) {
  318. let scheduleBtn;
  319. if (isDialogInner) {
  320. scheduleBtn = document.querySelector('div[role="dialog"]').querySelector('[data-testid="createPollButton"]');
  321. } else {
  322. let toolBar = document.querySelector('div[data-testid="toolBar"]');
  323. if (toolBar) {
  324. scheduleBtn = toolBar.querySelector('div[data-testid="geoButton"]');
  325. }
  326. }
  327. return scheduleBtn;
  328. }
  329. /**
  330. * 插入iframe到页面
  331. * @private
  332. */
  333. function _addIframe() {
  334. // let span = document.createElement('span');
  335. // const shadowRoot = span.attachShadow({mode: 'closed'})
  336. let iframe = document.createElement('iframe');
  337. iframe.src = chrome.runtime.getURL('/iframe/publish.html')
  338. iframe.id = 'iframe-content'
  339. iframe.style.cssText = 'position:fixed;top:0px;right:0;display:block; width:100%;height:100%;z-index:10000; border: medium none;display:none';
  340. // shadowRoot.appendChild(iframe);
  341. // document.body.appendChild(span)
  342. dom.iframe = iframe;
  343. let iframeContent = document.getElementById('iframe-content');
  344. if (!iframeContent) {
  345. document.querySelector('body').appendChild(iframe);
  346. }
  347. }
  348. function addPublishTipsIframe(params = {}) {
  349. let { time = 1000 } = params;
  350. setTimeout(() => {
  351. let dialog = document.querySelector('div[role="dialog"]').querySelector('div[role="dialog"]')
  352. if (dialog) {
  353. let right = dialog.offsetLeft - 15 - 266;
  354. let iframe = document.createElement('iframe');
  355. iframe.id = 'de-publish-tips'
  356. if (params.type == 'nft') {
  357. iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html?type="nft"');
  358. } else {
  359. iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html');
  360. }
  361. iframe.style.cssText = `border: medium none; width:270px;height:500px;position: fixed; right: ${right}px; top: 5%;z-index: -1`
  362. let iframeContent = document.getElementById('de-publish-tips');
  363. if (!iframeContent) {
  364. dialog.appendChild(iframe)
  365. }
  366. }
  367. }, time)
  368. }
  369. export function noticeBindTweet(params) {
  370. hidePinTips();
  371. hidePopupPage();
  372. let iframe = document.createElement('iframe');
  373. iframe.id = 'de-notice-bind-tweet';
  374. iframe.src = chrome.runtime.getURL('/iframe/bind-tweet.html') + `?params=${JSON.stringify(params)}`;
  375. iframe.style.cssText = `border: medium none; width:400px;min-height:313px;position: fixed; right: 16px; top: 16px;border-radius: 20px;`
  376. let iframeContent = document.getElementById('de-notice-bind-tweet');
  377. if (!iframeContent) {
  378. document.querySelector('body').appendChild(iframe)
  379. }
  380. }
  381. export function hideNoticeBindTweet() {
  382. let iframeContent = document.getElementById('de-notice-bind-tweet');
  383. if (iframeContent) {
  384. document.querySelector('body').removeChild(iframeContent)
  385. }
  386. }
  387. /**
  388. * 点击deNet按钮处理
  389. * @private
  390. */
  391. function _deNetBtnClick(params = {}) {
  392. getUserInfo((res) => {
  393. if (res) {
  394. if (window.location.pathname != '/home') {
  395. if (!dom.homeBtn) {
  396. dom.homeBtn = document.querySelector('a[data-testid="AppTabBar_Home_Link"]');
  397. }
  398. dom.homeBtn.click();
  399. }
  400. showGiveDialogHandler(params);
  401. } else {
  402. let loadIcon = document.getElementById('de-btn-loading');
  403. if (loadIcon) {
  404. return;
  405. }
  406. dom && dom.deBtn && dom.deBtn.insertBefore(dom.loadingImg, dom.deBtn.querySelector('span'));
  407. setTimeout(() => {
  408. dom.loadingImg.style.transform = 'rotate(1080deg)'
  409. });
  410. setTimeout(() => {
  411. dom.loadingImg.style.transform = 'rotate(0deg)'
  412. dom.deBtn.innerHTML = '<span>DeNet<span>';
  413. }, 2000)
  414. chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_LOGIN", data: '1' }, (res) => { console.log(res) })
  415. }
  416. })
  417. }
  418. /**
  419. * 设置发布内容
  420. * @param content
  421. * @private
  422. */
  423. let isSetContent = false;
  424. export const _setPublishContent = throttle(function (content, time = 1000) {
  425. if (!isSetContent) {
  426. isSetContent = true;
  427. let inputEle = document.querySelector('div[contenteditable="true"]');
  428. if (inputEle) {
  429. inputEle.focus();
  430. }
  431. setTimeout(() => {
  432. document.execCommand("insertText", false, content);
  433. setTimeout(() => {
  434. isSetContent = false;
  435. }, 2000)
  436. }, time);
  437. }
  438. }, 800);
  439. const setDialogPublishContent = throttle(function (content) {
  440. setTimeout(() => {
  441. let inputEle;
  442. let dialog = document.querySelector('div[role="dialog"]');
  443. if (dialog) {
  444. inputEle = dialog.querySelector('div[contenteditable="true"]');
  445. } else {
  446. inputEle = document.querySelector('div[contenteditable="true"]');
  447. }
  448. const dataTransfer = new DataTransfer();
  449. dataTransfer.setData('text', content);
  450. const event = new ClipboardEvent('paste', {
  451. clipboardData: dataTransfer,
  452. bubbles: true
  453. });
  454. if (inputEle) {
  455. inputEle.dispatchEvent(event);
  456. }
  457. }, 300)
  458. }, 600);
  459. /**
  460. * 创建deNet按钮 添加到页面
  461. * @returns {{deBtn2: HTMLDivElement, deBtn1: HTMLDivElement, deBtn: HTMLSpanElement}}
  462. * @private
  463. */
  464. function _createBtnDom() {
  465. let loadingImg = document.createElement('img');
  466. loadingImg.id = 'de-btn-loading'
  467. loadingImg.src = require("@/assets/img/icon-btn-loading.png");
  468. loadingImg.style.cssText = 'width:20px;height: 20px;margin-right:3px;transition-duration: 3s;';
  469. let style = document.createElement('style');
  470. style.innerHTML = "#de-btn:hover{opacity: .9;};@-webkit-keyframes load{from{ transform: rotate(0deg);} to{transform: rotate(360deg);}}";
  471. document.getElementsByTagName('head').item(0).appendChild(style);
  472. // 左侧大屏按钮
  473. let deBtn = document.createElement('span');
  474. // const shadowDiv = document.createElement('div');
  475. deBtn.innerHTML = '<span>DeNet</span>';
  476. deBtn.id = 'de-btn';
  477. deBtn.style.cssText = 'width:90%;height: 52px;text-align:center;line-height:52px;margin-bottom: 4px;margin-top: 4px;background: linear-gradient(274.8deg, #FF9900 -3.69%, #BD00FF 69.71%, #00F0FF 122.65%);color:#fff;font-size:17px;font-weight:700;border-radius:100px;cursor: pointer;display: flex;align-items: center;justify-content: center;';
  478. // 编辑框内按钮
  479. let src = require("@/assets/img/icon-gift-pack.png");
  480. const smallDeBtnStyle = 'width:20px;height: 20px;cursor: pointer;padding: 0px 8px';
  481. const deBtn2 = document.createElement('div');
  482. deBtn2.id = 'de-btn2';
  483. deBtn2.style.cssText = smallDeBtnStyle;
  484. deBtn2.src = src
  485. // 小屏按钮
  486. const deBtn3 = document.createElement('img');
  487. deBtn3.id = 'de-btn3'
  488. deBtn3.src = require("@/assets/logo/128.png");
  489. deBtn3.style.cssText = 'width:52px;height: 52px;margin-top:20px;cursor: pointer;';
  490. deBtn.addEventListener('click', () => {
  491. Report.reportLog({
  492. pageSource: Report.pageSource.mainPage,
  493. businessType: Report.businessType.buttonClick,
  494. objectType: Report.objectType.buttonMain
  495. });
  496. _deNetBtnClick({
  497. type: 'SHOW_SELECT'
  498. });
  499. })
  500. deBtn2.addEventListener('click', () => {
  501. _deNetBtnClick();
  502. })
  503. deBtn3.addEventListener('click', () => {
  504. Report.reportLog({
  505. pageSource: Report.pageSource.mainPage,
  506. businessType: Report.businessType.buttonClick,
  507. objectType: Report.objectType.buttonMain
  508. });
  509. _deNetBtnClick({
  510. type: 'SHOW_SELECT'
  511. });
  512. })
  513. dom.deBtn = deBtn;
  514. dom.deBtn2 = deBtn2;
  515. dom.deBtn3 = deBtn3;
  516. dom.loadingImg = loadingImg;
  517. }
  518. function createTweetToolbarDenet() {
  519. let src = require("@/assets/img/icon-gift-pack.png");
  520. const smallDeBtnStyle = 'width:20px;height: 20px;cursor: pointer;padding: 0px 8px';
  521. const deBtn1 = document.createElement('img');
  522. deBtn1.id = 'de-btn1';
  523. deBtn1.style.cssText = smallDeBtnStyle;
  524. deBtn1.src = src;
  525. deBtn1.addEventListener('click', () => {
  526. Report.reportLog({
  527. pageSource: Report.pageSource.mainPage,
  528. businessType: Report.businessType.buttonClick,
  529. objectType: Report.objectType.buttonSecond
  530. });
  531. _deNetBtnClick();
  532. })
  533. return deBtn1;
  534. }
  535. function createTweetToolbarToolBox() {
  536. let src = require("@/assets/img/icon-tool-box-01.png");
  537. const smallDeBtnStyle = 'width:20px;height: 20px;cursor: pointer;padding: 0px 8px';
  538. const deToolBoxBtn = document.createElement('img');
  539. deToolBoxBtn.id = 'de-tool-box-btn-01';
  540. deToolBoxBtn.style.cssText = smallDeBtnStyle;
  541. deToolBoxBtn.src = src;
  542. deToolBoxBtn.addEventListener('click', () => {
  543. _deNetBtnClick({
  544. type: 'TOOL_BOX'
  545. })
  546. })
  547. return deToolBoxBtn;
  548. }
  549. function addSliderNavDeBtn(isSmall = false) {
  550. try {
  551. if (!isSmall) {
  552. let bigDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
  553. let deBtn = document.getElementById('de-btn');
  554. if (bigDom && !deBtn) {
  555. dom && dom.deBtn && bigDom.appendChild(dom.deBtn);
  556. Report.reportLog({
  557. pageSource: Report.pageSource.mainPage,
  558. businessType: Report.businessType.buttonView,
  559. objectType: Report.objectType.buttonMain
  560. });
  561. }
  562. } else {
  563. let smallDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
  564. let deBtn3 = document.getElementById('de-btn3');
  565. if (smallDom && !deBtn3) {
  566. dom && dom.deBtn3 && smallDom.appendChild(dom.deBtn3);
  567. Report.reportLog({
  568. pageSource: Report.pageSource.mainPage,
  569. businessType: Report.businessType.buttonView,
  570. objectType: Report.objectType.buttonMain
  571. });
  572. }
  573. }
  574. } catch (e) {
  575. console.log(e)
  576. }
  577. }
  578. function onWindowResize() {
  579. window.onresize = throttle(function () {
  580. setTabGroupIframeStyle({}, true);
  581. try {
  582. if (tweetPublishStore.showPublishDialog) {
  583. let dialog = document.querySelector('div[role="dialog"]');
  584. let dePublishTips = document.getElementById('de-publish-tips');
  585. if (dialog && !dePublishTips) {
  586. addPublishTipsIframe({ time: 0 });
  587. } else if (dialog && dePublishTips) {
  588. let dialogContent = dialog.querySelector('div[role=dialog]')
  589. if (dialogContent) {
  590. let right = dialogContent.offsetLeft - 15 - 266;
  591. dePublishTips.style.right = right + 'px';
  592. }
  593. }
  594. }
  595. if (window.innerWidth < 1273) {
  596. let bigBtn = document.querySelector('#de-btn');
  597. bigBtn && bigBtn.remove();
  598. setTimeout(() => {
  599. addSliderNavDeBtn(true);
  600. })
  601. } else {
  602. let smallBtn = document.querySelector('#de-btn3');
  603. smallBtn && smallBtn.remove();
  604. setTimeout(() => {
  605. addSliderNavDeBtn()
  606. })
  607. }
  608. } catch (e) {
  609. console.log(e)
  610. }
  611. }, 800)
  612. }
  613. function checkHasDeBtn() {
  614. try {
  615. let toolBar = document.querySelector('div[data-testid="toolBar"]');
  616. let append = toolBar && !toolBar.querySelector('#de-btn1');
  617. if (append) {
  618. _addDeNetEditBtn();
  619. }
  620. } catch (e) {
  621. console.log(e)
  622. }
  623. }
  624. /**
  625. * 点击发推,后端绑定推特id
  626. */
  627. export function bindTwitterArtMethod() {
  628. if (!bindTwitterArt.postId) {
  629. return
  630. }
  631. if (bindTwitterArt.needBind && !bindTwitterArt.isBindIng) {
  632. bindTwitterArt.isBindIng = true;
  633. reportSrcPublishEvent({
  634. params: {
  635. postId: bindTwitterArt.postId,
  636. }
  637. }).then((res) => {
  638. if (res.code == 0) {
  639. // Report.reportLog({
  640. // objectType: Report.objectType.tweetPostBinded
  641. // });
  642. bindTwitterArt.needBind = false;
  643. bindTwitterArt.postId = '';
  644. bindTwitterArt.isBindIng = false;
  645. }
  646. })
  647. }
  648. }
  649. import parseCard from './ParseCard'
  650. // 检测dom改变
  651. // 获取短链接
  652. // 查看本地是否有postid
  653. // 如果有 修改dom 返回
  654. // 如果没有 网络请求
  655. // 获取postid
  656. // 获取twitterid
  657. // 检测当前所有dom 如果没有
  658. let queue_num = 1
  659. export const changeQueueNum = (num = 0) => {
  660. queue_num = queue_num + num
  661. if (queue_num > 5) {
  662. queue_num = 5
  663. }
  664. }
  665. let main_observer = null
  666. function onChangePageMain(targetNode) {
  667. if (main_observer) {
  668. return
  669. }
  670. changeQueueNum(1)
  671. try {
  672. const config = { attributes: false, childList: true, subtree: true };
  673. const callback = (mutationsList, observer) => {
  674. changeQueueNum(1)
  675. }
  676. main_observer = new MutationObserver(callback);
  677. main_observer.observe(targetNode, config);
  678. } catch (error) {
  679. main_observer = null
  680. }
  681. }
  682. // 1.监听main改变
  683. // 2.监听卡片是否可见
  684. // 3.如果可见了 去找
  685. function setIframeRedPacket(type = 'twitter') {
  686. // 获取所有卡片参数
  687. let card_json_data
  688. switch (type) {
  689. case 'facebook':
  690. card_json_data = parseCard.parseFacebookCardParmas()
  691. for (let i in card_json_data) {
  692. parseCard.replaceFacebookPacket(card_json_data[i])
  693. }
  694. break;
  695. default:
  696. card_json_data = parseCard.parseAllDeNetCardParmas()
  697. // 过滤出可以请求的短链接
  698. parseCard.getCardParmas(card_json_data).then((res) => {
  699. for (let i in res.has_post_Id_card_data) {
  700. let item = res.has_post_Id_card_data[i];
  701. if (item && item.post_Id && item.post_Id.indexOf('nft/') >= 0) {
  702. parseCard.replaceNftDomRedPacket(item)
  703. } else if (item && item.post_Id && item.post_Id.indexOf('nft_group/') >= 0) {
  704. parseCard.replaceNftGroupDomRedPacket(item)
  705. } else if (item && item.post_Id && item.post_Id.indexOf('luckdraw/') >= 0) {
  706. item.post_Id = item.post_Id.split('luckdraw/')[1] || ''
  707. item.page_type = '抽奖'
  708. parseCard.replaceDOMRedPacket(item)
  709. } else if (item && item.post_Id && item.post_Id.indexOf('toolbox/') >= 0) {
  710. item.page_type = 'toolbox'
  711. item.post_Id = item.post_Id.split('toolbox/')[1] || ''
  712. if (item.post_Id) {
  713. parseCard.replaceIframeToolBox(item)
  714. }
  715. } else if (item && item.post_Id && !item.post_Id.includes('/')) {
  716. item.page_type = '红包'
  717. parseCard.replaceDOMRedPacket(item)
  718. }
  719. }
  720. if (res.need_net_short_url.length > 0) {
  721. // 请求短链接
  722. chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_SHORT_LINK", data: "", arr_url: res.need_net_short_url }, (res) => {
  723. if (!res) {
  724. Report.reportLog({
  725. objectType: Report.objectType.parse_card_error
  726. });
  727. }
  728. })
  729. }
  730. })
  731. break;
  732. }
  733. }
  734. // 监听点击发推 上报文案
  735. // document.addEventListener('click', (e) => {
  736. // try {
  737. // let inputEle = document.querySelector('div[contenteditable="true"]');
  738. // if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == 'tweetButton') {
  739. // // 获取文案上报
  740. // console.log(inputEle.innerText)
  741. // } else if (e.target.closest('div[data-testid=tweetButton]')) {
  742. // console.log(inputEle.innerText)
  743. // }
  744. // } catch (error) {
  745. // console.error('error', error)
  746. // }
  747. // })
  748. export function initExecuteScript(changes) {
  749. if (changes.executeScript) {
  750. let item = JSON.parse(changes.executeScript.newValue)
  751. if (item.executeScript) {
  752. init()
  753. }
  754. }
  755. if (changes.userInfo) {
  756. let item = JSON.parse(changes.userInfo.newValue)
  757. if (item) {
  758. checkUserJoinGroup(() => {
  759. showNFTGroupIcon()
  760. })
  761. }
  762. }
  763. }
  764. const createNFTIframe = ({ url, id }, callback) => {
  765. let iframe = document.createElement('iframe')
  766. iframe.id = id
  767. iframe.src = url
  768. iframe.style.cssText = 'border:medium none; width:100%; height:100%; z-index:100; position: fixed; top:0;left:0; display:none;';
  769. iframe.onload = () => {
  770. callback && callback()
  771. }
  772. document.body.appendChild(iframe);
  773. }
  774. function initParseCard() {
  775. let timer = setInterval(() => {
  776. let inTwitter = window.location.host.includes('twitter.com');
  777. let inTwitterNode = document.querySelector('main');
  778. let inFacebook = window.location.host.includes('facebook.com');
  779. let inFacebookNode = document.querySelector('#facebook');
  780. if (inTwitter && inTwitterNode) {
  781. clearInterval(timer)
  782. setInterval(() => {
  783. onChangePageMain(inTwitterNode)
  784. checkHasDeBtn()
  785. twitterPinLogin()
  786. showNFTGroupIcon()
  787. if (queue_num <= 0) {
  788. return
  789. }
  790. initGroupTip()
  791. setIframeRedPacket()
  792. checkHasSliderDeBtn();
  793. changeQueueNum(-1)
  794. showNFTCard()
  795. addGroupTab();
  796. addJoinedGroupList();
  797. }, 1000)
  798. } else if (inFacebook && inFacebookNode) {
  799. clearInterval(timer)
  800. setInterval(() => {
  801. onChangePageMain(inTwitterNode)
  802. if (queue_num <= 0) {
  803. return
  804. }
  805. setIframeRedPacket('facebook')
  806. changeQueueNum(-1)
  807. }, 1000)
  808. }
  809. }, 1000);
  810. }
  811. let inited = false
  812. // 初始化
  813. export function init() {
  814. if (inited) {
  815. return
  816. }
  817. inited = true
  818. console.log('init')
  819. twitterPinLogin()
  820. getDiscordAuthCode();
  821. appendPopupPage();
  822. chrome.runtime.sendMessage({
  823. actionType: "CONTENT_SET_POPUP_CONFIG",
  824. data: {
  825. popup: 'popup.html'
  826. }
  827. }, () => { });
  828. let where = window.location.host.indexOf('twitter.com') < 0 && window.location.host.indexOf('facebook.com') < 0;
  829. if (where) {
  830. return
  831. }
  832. if (window.location.host.includes('twitter.com')) {
  833. // onPageVisbile();
  834. renderDom();
  835. showNFTCard()
  836. showNFTGroupIcon()
  837. addEventAction();
  838. checkUserJoinGroup();
  839. checkTwitterTaskState();
  840. initBuyNFT();
  841. addJoinedGroupList();
  842. getSysTheme();
  843. addGroupTab();
  844. // 预加载全屏 toobbox
  845. toolBox.initFull()
  846. }
  847. // 渲染dom
  848. initParseCard()
  849. getChromeStorage("popupShowPublishDialog", (res) => {
  850. console.log("popupShowPublishDialog", res);
  851. if (res && res.show) {
  852. setTimeout(() => {
  853. showTwitterPublishDialogHandler({
  854. srcContent: res.srcContent,
  855. postId: res.postId,
  856. copyContent: res.copyContent || ''
  857. });
  858. }, 1500);
  859. chrome.storage.local.remove("popupShowPublishDialog");
  860. }
  861. });
  862. getChromeStorage("userSettings", (res) => {
  863. setTimeout(() => {
  864. addPinedPop();
  865. if (res && !res.isOnToolbar) {
  866. setTimeout(() => {
  867. showPinTips();
  868. chrome.storage.local.remove("userSettings");
  869. }, 800);
  870. }
  871. }, 800);
  872. });
  873. }
  874. function onPageVisbile() {
  875. document.addEventListener('visibilitychange', function () {
  876. let isHidden = document.hidden;
  877. if (!isHidden) {
  878. depositUSShowPopupPage();
  879. }
  880. });
  881. }
  882. const depositUSShowPopupPage = async () => {
  883. let {form = '', path} = await getChromeStorage('achPayData') || {};
  884. if(form == 'popupPage') {
  885. showPopupPage({path});
  886. chrome.storage.local.remove("achPayData");
  887. }
  888. }
  889. function checkHasSliderDeBtn() {
  890. let deBtn = document.getElementById('de-btn');
  891. let deBtn3 = document.getElementById('de-btn3');
  892. if (!deBtn && !deBtn3) {
  893. addSliderNavDeBtn();
  894. }
  895. }
  896. export function facebookReplyTweet(params) {
  897. if (window.location.origin.indexOf('twitter.com')) {
  898. const urlParams = new URLSearchParams(window.location.search);
  899. const actionType = urlParams.get('actionType');
  900. let deReplyParams = urlParams.get('deReplyParams') || '{}';
  901. deReplyParams = JSON.parse(deReplyParams);
  902. if (actionType == 'denetFacebookToTwitterReply') {
  903. if (params.postId == deReplyParams.postId) {
  904. let iframe = document.getElementById(params.postId);
  905. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_FACEBOOK_REPLY', data: deReplyParams }, '*');
  906. }
  907. }
  908. }
  909. }
  910. export function replyHandle(params) {
  911. let iframe = window.parent.document.getElementById(params.postId);
  912. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  913. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  914. if (replyBtn) {
  915. replyBtn.click();
  916. }
  917. onReplyDialogOpen(params, iframe);
  918. // 详情页推文底部评论处理
  919. let pathNameArr = window.location.pathname.split('/');
  920. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  921. let tweetReply = document.querySelector('div[data-testid="tweetButtonInline"]');
  922. if (tweetReply) {
  923. tweetReply.addEventListener('click', function () {
  924. // 详情页回复按钮点击
  925. Report.reportLog({
  926. pageSource: Report.pageSource.mainPage,
  927. businessType: Report.businessType.buttonClick,
  928. objectType: Report.objectType.replyClickByDetailPage
  929. });
  930. let eleList = tweetReply.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('span[data-text="true"]');
  931. reportReplyResult(eleList, params, () => {
  932. // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
  933. chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
  934. });
  935. })
  936. }
  937. }
  938. }
  939. export function onTweetReplyClick(params) {
  940. let iframe = window.parent.document.getElementById(params.postId);
  941. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  942. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  943. if (replyBtn) {
  944. replyBtn.addEventListener('click', () => {
  945. onReplyDialogOpen(params, iframe);
  946. })
  947. }
  948. }
  949. function onReplyDialogOpen(params, iframe) {
  950. setTimeout(() => {
  951. let dialog = document.querySelector('div[role="dialog"]');
  952. let replyBtn;
  953. if (dialog) {
  954. let dialogContent = dialog.querySelector('div[role="dialog"]');
  955. replyBtn = dialog.querySelector('div[data-testid="toolBar"]').querySelector('div[data-testid="tweetButton"]');
  956. if (dialogContent) {
  957. let width = dialogContent.offsetWidth;
  958. let ele = document.createElement('div');
  959. ele.innerText = 'Tag 3 friends to complete the task';
  960. ele.style.cssText = `width: ${width}px; height: 38px; color: #fff; font-weight: 600;
  961. font-size: 16px; display: flex; align-items: center; justify-content: center; background: #1D9BF0;
  962. opacity: 0.8; position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1000`;
  963. dialogContent.style.top = '80px';
  964. dialogContent.parentNode.appendChild(ele);
  965. }
  966. } else {
  967. dialog = document.querySelector('main[role="main"]');
  968. if (dialog) {
  969. replyBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  970. }
  971. }
  972. if (dialog && replyBtn) {
  973. replyBtn.addEventListener('click', function () {
  974. // 推文页回复按钮点击
  975. Report.reportLog({
  976. pageSource: Report.pageSource.mainPage,
  977. businessType: Report.businessType.buttonClick,
  978. objectType: Report.objectType.replyClickByTwitterList
  979. });
  980. let eleList = dialog.querySelector('div[contenteditable="true"]').querySelectorAll('span[data-text="true"]');
  981. reportReplyResult(eleList, params, () => {
  982. // 上報完成
  983. // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
  984. chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
  985. })
  986. });
  987. }
  988. }, 1000);
  989. }
  990. const reportReplyResult = throttle(function (eleList, params, cb) {
  991. //未过滤的回复文本
  992. Report.reportLog({
  993. pageSource: Report.pageSource.mainPage,
  994. businessType: Report.businessType.buttonClick,
  995. objectType: Report.objectType.replyInputTextGet
  996. }, {
  997. replyStr: eleList
  998. });
  999. if (eleList && eleList.length) {
  1000. let atList = [];
  1001. for (let i = 0; i < eleList.length; i++) {
  1002. let item = eleList[i];
  1003. // 是否有中文
  1004. let reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
  1005. if (item && item.innerText.startsWith('@') && !reg.test(item.innerText)) {
  1006. atList.push(item.innerText);
  1007. }
  1008. }
  1009. // 去重过滤文本
  1010. atList = Array.from(new Set(atList));
  1011. Report.reportLog({
  1012. pageSource: Report.pageSource.mainPage,
  1013. businessType: Report.businessType.buttonClick,
  1014. objectType: Report.objectType.replyFilterTextGet
  1015. }, {
  1016. replyStr: atList
  1017. });
  1018. if (atList.length >= 3) {
  1019. //真实上报
  1020. Report.reportLog({
  1021. pageSource: Report.pageSource.mainPage,
  1022. businessType: Report.businessType.buttonClick,
  1023. objectType: Report.objectType.replyReport
  1024. }, {
  1025. replyStr: atList
  1026. });
  1027. fetchAddFinishEvent({
  1028. eventType: params.type,
  1029. luckdropId: params.taskLuckdropId
  1030. }).then(res => {
  1031. if (res.code == 0) {
  1032. cb && cb();
  1033. }
  1034. })
  1035. }
  1036. }
  1037. }, 800);
  1038. // 根据推特id找到dom,完成任务
  1039. export function findTweetByIdDoTask({ tweet_Id = '', follow_names = [] }, task_type = 'like') {
  1040. // 1.根据推特ID寻找推文,获取卡片
  1041. // 获取所有卡片参数
  1042. let card_json_data = parseCard.parseAllDeNetCardParmas()
  1043. let result = card_json_data.filter((item) => { return item.tweet_Id == tweet_Id }) || []
  1044. if (result.length < 1) {
  1045. return
  1046. }
  1047. result = result[0]
  1048. switch (task_type) {
  1049. case 'like':
  1050. // https://twitter.com/intent/retweet?tweet_id=1525900221628223491
  1051. if (result.dom_card) {
  1052. result.dom_card.querySelector('div[data-testid=like]').click()
  1053. result.dom_card.querySelector('iframe').contentWindow.postMessage({ actionType: 'CONTENT_DONE_TASK', task_type, }, '*');
  1054. }
  1055. break;
  1056. case 'retweet':
  1057. if (result.dom_card) {
  1058. result.dom_card.querySelector('div[data-testid=retweet]').click()
  1059. result.dom_card.querySelector('div[data-testid=retweetConfirm]').click()
  1060. }
  1061. break
  1062. case 'follow':
  1063. follow_names.forEach((item) => {
  1064. window.open(`https://twitter.com/intent/follow?screen_name=${item}&tweet_Id=${tweet_Id}`)
  1065. })
  1066. break
  1067. }
  1068. }
  1069. function clickByDataTestId(e, id, callback) {
  1070. if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == id) {
  1071. callback()
  1072. } else if (e.target.closest('div[data-testid=' + id + ']')) {
  1073. callback()
  1074. }
  1075. }
  1076. // 校验关注推特状态
  1077. export function checkTwitterTaskState() {
  1078. let task_type = ''
  1079. let url = window.location.href
  1080. let tweet_Id
  1081. let task_data = {
  1082. follow_name: ''
  1083. }
  1084. // 校验当前链接
  1085. if (url.includes('https://twitter.com/intent/retweet')) {
  1086. task_type = 'retweet'
  1087. } else if (url.includes('https://twitter.com/intent/follow')) {
  1088. task_type = 'follow'
  1089. task_data.follow_name = getQueryString('screen_name')
  1090. } else if (url.includes('https://twitter.com/intent/like')) {
  1091. task_type = 'like'
  1092. } else {
  1093. return
  1094. }
  1095. tweet_Id = getQueryString('tweet_id')
  1096. // let root_status
  1097. document.body.addEventListener('click', (e) => {
  1098. // 点击 确认
  1099. clickByDataTestId(e, 'confirmationSheetConfirm', () => {
  1100. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1101. })
  1102. // 点击取消
  1103. clickByDataTestId(e, 'confirmationSheetCancel', () => {
  1104. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  1105. })
  1106. // 点击 蒙层
  1107. if (e.target && e.target.nextSibling && e.target.nextSibling.dataset && e.target.nextSibling.dataset.testid == 'confirmationSheetDialog') {
  1108. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  1109. }
  1110. }, true)
  1111. let timer = setInterval(() => {
  1112. // 喜欢
  1113. if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
  1114. clearInterval(timer)
  1115. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1116. }
  1117. // 转推
  1118. if (document.querySelector('div[data-testid=unretweet]') && task_type == 'retweet') {
  1119. clearInterval(timer)
  1120. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1121. }
  1122. // 关注
  1123. if (task_type == 'follow') {
  1124. let follow_area = document.querySelector('div[data-testid=placementTracking]')
  1125. if (follow_area && follow_area.querySelectorAll('div')) {
  1126. follow_area = follow_area.querySelectorAll('div')
  1127. clearInterval(timer)
  1128. for (let i in follow_area) {
  1129. if (follow_area[i] && follow_area[i].dataset && follow_area[i].dataset.testid && follow_area[i].dataset.testid.indexOf('unfollow') > 0) {
  1130. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1131. break
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }, 1000)
  1137. }
  1138. export function getTweetAuthorByDom(params) {
  1139. let iframe = document.getElementById(params.postId);
  1140. if (!iframe) {
  1141. return;
  1142. }
  1143. let fullNameDom;
  1144. let pathNameArr = window.location.pathname.split('/');
  1145. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  1146. fullNameDom = iframe.parentNode.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  1147. } else {
  1148. fullNameDom = iframe.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  1149. }
  1150. if (fullNameDom) {
  1151. let arr = fullNameDom.href.split('/');
  1152. if (arr.length) {
  1153. let fullName = arr[arr.length - 1];
  1154. if (fullName) {
  1155. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_GET_TWEET_AUTHOR', data: { fullName } }, '*');
  1156. }
  1157. }
  1158. }
  1159. }
  1160. export function doTaskTwitterAPI({ task_data, task_type }) {
  1161. switch (task_type) {
  1162. case 'like':
  1163. TwitterLikeAPI(task_data.tweet_Id)
  1164. break
  1165. case 'retweet':
  1166. TwitterRetweetAPI(task_data.tweet_Id)
  1167. break
  1168. case 'follow':
  1169. task_data.follow_data.forEach((item) => {
  1170. if (item.name && item.twitterUserId) {
  1171. TwitterFollowAPI(item, task_data.tweet_Id)
  1172. }
  1173. })
  1174. break
  1175. }
  1176. }
  1177. export function showJoinDialog(data) {
  1178. let iframe = document.querySelector('#nftProjectId')
  1179. iframe.style.display = 'block'
  1180. iframe.contentWindow.postMessage({ actionType: 'SHOW_JOIN_DATA', data }, '*');
  1181. iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/group?params=${JSON.stringify(data)}&time=${new Date().getTime()}`)
  1182. }
  1183. const TwitterFollowAPI = (item, tweet_Id) => {
  1184. fetch("https://twitter.com/i/api/1.1/friendships/create.json", {
  1185. "headers": {
  1186. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1187. "content-type": "application/x-www-form-urlencoded",
  1188. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1189. "sec-ch-ua-mobile": "?0",
  1190. "sec-ch-ua-platform": "\"macOS\"",
  1191. "x-csrf-token": getCookie('ct0'),
  1192. "x-twitter-active-user": "yes",
  1193. "x-twitter-auth-type": "OAuth2Session",
  1194. "x-twitter-client-language": "zh-cn"
  1195. },
  1196. "referrer": "https://twitter.com/home",
  1197. "referrerPolicy": "strict-origin-when-cross-origin",
  1198. "body": "include_profile_interstitial_type=1&include_blocking=1&include_blocked_by=1&include_followed_by=1&include_want_retweets=1&include_mute_edge=1&include_can_dm=1&include_can_media_tag=1&include_ext_has_nft_avatar=1&skip_status=1&user_id=" + item.twitterUserId + "",
  1199. "method": "POST",
  1200. "mode": "cors",
  1201. "credentials": "include"
  1202. }).then(() => {
  1203. let task_data = {
  1204. follow_name: item.name
  1205. }
  1206. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: true }, () => { })
  1207. }).catch(() => {
  1208. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: false }, () => { })
  1209. })
  1210. }
  1211. const TwitterRetweetAPI = (tweet_Id) => {
  1212. fetch("https://twitter.com/i/api/graphql/ojPdsZsimiJrUGLR1sjUtA/CreateRetweet", {
  1213. "headers": {
  1214. "accept": "*/*",
  1215. "accept-language": "zh,en;q=0.9,zh-CN;q=0.8",
  1216. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1217. "content-type": "application/json",
  1218. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1219. "sec-ch-ua-mobile": "?0",
  1220. "sec-ch-ua-platform": "\"macOS\"",
  1221. "sec-fetch-dest": "empty",
  1222. "sec-fetch-mode": "cors",
  1223. "sec-fetch-site": "same-origin",
  1224. "x-csrf-token": getCookie('ct0'),
  1225. "x-twitter-active-user": "yes",
  1226. "x-twitter-auth-type": "OAuth2Session",
  1227. "x-twitter-client-language": "zh-cn"
  1228. },
  1229. "referrer": "https://twitter.com/home",
  1230. "referrerPolicy": "strict-origin-when-cross-origin",
  1231. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\",\"dark_request\":false},\"queryId\":\"ojPdsZsimiJrUGLR1sjUtA\"}",
  1232. "method": "POST",
  1233. "mode": "cors",
  1234. "credentials": "include"
  1235. }).then(() => {
  1236. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true }, () => { })
  1237. }).catch(() => {
  1238. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: false }, () => { })
  1239. })
  1240. }
  1241. const TwitterLikeAPI = (tweet_Id) => {
  1242. fetch("https://twitter.com/i/api/graphql/lI07N6Otwv1PhnEgXILM7A/FavoriteTweet", {
  1243. "headers": {
  1244. "accept": "*/*",
  1245. "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
  1246. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1247. "content-type": "application/json",
  1248. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
  1249. "sec-ch-ua-mobile": "?0",
  1250. "sec-ch-ua-platform": "\"Windows\"",
  1251. "sec-fetch-dest": "empty",
  1252. "sec-fetch-mode": "cors",
  1253. "sec-fetch-site": "same-origin",
  1254. "x-csrf-token": getCookie('ct0'),
  1255. "x-twitter-active-user": "yes",
  1256. "x-twitter-auth-type": "OAuth2Session",
  1257. "x-twitter-client-language": "en"
  1258. },
  1259. "referrer": "https://twitter.com/home",
  1260. "referrerPolicy": "strict-origin-when-cross-origin",
  1261. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\"},\"queryId\":\"lI07N6Otwv1PhnEgXILM7A\"}",
  1262. "method": "POST",
  1263. "mode": "cors",
  1264. "credentials": "include"
  1265. }).then(() => {
  1266. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true }, () => { })
  1267. }).catch(() => {
  1268. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false }, () => { })
  1269. })
  1270. }
  1271. export const TwitterApiUserByScreenName = (params) => {
  1272. let { screen_name } = params;
  1273. axios.get(`https://twitter.com/i/api/graphql/mCbpQvZAw6zu_4PvuAUVVQ/UserByScreenName?variables=%7B%22screen_name%22%3A%22${screen_name}%22%2C%22withSafetyModeUserFields%22%3Atrue%2C%22withSuperFollowsUserFields%22%3Atrue%7D`, {
  1274. headers: {
  1275. "accept": "*/*",
  1276. "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
  1277. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1278. "content-type": "application/json",
  1279. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
  1280. "sec-ch-ua-mobile": "?0",
  1281. "sec-ch-ua-platform": "\"Windows\"",
  1282. "sec-fetch-dest": "empty",
  1283. "sec-fetch-mode": "cors",
  1284. "sec-fetch-site": "same-origin",
  1285. "x-csrf-token": getCookie('ct0'),
  1286. "x-twitter-active-user": "yes",
  1287. "x-twitter-auth-type": "OAuth2Session",
  1288. "x-twitter-client-language": "en"
  1289. },
  1290. }).then(function (response) {
  1291. chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: response.data.data || {} }, () => { })
  1292. }).catch(function (response) {
  1293. });
  1294. }
  1295. let click_old_time = new Date().getTime()
  1296. export const showTwitterPost = (data) => {
  1297. let click_new_time = new Date().getTime()
  1298. if ((click_new_time - click_old_time) < 3000) {
  1299. return
  1300. }
  1301. click_old_time = click_new_time
  1302. showEditTweet(() => {
  1303. clearPostContent(() => {
  1304. contentGetNftPostPre({
  1305. groupId: data.groupId
  1306. })
  1307. })
  1308. })
  1309. // addPublishTipsIframe({ type: 'nft' })
  1310. setGroupTabStatus();
  1311. }
  1312. export function publishNFTTweetEvent({ groupId, postId, srcContent }, callback) {
  1313. setTimeout(() => {
  1314. let publishTweetBtn;
  1315. let dialog = document.querySelector('div[role="dialog"]');
  1316. if (dialog) {
  1317. publishTweetBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  1318. } else {
  1319. let domMain = document.querySelector('main[role="main"]');
  1320. publishTweetBtn = domMain && domMain.querySelector('div[data-testid="tweetButton"]');
  1321. }
  1322. publishTweetBtn && publishTweetBtn.addEventListener('click', function () {
  1323. // 获取文案上报
  1324. publishNFTTweetPost({ postId, srcContent, groupId })
  1325. // 绑定推文id
  1326. bindTwitterArt.needBind = true;
  1327. bindTwitterArt.postId = postId;
  1328. callback && callback()
  1329. jumpTwitterDetailByAlert()
  1330. setTimeout(() => {
  1331. setGroupTabSelfStyle({
  1332. groupColor: 'rgb(83, 100, 113)',
  1333. groupFontWeight: '500',
  1334. lineDisplay: 'none'
  1335. });
  1336. sendMessageToGroupBanner({ type: 'arrow' })
  1337. }, 2000);
  1338. });
  1339. }, 800)
  1340. }
  1341. const sendMessageToGroupBanner = (params) => {
  1342. chrome.runtime.sendMessage({
  1343. actionType: "SWITCH_GROUP_BANNER_STATUS",
  1344. data: params
  1345. }, (res) => {
  1346. if (!res) {
  1347. Report.reportLog({
  1348. objectType: Report.objectType.chrome_extension_sendmessage_error
  1349. })
  1350. }
  1351. });
  1352. }
  1353. export const publishNFTTweetPost = ({ postId, srcContent, groupId }) => {
  1354. let inputEle = document.querySelector('div[contenteditable="true"]');
  1355. let textContent = inputEle.innerText
  1356. srcContent = srcContent.replaceAll('#DNFT', '')
  1357. srcContent = srcContent.replaceAll('⬇️', '')
  1358. srcContent = srcContent.replaceAll('Join', '')
  1359. srcContent = srcContent.replaceAll('Now:', '')
  1360. let arr = srcContent.split(' ') || []
  1361. arr.forEach((item) => {
  1362. if (textContent.includes(item)) {
  1363. textContent = textContent.replaceAll(item, '')
  1364. }
  1365. })
  1366. textContent = textContent.replaceAll('#DNFT', '')
  1367. textContent = textContent.replaceAll('⬇️', '')
  1368. textContent = textContent.replaceAll('Join', '')
  1369. textContent = textContent.replaceAll('Now:', '')
  1370. textContent = textContent.trim()
  1371. let formData = {
  1372. groupId,
  1373. textContent
  1374. }
  1375. let params = {
  1376. postBizData: JSON.stringify(formData),
  1377. postSrc: 1, //1 twitter
  1378. postType: 2, //2 nft
  1379. postId
  1380. }
  1381. chrome.runtime.sendMessage({
  1382. actionType: "CONTENT_NFT_TXT_PUBLISH",
  1383. data: params
  1384. }, () => { });
  1385. }
  1386. const contentGetNftPostPre = (data) => {
  1387. chrome.runtime.sendMessage({
  1388. actionType: "CONTENT_GET_TWITTER_NFT_POST_PRE",
  1389. data
  1390. }, () => { });
  1391. }
  1392. let tweet_nft_content = {}
  1393. export const setTwitterTextarea = (params, num = 5) => {
  1394. if (num <= 0) {
  1395. return
  1396. }
  1397. tweet_nft_content = params
  1398. let inputEle = document.querySelector('div[contenteditable="true"]');
  1399. if (inputEle) {
  1400. inputEle.focus();
  1401. setGroupIconStatus();
  1402. document.execCommand("insertText", false, '');
  1403. setTimeout(() => {
  1404. document.execCommand("insertText", false, params.srcContent + ' ');
  1405. // 光标定位到起始位置
  1406. setTimeout(() => {
  1407. inputEle.focus();
  1408. let sel = window.getSelection()
  1409. let range = document.createRange()
  1410. range.setStart(inputEle, 0)
  1411. range.setEnd(inputEle, 0)
  1412. sel.removeAllRanges()
  1413. sel.addRange(range);
  1414. }, 0)
  1415. publishNFTTweetEvent(params, bindTwitterArtMethod)
  1416. }, 1000)
  1417. } else {
  1418. setTimeout(() => {
  1419. num--
  1420. setTwitterTextarea(params, num)
  1421. }, 500);
  1422. }
  1423. }
  1424. const initGroupTip = () => {
  1425. let arr = window.location.pathname.split('/') || []
  1426. if (location.pathname == '/compose/tweet') {
  1427. return
  1428. }
  1429. if (!document.querySelector('div[data-testid=UserName]')) {
  1430. return
  1431. }
  1432. if (arr.length >= 2) {
  1433. let twitterAccount = arr[1]
  1434. let iframe_banner = document.querySelector('#denet_group_banner')
  1435. if (iframe_banner) {
  1436. if (twitterAccount != getQueryStringByUrl(iframe_banner.src, 'twitterAccount')) {
  1437. iframe_banner.style.display = 'none'
  1438. // iframe_banner.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
  1439. iframe_banner.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
  1440. }
  1441. return
  1442. }
  1443. try {
  1444. let dom = document.querySelector('div[data-testid="ScrollSnap-SwipeableList"]').closest('nav')
  1445. let iframe = document.createElement('iframe')
  1446. iframe.id = 'denet_group_banner'
  1447. iframe.style.cssText = 'border: medium none; display:none; width:100%; height:100px;'
  1448. iframe.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
  1449. // iframe.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
  1450. if (dom && !dom.parentNode.children[0].querySelector('iframe')) {
  1451. // dom.parentNode.insertBefore(iframe, dom)
  1452. dom.parentNode.children[0].appendChild(iframe)
  1453. }
  1454. } catch (error) {
  1455. }
  1456. }
  1457. }
  1458. export const showGroupTip = () => {
  1459. let dom_denet_group_banner = document.querySelector('#denet_group_banner')
  1460. dom_denet_group_banner.style.display = 'block';
  1461. groupBtnStyleChange();
  1462. }
  1463. export const hideBuyNFT = () => {
  1464. let iframe = document.querySelector('#nftProjectId')
  1465. iframe.style.display = 'none'
  1466. iframe.src = ''
  1467. }
  1468. export const showBuyNFT = ({ nft_project_Id }) => {
  1469. if (!nft_project_Id) {
  1470. return
  1471. }
  1472. let iframe = document.querySelector('#nftProjectId')
  1473. iframe.style.display = 'block'
  1474. iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/?nftProjectId=${nft_project_Id}`)
  1475. }
  1476. const initBuyNFT = () => {
  1477. let url = ''
  1478. let id = `nftProjectId`
  1479. createNFTIframe({ url, id })
  1480. }
  1481. export const showNFTCard = () => {
  1482. let urlInfo = new URL(window.location.href)
  1483. let isTwitter = urlInfo.hostname === 'twitter.com'
  1484. let userElem = document.querySelector('div[data-testid="UserName"]');
  1485. let sideElem = document.querySelector('div[data-testid="sidebarColumn"]')
  1486. let tabIndex = sideElem && sideElem.querySelector('div[tabindex="0"]');
  1487. let isAppend = document.querySelector('div[id="de-nft-node"]');
  1488. let where = isTwitter && userElem && tabIndex;
  1489. if (where) {
  1490. let iframe = document.createElement('iframe');
  1491. iframe.src = chrome.runtime.getURL(`/iframe/nft-card.html`)
  1492. iframe.style.cssText = 'border:medium none; width:100%; height:290px;';
  1493. let nftElement = document.createElement('div');
  1494. nftElement.id = 'de-nft-node';
  1495. nftElement.innerHTML = `
  1496. ${iframe.outerHTML}
  1497. <style>
  1498. #de-nft-node {height:290px; margin-bottom:17px; display:none;}
  1499. </style>
  1500. `;
  1501. if (tabIndex && tabIndex.firstChild && tabIndex.firstChild.childNodes && !isAppend) {
  1502. tabIndex.firstChild.insertBefore(nftElement, tabIndex.firstChild.childNodes[2]);
  1503. }
  1504. }
  1505. }
  1506. export const showNFTSale = () => {
  1507. document.querySelector('div[id="de-nft-node"]').style.display = 'block';
  1508. }
  1509. export const addEventAction = () => {
  1510. let urlInfo = new URL(window.location.href)
  1511. let isTwitter = urlInfo.hostname === 'twitter.com'
  1512. // 页面滚动
  1513. if (isTwitter) {
  1514. // 首页
  1515. if (urlInfo.pathname === '/home') {
  1516. window.addEventListener('scroll', () => {
  1517. hideNFTGroupList()
  1518. })
  1519. }
  1520. }
  1521. }
  1522. export const appendPopupPage = (params = {}) => {
  1523. let { path = '' } = params;
  1524. let iframe = document.createElement('iframe');
  1525. iframe.id = 'de-popup-page';
  1526. iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
  1527. iframe.style.cssText = `border: medium none; width: 375px !important;
  1528. height: 650px;position: fixed; right: 16px; top: 16px;background: #FFFFFF;border: 0.5px solid #919191;box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.2);box-sizing: border-box;z-index: 90000;
  1529. animation-duration: 0.5s !important;
  1530. animation-timing-function: ease-in-out !important;
  1531. animation-fill-mode: forwards !important;
  1532. transition: all 1s ease 0s !important;right: -385px;transform: translateX(385px);`
  1533. let iframeContent = document.getElementById('de-popup-page');
  1534. let overlayDom = document.createElement('div');
  1535. overlayDom.id = 'de-popup-overlay';
  1536. overlayDom.style.cssText = `position: fixed;z-index: 88888;top: 0;
  1537. left: 0;width: 100%;height: 100%;opacity: 0;display: none`;
  1538. let overlay = document.getElementById('de-popup-overlay');
  1539. let body = document.querySelector('body');
  1540. if (!iframeContent && body) {
  1541. document.querySelector('body').appendChild(iframe);
  1542. if (!overlay) {
  1543. document.querySelector('body').appendChild(overlayDom);
  1544. overlayDom.addEventListener('click', function () {
  1545. hidePopupPage();
  1546. })
  1547. } else {
  1548. overlay.addEventListener('click', function () {
  1549. hidePopupPage();
  1550. })
  1551. }
  1552. }
  1553. }
  1554. let showPopupPageFrom = '';
  1555. export const showPopupPage = (params = {}) => {
  1556. let { path = '', from, showJoinGroupFinish = false } = params;
  1557. showPopupPageFrom = from;
  1558. hidePinTips();
  1559. hideNoticeBindTweet();
  1560. let iframe = document.getElementById('de-popup-page');
  1561. if (!iframe) {
  1562. appendPopupPage();
  1563. iframe = document.getElementById('de-popup-page');
  1564. }
  1565. if (iframe) {
  1566. if (path) {
  1567. iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
  1568. }
  1569. iframe.style.transform = 'translateX(-' + 395 + 'px)';
  1570. chrome.runtime.sendMessage({
  1571. actionType: "CONTENT_POPUP_PAGE_SHOW",
  1572. data: {
  1573. path,
  1574. showJoinGroupFinish,
  1575. }
  1576. }, () => { });
  1577. chrome.runtime.sendMessage({
  1578. actionType: "CONTENT_SET_POPUP_CONFIG",
  1579. data: {
  1580. popup: ''
  1581. }
  1582. }, () => { });
  1583. let overlay = document.getElementById('de-popup-overlay');
  1584. overlay.style.display = 'block';
  1585. let htmlDom = document.querySelector('html');
  1586. if (htmlDom) {
  1587. htmlDom.style.overflowY = 'hidden';
  1588. }
  1589. }
  1590. }
  1591. export const hidePopupPage = () => {
  1592. let iframe = document.getElementById('de-popup-page');
  1593. if (iframe) {
  1594. iframe.style.transform = 'translateX(' + 385 + 'px)';
  1595. let overlay = document.getElementById('de-popup-overlay');
  1596. overlay.style.display = 'none';
  1597. let htmlDom = document.querySelector('html');
  1598. if (htmlDom) {
  1599. htmlDom.style.overflowY = 'auto';
  1600. }
  1601. chrome.runtime.sendMessage({
  1602. actionType: "CONTENT_SET_POPUP_CONFIG",
  1603. data: {
  1604. popup: 'popup.html'
  1605. }
  1606. }, () => { });
  1607. if (showPopupPageFrom == 'BUY_NFT_FINISH') {
  1608. chrome.runtime.sendMessage({
  1609. actionType: "CONTENT_GET_PINED",
  1610. data: {}
  1611. }, () => { });
  1612. showPopupPageFrom = '';
  1613. }
  1614. }
  1615. }
  1616. export const tiggerInjectPopupPage = () => {
  1617. let iframeContent = document.getElementById('de-popup-page');
  1618. if (iframeContent) {
  1619. hidePinTips();
  1620. hideNoticeBindTweet();
  1621. let { transform = '' } = iframeContent.style;
  1622. if (transform == 'translateX(385px)' || !transform) {
  1623. showPopupPage();
  1624. } else {
  1625. hidePopupPage();
  1626. }
  1627. } else {
  1628. appendPopupPage();
  1629. setTimeout(() => {
  1630. let iframe = document.getElementById('de-popup-page');
  1631. let { transform = '' } = iframe.style;
  1632. if (transform == 'translateX(385px)' || !transform) {
  1633. showPopupPage();
  1634. } else {
  1635. hidePopupPage();
  1636. }
  1637. }, 300)
  1638. }
  1639. }
  1640. export const setPopupConfByPopupPage = () => {
  1641. let iframe = document.getElementById('de-popup-page');
  1642. if (iframe) {
  1643. let { transform = '' } = iframe.style;
  1644. if (transform && transform == 'translateX(-395px)') {
  1645. chrome.runtime.sendMessage({
  1646. actionType: "CONTENT_SET_POPUP_CONFIG",
  1647. data: {
  1648. popup: ''
  1649. }
  1650. }, () => { });
  1651. } else {
  1652. chrome.runtime.sendMessage({
  1653. actionType: "CONTENT_SET_POPUP_CONFIG",
  1654. data: {
  1655. popup: 'popup.html'
  1656. }
  1657. }, () => { });
  1658. }
  1659. } else {
  1660. chrome.runtime.sendMessage({
  1661. actionType: "CONTENT_SET_POPUP_CONFIG",
  1662. data: {
  1663. popup: 'popup.html'
  1664. }
  1665. }, () => { });
  1666. }
  1667. }
  1668. /**
  1669. *
  1670. * Group Tab List Start
  1671. */
  1672. /**
  1673. *
  1674. * 创建 Group Tab
  1675. */
  1676. const createGroupTabNode = () => {
  1677. let groupIcon = document.createElement('img');
  1678. groupIcon.id = 'de-group-tab-icon'
  1679. groupIcon.src = require("@/assets/img/icon-group-tab-item.png");
  1680. groupIcon.style.cssText = 'width:20px;height: 20px;margin-right:4px;';
  1681. let divNode = document.createElement('div');
  1682. divNode.style.cssText = 'display: flex; align-items: center;height: 100%';
  1683. divNode.appendChild(groupIcon);
  1684. divNode.appendChild(document.createTextNode('Group'));
  1685. let lineDom = document.createElement('div');
  1686. lineDom.id = 'de-tab-line';
  1687. lineDom.style.cssText = `border-radius: 9999px;
  1688. position: absolute;
  1689. bottom: 0px;
  1690. min-width: 56px;
  1691. align-self: center;
  1692. height: 4px;
  1693. background-color: rgb(29, 155, 240);
  1694. display: none`;
  1695. let groupTab = document.createElement('div');
  1696. groupTab.id = 'de-nav-tab-group';
  1697. groupTab.style.cssText = `z-index: 1;
  1698. position: relative;
  1699. display: flex;
  1700. min-width: 56px;
  1701. -webkit-box-pack: center;
  1702. justify-content: center;
  1703. -webkit-box-align: center;
  1704. align-items: center;
  1705. text-align: center;
  1706. padding: 0px 16px;
  1707. color: rgb(83, 100, 113);
  1708. font-weight: 700;
  1709. height: 53px;
  1710. cursor: pointer;
  1711. font: 500 15px / 20px TwitterChirp, -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;`;
  1712. groupTab.appendChild(divNode);
  1713. groupTab.appendChild(lineDom);
  1714. return groupTab;
  1715. }
  1716. const groupBtnStyleChange = () => {
  1717. let tab = getGroupTabNode();
  1718. if (tab) {
  1719. let line = tab.querySelector('#de-tab-line');
  1720. if (line) {
  1721. let { display } = line.style;
  1722. if (display != 'none') {
  1723. sendMessageToGroupBanner({ type: 'btn' })
  1724. }
  1725. }
  1726. }
  1727. }
  1728. const getGroupTabNode = () => {
  1729. let tab = document.querySelector('#de-nav-tab-group');
  1730. return tab;
  1731. }
  1732. const addGroupTab = () => {
  1733. if (!document.querySelector('div[data-testid=UserName]')) {
  1734. return
  1735. }
  1736. let tabListDom = document.querySelector('div[role="tablist"]');
  1737. let groupItemTab = getGroupTabNode();
  1738. if (tabListDom && !groupItemTab) {
  1739. let groupTab = createGroupTabNode();
  1740. tabListDom.appendChild(groupTab);
  1741. groupTab.addEventListener('mouseenter', function () {
  1742. groupTab.style.background = 'rgba(15, 20, 25, 0.1)'
  1743. });
  1744. groupTab.addEventListener('mouseleave', function () {
  1745. groupTab.style.background = 'none'
  1746. });
  1747. setTimeout(() => {
  1748. let count = 0;
  1749. hiddenMaskWeb3Tab(count);
  1750. }, 1300)
  1751. addGroupTabEventListener();
  1752. }
  1753. removeTweetTabEvent({
  1754. tabListDom
  1755. });
  1756. addTweetTabEventListener({
  1757. tabListDom
  1758. });
  1759. addTabGroupContent(() => {
  1760. checkNeedSelectGroupTab();
  1761. });
  1762. }
  1763. const hiddenMaskWeb3Tab = (count) => {
  1764. setTimeout(() => {
  1765. count++;
  1766. if (count < 6) {
  1767. let tab = getMaskWeb3Tab();
  1768. if (tab) {
  1769. tab.style.display = 'none'
  1770. } else {
  1771. hiddenMaskWeb3Tab(count);
  1772. }
  1773. }
  1774. }, 1000);
  1775. }
  1776. /**
  1777. * 跳转到个人主页 检查是否需要选中 Group tab
  1778. */
  1779. const checkNeedSelectGroupTab = () => {
  1780. if (window.location.pathname != '/home') {
  1781. setTimeout(() => {
  1782. getChromeStorage('groupTabData', (res) => {
  1783. console.log('groupTabData', res);
  1784. if (res && res.deTabVal == 'deGroupTab') {
  1785. chrome.storage.local.remove("groupTabData");
  1786. setTimeout(() => {
  1787. selectGroupTab();
  1788. }, 300)
  1789. }
  1790. })
  1791. }, 1300)
  1792. }
  1793. }
  1794. /** 选中 Group tab */
  1795. export const selectGroupTab = () => {
  1796. let groupTab = getGroupTabNode();
  1797. if (groupTab) {
  1798. groupTab.click();
  1799. }
  1800. };
  1801. export const groupTipsSelectGroupTab = (params = {}) => {
  1802. if (params.type == 'btn') {
  1803. let groupTab = getGroupTabNode();
  1804. if (groupTab) {
  1805. let line = groupTab.querySelector('#de-tab-line');
  1806. if (line) {
  1807. let { display } = line.style;
  1808. if (display == 'none') {
  1809. groupTab.click();
  1810. }
  1811. }
  1812. }
  1813. } else {
  1814. selectGroupTab();
  1815. }
  1816. }
  1817. /**
  1818. *
  1819. * Group tab点击事件监听
  1820. */
  1821. const addGroupTabEventListener = () => {
  1822. let groupTab = getGroupTabNode();
  1823. groupTab.addEventListener('click', function () {
  1824. let bgColor = document.querySelector('body').style.backgroundColor;
  1825. let groupColor = systemInfo.theme == 'dark' && bgColor == 'rgb(0, 0, 0)' ? '#fff' : 'rgb(15, 20, 25)';
  1826. // let groupColor = systemInfo.theme == 'light' ? 'rgb(15, 20, 25)' : '#fff';
  1827. setGroupTabSelfStyle({
  1828. groupColor: groupColor,
  1829. groupFontWeight: '700',
  1830. lineDisplay: 'block'
  1831. });
  1832. setTweetActiveTabStyle({
  1833. color: 'rgb(83, 100, 113)',
  1834. display: 'none'
  1835. });
  1836. setTabContentStyle({
  1837. tweetTabContentDisply: 'none',
  1838. iframeContentDisplay: 'block'
  1839. });
  1840. refreshTabGroup();
  1841. window.addEventListener('scroll', addPageScrollEvent);
  1842. let tipsDom = document.querySelector('#denet_group_banner');
  1843. if (tipsDom) {
  1844. sendMessageToGroupBanner({ type: 'btn' })
  1845. } else {
  1846. onShowGroupBanner();
  1847. }
  1848. })
  1849. }
  1850. const onShowGroupBanner = () => {
  1851. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  1852. switch (req.actionType) {
  1853. case 'IFRAME_SHOW_GROUP_TIP':
  1854. sendMessageToGroupBanner({ type: 'btn' })
  1855. if (!getGroupTabNode()) {
  1856. addGroupTab();
  1857. }
  1858. break
  1859. }
  1860. })
  1861. }
  1862. const addPageScrollEvent = () => {
  1863. let wrapperDom = document.querySelector('html');
  1864. let contentDom = document.querySelector('main[role="main"]');
  1865. let data = {
  1866. wrapperHeight: wrapperDom.offsetHeight,
  1867. wrapperScrollTop: wrapperDom.scrollTop,
  1868. contentHeight: contentDom.offsetHeight
  1869. }
  1870. chrome.runtime.sendMessage({
  1871. actionType: "CONTENT_GROUP_LIST_SCROLL",
  1872. data: data
  1873. }, () => { });
  1874. };
  1875. const removeTweetTabEvent = (params) => {
  1876. let { tabListDom } = params;
  1877. if (tabListDom) {
  1878. let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
  1879. if (tweetTabItem.length) {
  1880. for (let i = 0; i < tweetTabItem.length; i++) {
  1881. let item = tweetTabItem[i];
  1882. item.removeEventListener('click', TweetTabEventHandler)
  1883. }
  1884. }
  1885. }
  1886. }
  1887. /**
  1888. *
  1889. * twitter tab点击事件监听
  1890. */
  1891. const addTweetTabEventListener = (params) => {
  1892. let { tabListDom } = params;
  1893. let groupItemTab = getGroupTabNode();
  1894. if (tabListDom && groupItemTab) {
  1895. // 监听twitter tab点击事件
  1896. let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
  1897. if (tweetTabItem.length) {
  1898. for (let i = 0; i < tweetTabItem.length; i++) {
  1899. let item = tweetTabItem[i];
  1900. item.addEventListener('click', TweetTabEventHandler)
  1901. }
  1902. }
  1903. }
  1904. }
  1905. const TweetTabEventHandler = () => {
  1906. window.removeEventListener('scroll', addPageScrollEvent);
  1907. setGroupTabSelfStyle({
  1908. groupColor: 'rgb(83, 100, 113)',
  1909. groupFontWeight: '500',
  1910. lineDisplay: 'none'
  1911. });
  1912. setTabContentStyle({
  1913. tweetTabContentDisply: 'block',
  1914. iframeContentDisplay: 'none'
  1915. });
  1916. setTweetActiveTabStyle({
  1917. color: 'rgb(15, 20, 25)',
  1918. display: 'block'
  1919. });
  1920. sendMessageToGroupBanner({ type: 'arrow' })
  1921. };
  1922. /**
  1923. * 设置 Group Tab 样式
  1924. * */
  1925. const setGroupTabSelfStyle = (params = {}) => {
  1926. let { groupColor, groupFontWeight, lineDisplay } = params;
  1927. let groupTab = getGroupTabNode();
  1928. if (groupTab) {
  1929. groupTab.style.color = groupColor;
  1930. groupTab.style.fontWeight = groupFontWeight;
  1931. let lineDom = groupTab.querySelector('#de-tab-line');
  1932. if (lineDom) {
  1933. lineDom.style.display = lineDisplay;
  1934. }
  1935. }
  1936. };
  1937. /**
  1938. * 切换到 Group tab时 刷新列表
  1939. */
  1940. export const refreshTabGroup = () => {
  1941. chrome.runtime.sendMessage({
  1942. actionType: "CONTENT_REFRESH_TAB_GROUP_LIST",
  1943. data: {}
  1944. }, () => { });
  1945. }
  1946. /**
  1947. *
  1948. * tab选中时设置 激活 的字体样式和选中条
  1949. */
  1950. const setTweetActiveTabStyle = (params) => {
  1951. let { color, display } = params || {};
  1952. let tab = document.querySelector('a[aria-selected="true"]');
  1953. if (tab) {
  1954. let tweetActiveTab = tab.querySelector('div');
  1955. if (tweetActiveTab) {
  1956. tweetActiveTab.style.color = color;
  1957. let tweetTabLine = tweetActiveTab.querySelector('div');
  1958. if (tweetTabLine) {
  1959. tweetTabLine.style.display = display;
  1960. }
  1961. }
  1962. }
  1963. }
  1964. /**
  1965. *
  1966. * 设置 tab 切换时 tab内容的样式(显示隐藏)
  1967. */
  1968. const setTabContentStyle = (params) => {
  1969. let { tweetTabContentDisply, iframeContentDisplay } = params;
  1970. let tweetTabContent = getTweetTabContent();
  1971. if (tweetTabContent) {
  1972. if (tweetTabContentDisply == 'block') {
  1973. let { visibility } = tweetTabContent.style;
  1974. if (visibility == 'hidden') {
  1975. tweetTabContent.style.visibility = 'visible';
  1976. tweetTabContent.style.height = 'auto';
  1977. tweetTabContent.style.overflow = 'auto';
  1978. }
  1979. } else {
  1980. tweetTabContent.style.visibility = 'hidden';
  1981. tweetTabContent.style.height = '0px';
  1982. tweetTabContent.style.overflow = 'hidden';
  1983. tweetTabContent.style.margin = '0';
  1984. }
  1985. }
  1986. let iframeContent = getGroupTabContentNode();
  1987. if (!iframeContent) {
  1988. addTabGroupContent();
  1989. }
  1990. setTimeout(() => {
  1991. iframeContent = getGroupTabContentNode();
  1992. if (iframeContent) {
  1993. iframeContent.style.display = iframeContentDisplay;
  1994. }
  1995. })
  1996. };
  1997. /**
  1998. *
  1999. * 获取 twitter tab 下的内容
  2000. */
  2001. const getTweetTabContent = () => {
  2002. let tweetTabContent = document.querySelector('[data-testid="primaryColumn"] [role="navigation"] + * > div[aria-label]:not([role="progressbar"])') || document.querySelector('div[data-testid="emptyState"]');
  2003. return tweetTabContent;
  2004. }
  2005. /**
  2006. * 注入 Group List 内容
  2007. */
  2008. const addTabGroupContent = (cb) => {
  2009. let params = {
  2010. windowLocation: window.location
  2011. }
  2012. let iframe = document.createElement('iframe');
  2013. iframe.id = 'de-tab-group-content';
  2014. iframe.src = chrome.runtime.getURL('/iframe/tab-group.html') + `?params=${JSON.stringify(params)}`;
  2015. iframe.style.cssText = `border: medium none; height: 500px;display: none`
  2016. let iframeContent = getGroupTabContentNode();
  2017. let tweetTabContent = getTweetTabContent();
  2018. if (!iframeContent) {
  2019. if (tweetTabContent && tweetTabContent.parentElement) {
  2020. tweetTabContent.parentElement.appendChild(iframe);
  2021. cb && cb();
  2022. }
  2023. }
  2024. };
  2025. const getGroupTabContentNode = () => {
  2026. let content = document.getElementById('de-tab-group-content');
  2027. return content;
  2028. }
  2029. const setGroupTabStatus = () => {
  2030. let groupTab = getGroupTabNode();
  2031. if (groupTab) {
  2032. let line = groupTab.querySelector('#de-tab-line');
  2033. if (line) {
  2034. let { display } = line.style;
  2035. if (display != 'none') {
  2036. groupTab.click();
  2037. }
  2038. }
  2039. } else {
  2040. setTimeout(() => {
  2041. addGroupTab();
  2042. }, 2000)
  2043. }
  2044. clearInterval(fixProfileTabAutoTimer);
  2045. fixProfileTabAutoSwitch();
  2046. };
  2047. const fixProfileTabAutoSwitch = () => {
  2048. fixProfileTabAutoTimer = setInterval(() => {
  2049. let groupTab = getGroupTabNode();
  2050. let tweetTab = document.querySelector('a[aria-selected="true"]');
  2051. if (groupTab) {
  2052. let line = groupTab.querySelector('#de-tab-line');
  2053. if (line) {
  2054. let { display } = line.style;
  2055. if (display != 'none' && tweetTab) {
  2056. let groupContent = getGroupTabContentNode();
  2057. if (groupContent) {
  2058. let tweetTabContent = getTweetTabContent();
  2059. let { visibility } = tweetTabContent.style;
  2060. let { display } = groupContent.style;
  2061. if (display == 'block' && visibility != 'hidden') {
  2062. groupTab.click();
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }, 1000)
  2069. }
  2070. /**
  2071. *
  2072. * 设置Tab Group Iframe 样式
  2073. */
  2074. export const setTabGroupIframeStyle = (params, isReSize = false) => {
  2075. if (!isReSize) {
  2076. getSysTheme();
  2077. }
  2078. let iframeContent = getGroupTabContentNode();
  2079. if (iframeContent) {
  2080. let htmlHeight = document.querySelector('html').offsetHeight;
  2081. let primaryColumnHeightn = document.querySelector('div[data-testid="primaryColumn"]').offsetHeight;
  2082. let height = primaryColumnHeightn > htmlHeight ? primaryColumnHeightn : htmlHeight;
  2083. iframeContent.style.height = height + 'px';
  2084. }
  2085. }
  2086. /**
  2087. * mask web3 Tab
  2088. *
  2089. */
  2090. const getMaskWeb3Tab = () => {
  2091. let tab = document.querySelector('div[data-testid="ScrollSnap-nextButtonWrapper"] + span');
  2092. return tab;
  2093. }
  2094. export const pageJumpHandler = (params) => {
  2095. let { url } = params
  2096. if (url) {
  2097. window.open(url)
  2098. }
  2099. }
  2100. export const getTweetProfileNavTop = (params) => {
  2101. let top = document.querySelector('div[role="tablist"]').closest('nav').getBoundingClientRect().top;
  2102. chrome.runtime.sendMessage({
  2103. actionType: "CONTENT_SEND_GROUP_NAV_TOP", data: {
  2104. top,
  2105. scrollTop: params.scrollTop
  2106. }
  2107. }, () => { })
  2108. }
  2109. export const setGroupInfo = (params = {}) => {
  2110. tweetAccountBindGroupInfo.groupInfo = params;
  2111. let groupTab = getGroupTabNode();
  2112. if (!params.nftGroupId) {
  2113. let { pathname = '' } = window.location;
  2114. if (pathname == "/compose/tweet") {
  2115. return;
  2116. };
  2117. if (groupTab) {
  2118. groupTab.style.display = 'none';
  2119. } else {
  2120. setTimeout(() => {
  2121. groupTab = getGroupTabNode();
  2122. if (groupTab) {
  2123. groupTab.style.display = 'none';
  2124. }
  2125. }, 800)
  2126. }
  2127. } else {
  2128. if (groupTab) {
  2129. let { display } = groupTab.style;
  2130. if (display == 'none') {
  2131. groupTab.style.display = 'block';
  2132. }
  2133. }
  2134. }
  2135. }
  2136. const getSysTheme = () => {
  2137. const themeMedia = window.matchMedia("(prefers-color-scheme: light)");
  2138. if (themeMedia.matches) {
  2139. systemInfo.theme = 'light'
  2140. } else {
  2141. systemInfo.theme = 'dark'
  2142. }
  2143. sysThemeChange();
  2144. themeMedia.addListener(e => {
  2145. addGroupTab()
  2146. if (e.matches) {
  2147. systemInfo.theme = 'light'
  2148. } else {
  2149. systemInfo.theme = 'dark'
  2150. }
  2151. sysThemeChange();
  2152. });
  2153. }
  2154. const sysThemeChange = () => {
  2155. setTimeout(() => {
  2156. let bgColor = document.querySelector('body').style.backgroundColor;
  2157. chrome.runtime.sendMessage({
  2158. actionType: "CONTENT_SYS_THEME_CHANGE", data: {
  2159. theme: systemInfo.theme,
  2160. twitterTheme: bgColor == 'rgb(0, 0, 0)' ? 'dark' : 'light'
  2161. }
  2162. }, () => { })
  2163. }, 800)
  2164. }
  2165. /**
  2166. *
  2167. * Group Tab List End
  2168. *
  2169. */
  2170. export const loginSuccessHandle = () => {
  2171. // 检查是否漏出group图标
  2172. checkUserJoinGroup(() => {
  2173. showNFTGroupIcon()
  2174. addEventAction()
  2175. addJoinedGroupList();
  2176. })
  2177. }
  2178. export const showPublishDialog = () => {
  2179. let smallBtn = document.getElementById('de-btn1');
  2180. if (smallBtn) {
  2181. smallBtn.click();
  2182. }
  2183. }