twitter.js 80 KB

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