twitter.js 86 KB

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