twitter.js 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  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. initGroupTip()
  792. setIframeRedPacket()
  793. checkHasDeBtn()
  794. checkHasSliderDeBtn();
  795. changeQueueNum(-1)
  796. showNFTCard()
  797. addGroupTab();
  798. addJoinedGroupList();
  799. }, 1000)
  800. } else if (inFacebook && inFacebookNode) {
  801. clearInterval(timer)
  802. setInterval(() => {
  803. onChangePageMain(inTwitterNode)
  804. if (queue_num <= 0) {
  805. return
  806. }
  807. setIframeRedPacket('facebook')
  808. changeQueueNum(-1)
  809. }, 1000)
  810. }
  811. }, 1000);
  812. }
  813. let inited = false
  814. // 初始化
  815. export function init() {
  816. if (inited) {
  817. return
  818. }
  819. inited = true
  820. console.log('init')
  821. twitterPinLogin()
  822. getDiscordAuthCode();
  823. appendPopupPage();
  824. chrome.runtime.sendMessage({
  825. actionType: "CONTENT_SET_POPUP_CONFIG",
  826. data: {
  827. popup: 'popup.html'
  828. }
  829. }, () => { });
  830. let where = window.location.host.indexOf('twitter.com') < 0 && window.location.host.indexOf('facebook.com') < 0;
  831. if (where) {
  832. return
  833. }
  834. if (window.location.host.includes('twitter.com')) {
  835. onPageVisbile();
  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 onPageVisbile() {
  877. document.addEventListener('visibilitychange', function () {
  878. let isHidden = document.hidden;
  879. if (!isHidden) {
  880. depositUSShowPopupPage();
  881. }
  882. });
  883. }
  884. const depositUSShowPopupPage = async () => {
  885. let {form = ''} = await getChromeStorage('achPayData') || {};
  886. if(form == 'popupPage') {
  887. showPopupPage();
  888. chrome.storage.local.remove("achPayData");
  889. }
  890. }
  891. function checkHasSliderDeBtn() {
  892. let deBtn = document.getElementById('de-btn');
  893. let deBtn3 = document.getElementById('de-btn3');
  894. if (!deBtn && !deBtn3) {
  895. addSliderNavDeBtn();
  896. }
  897. }
  898. export function facebookReplyTweet(params) {
  899. if (window.location.origin.indexOf('twitter.com')) {
  900. const urlParams = new URLSearchParams(window.location.search);
  901. const actionType = urlParams.get('actionType');
  902. let deReplyParams = urlParams.get('deReplyParams') || '{}';
  903. deReplyParams = JSON.parse(deReplyParams);
  904. if (actionType == 'denetFacebookToTwitterReply') {
  905. if (params.postId == deReplyParams.postId) {
  906. let iframe = document.getElementById(params.postId);
  907. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_FACEBOOK_REPLY', data: deReplyParams }, '*');
  908. }
  909. }
  910. }
  911. }
  912. export function replyHandle(params) {
  913. let iframe = window.parent.document.getElementById(params.postId);
  914. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  915. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  916. if (replyBtn) {
  917. replyBtn.click();
  918. }
  919. onReplyDialogOpen(params, iframe);
  920. // 详情页推文底部评论处理
  921. let pathNameArr = window.location.pathname.split('/');
  922. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  923. let tweetReply = document.querySelector('div[data-testid="tweetButtonInline"]');
  924. if (tweetReply) {
  925. tweetReply.addEventListener('click', function () {
  926. // 详情页回复按钮点击
  927. Report.reportLog({
  928. pageSource: Report.pageSource.mainPage,
  929. businessType: Report.businessType.buttonClick,
  930. objectType: Report.objectType.replyClickByDetailPage
  931. });
  932. let eleList = tweetReply.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('span[data-text="true"]');
  933. reportReplyResult(eleList, params, () => {
  934. // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
  935. chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
  936. });
  937. })
  938. }
  939. }
  940. }
  941. export function onTweetReplyClick(params) {
  942. let iframe = window.parent.document.getElementById(params.postId);
  943. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  944. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  945. if (replyBtn) {
  946. replyBtn.addEventListener('click', () => {
  947. onReplyDialogOpen(params, iframe);
  948. })
  949. }
  950. }
  951. function onReplyDialogOpen(params, iframe) {
  952. setTimeout(() => {
  953. let dialog = document.querySelector('div[role="dialog"]');
  954. let replyBtn;
  955. if (dialog) {
  956. let dialogContent = dialog.querySelector('div[role="dialog"]');
  957. replyBtn = dialog.querySelector('div[data-testid="toolBar"]').querySelector('div[data-testid="tweetButton"]');
  958. if (dialogContent) {
  959. let width = dialogContent.offsetWidth;
  960. let ele = document.createElement('div');
  961. ele.innerText = 'Tag 3 friends to complete the task';
  962. ele.style.cssText = `width: ${width}px; height: 38px; color: #fff; font-weight: 600;
  963. font-size: 16px; display: flex; align-items: center; justify-content: center; background: #1D9BF0;
  964. opacity: 0.8; position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1000`;
  965. dialogContent.style.top = '80px';
  966. dialogContent.parentNode.appendChild(ele);
  967. }
  968. } else {
  969. dialog = document.querySelector('main[role="main"]');
  970. if (dialog) {
  971. replyBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  972. }
  973. }
  974. if (dialog && replyBtn) {
  975. replyBtn.addEventListener('click', function () {
  976. // 推文页回复按钮点击
  977. Report.reportLog({
  978. pageSource: Report.pageSource.mainPage,
  979. businessType: Report.businessType.buttonClick,
  980. objectType: Report.objectType.replyClickByTwitterList
  981. });
  982. let eleList = dialog.querySelector('div[contenteditable="true"]').querySelectorAll('span[data-text="true"]');
  983. reportReplyResult(eleList, params, () => {
  984. // 上報完成
  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. }, 1000);
  991. }
  992. const reportReplyResult = throttle(function (eleList, params, cb) {
  993. //未过滤的回复文本
  994. Report.reportLog({
  995. pageSource: Report.pageSource.mainPage,
  996. businessType: Report.businessType.buttonClick,
  997. objectType: Report.objectType.replyInputTextGet
  998. }, {
  999. replyStr: eleList
  1000. });
  1001. if (eleList && eleList.length) {
  1002. let atList = [];
  1003. for (let i = 0; i < eleList.length; i++) {
  1004. let item = eleList[i];
  1005. // 是否有中文
  1006. let reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
  1007. if (item && item.innerText.startsWith('@') && !reg.test(item.innerText)) {
  1008. atList.push(item.innerText);
  1009. }
  1010. }
  1011. // 去重过滤文本
  1012. atList = Array.from(new Set(atList));
  1013. Report.reportLog({
  1014. pageSource: Report.pageSource.mainPage,
  1015. businessType: Report.businessType.buttonClick,
  1016. objectType: Report.objectType.replyFilterTextGet
  1017. }, {
  1018. replyStr: atList
  1019. });
  1020. if (atList.length >= 3) {
  1021. //真实上报
  1022. Report.reportLog({
  1023. pageSource: Report.pageSource.mainPage,
  1024. businessType: Report.businessType.buttonClick,
  1025. objectType: Report.objectType.replyReport
  1026. }, {
  1027. replyStr: atList
  1028. });
  1029. fetchAddFinishEvent({
  1030. eventType: params.type,
  1031. luckdropId: params.taskLuckdropId
  1032. }).then(res => {
  1033. if (res.code == 0) {
  1034. cb && cb();
  1035. }
  1036. })
  1037. }
  1038. }
  1039. }, 800);
  1040. // 根据推特id找到dom,完成任务
  1041. export function findTweetByIdDoTask({ tweet_Id = '', follow_names = [] }, task_type = 'like') {
  1042. // 1.根据推特ID寻找推文,获取卡片
  1043. // 获取所有卡片参数
  1044. let card_json_data = parseCard.parseAllDeNetCardParmas()
  1045. let result = card_json_data.filter((item) => { return item.tweet_Id == tweet_Id }) || []
  1046. if (result.length < 1) {
  1047. return
  1048. }
  1049. result = result[0]
  1050. switch (task_type) {
  1051. case 'like':
  1052. // https://twitter.com/intent/retweet?tweet_id=1525900221628223491
  1053. if (result.dom_card) {
  1054. result.dom_card.querySelector('div[data-testid=like]').click()
  1055. result.dom_card.querySelector('iframe').contentWindow.postMessage({ actionType: 'CONTENT_DONE_TASK', task_type, }, '*');
  1056. }
  1057. break;
  1058. case 'retweet':
  1059. if (result.dom_card) {
  1060. result.dom_card.querySelector('div[data-testid=retweet]').click()
  1061. result.dom_card.querySelector('div[data-testid=retweetConfirm]').click()
  1062. }
  1063. break
  1064. case 'follow':
  1065. follow_names.forEach((item) => {
  1066. window.open(`https://twitter.com/intent/follow?screen_name=${item}&tweet_Id=${tweet_Id}`)
  1067. })
  1068. break
  1069. }
  1070. }
  1071. function clickByDataTestId(e, id, callback) {
  1072. if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == id) {
  1073. callback()
  1074. } else if (e.target.closest('div[data-testid=' + id + ']')) {
  1075. callback()
  1076. }
  1077. }
  1078. // 校验关注推特状态
  1079. export function checkTwitterTaskState() {
  1080. let task_type = ''
  1081. let url = window.location.href
  1082. let tweet_Id
  1083. let task_data = {
  1084. follow_name: ''
  1085. }
  1086. // 校验当前链接
  1087. if (url.includes('https://twitter.com/intent/retweet')) {
  1088. task_type = 'retweet'
  1089. } else if (url.includes('https://twitter.com/intent/follow')) {
  1090. task_type = 'follow'
  1091. task_data.follow_name = getQueryString('screen_name')
  1092. } else if (url.includes('https://twitter.com/intent/like')) {
  1093. task_type = 'like'
  1094. } else {
  1095. return
  1096. }
  1097. tweet_Id = getQueryString('tweet_id')
  1098. // let root_status
  1099. document.body.addEventListener('click', (e) => {
  1100. // 点击 确认
  1101. clickByDataTestId(e, 'confirmationSheetConfirm', () => {
  1102. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1103. })
  1104. // 点击取消
  1105. clickByDataTestId(e, 'confirmationSheetCancel', () => {
  1106. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  1107. })
  1108. // 点击 蒙层
  1109. if (e.target && e.target.nextSibling && e.target.nextSibling.dataset && e.target.nextSibling.dataset.testid == 'confirmationSheetDialog') {
  1110. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  1111. }
  1112. }, true)
  1113. let timer = setInterval(() => {
  1114. // 喜欢
  1115. if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
  1116. clearInterval(timer)
  1117. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1118. }
  1119. // 转推
  1120. if (document.querySelector('div[data-testid=unretweet]') && task_type == 'retweet') {
  1121. clearInterval(timer)
  1122. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1123. }
  1124. // 关注
  1125. if (task_type == 'follow') {
  1126. let follow_area = document.querySelector('div[data-testid=placementTracking]')
  1127. if (follow_area && follow_area.querySelectorAll('div')) {
  1128. follow_area = follow_area.querySelectorAll('div')
  1129. clearInterval(timer)
  1130. for (let i in follow_area) {
  1131. if (follow_area[i] && follow_area[i].dataset && follow_area[i].dataset.testid && follow_area[i].dataset.testid.indexOf('unfollow') > 0) {
  1132. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  1133. break
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }, 1000)
  1139. }
  1140. export function getTweetAuthorByDom(params) {
  1141. let iframe = document.getElementById(params.postId);
  1142. if (!iframe) {
  1143. return;
  1144. }
  1145. let fullNameDom;
  1146. let pathNameArr = window.location.pathname.split('/');
  1147. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  1148. fullNameDom = iframe.parentNode.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  1149. } else {
  1150. fullNameDom = iframe.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  1151. }
  1152. if (fullNameDom) {
  1153. let arr = fullNameDom.href.split('/');
  1154. if (arr.length) {
  1155. let fullName = arr[arr.length - 1];
  1156. if (fullName) {
  1157. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_GET_TWEET_AUTHOR', data: { fullName } }, '*');
  1158. }
  1159. }
  1160. }
  1161. }
  1162. export function doTaskTwitterAPI({ task_data, task_type }) {
  1163. switch (task_type) {
  1164. case 'like':
  1165. TwitterLikeAPI(task_data.tweet_Id)
  1166. break
  1167. case 'retweet':
  1168. TwitterRetweetAPI(task_data.tweet_Id)
  1169. break
  1170. case 'follow':
  1171. task_data.follow_data.forEach((item) => {
  1172. if (item.name && item.twitterUserId) {
  1173. TwitterFollowAPI(item, task_data.tweet_Id)
  1174. }
  1175. })
  1176. break
  1177. }
  1178. }
  1179. export function showJoinDialog(data) {
  1180. let iframe = document.querySelector('#nftProjectId')
  1181. iframe.style.display = 'block'
  1182. iframe.contentWindow.postMessage({ actionType: 'SHOW_JOIN_DATA', data }, '*');
  1183. iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/group?params=${JSON.stringify(data)}&time=${new Date().getTime()}`)
  1184. }
  1185. const TwitterFollowAPI = (item, tweet_Id) => {
  1186. fetch("https://twitter.com/i/api/1.1/friendships/create.json", {
  1187. "headers": {
  1188. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1189. "content-type": "application/x-www-form-urlencoded",
  1190. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1191. "sec-ch-ua-mobile": "?0",
  1192. "sec-ch-ua-platform": "\"macOS\"",
  1193. "x-csrf-token": getCookie('ct0'),
  1194. "x-twitter-active-user": "yes",
  1195. "x-twitter-auth-type": "OAuth2Session",
  1196. "x-twitter-client-language": "zh-cn"
  1197. },
  1198. "referrer": "https://twitter.com/home",
  1199. "referrerPolicy": "strict-origin-when-cross-origin",
  1200. "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 + "",
  1201. "method": "POST",
  1202. "mode": "cors",
  1203. "credentials": "include"
  1204. }).then(() => {
  1205. let task_data = {
  1206. follow_name: item.name
  1207. }
  1208. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: true }, () => { })
  1209. }).catch(() => {
  1210. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: false }, () => { })
  1211. })
  1212. }
  1213. const TwitterRetweetAPI = (tweet_Id) => {
  1214. fetch("https://twitter.com/i/api/graphql/ojPdsZsimiJrUGLR1sjUtA/CreateRetweet", {
  1215. "headers": {
  1216. "accept": "*/*",
  1217. "accept-language": "zh,en;q=0.9,zh-CN;q=0.8",
  1218. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1219. "content-type": "application/json",
  1220. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1221. "sec-ch-ua-mobile": "?0",
  1222. "sec-ch-ua-platform": "\"macOS\"",
  1223. "sec-fetch-dest": "empty",
  1224. "sec-fetch-mode": "cors",
  1225. "sec-fetch-site": "same-origin",
  1226. "x-csrf-token": getCookie('ct0'),
  1227. "x-twitter-active-user": "yes",
  1228. "x-twitter-auth-type": "OAuth2Session",
  1229. "x-twitter-client-language": "zh-cn"
  1230. },
  1231. "referrer": "https://twitter.com/home",
  1232. "referrerPolicy": "strict-origin-when-cross-origin",
  1233. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\",\"dark_request\":false},\"queryId\":\"ojPdsZsimiJrUGLR1sjUtA\"}",
  1234. "method": "POST",
  1235. "mode": "cors",
  1236. "credentials": "include"
  1237. }).then(() => {
  1238. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true }, () => { })
  1239. }).catch(() => {
  1240. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: false }, () => { })
  1241. })
  1242. }
  1243. const TwitterLikeAPI = (tweet_Id) => {
  1244. fetch("https://twitter.com/i/api/graphql/lI07N6Otwv1PhnEgXILM7A/FavoriteTweet", {
  1245. "headers": {
  1246. "accept": "*/*",
  1247. "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
  1248. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1249. "content-type": "application/json",
  1250. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
  1251. "sec-ch-ua-mobile": "?0",
  1252. "sec-ch-ua-platform": "\"Windows\"",
  1253. "sec-fetch-dest": "empty",
  1254. "sec-fetch-mode": "cors",
  1255. "sec-fetch-site": "same-origin",
  1256. "x-csrf-token": getCookie('ct0'),
  1257. "x-twitter-active-user": "yes",
  1258. "x-twitter-auth-type": "OAuth2Session",
  1259. "x-twitter-client-language": "en"
  1260. },
  1261. "referrer": "https://twitter.com/home",
  1262. "referrerPolicy": "strict-origin-when-cross-origin",
  1263. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\"},\"queryId\":\"lI07N6Otwv1PhnEgXILM7A\"}",
  1264. "method": "POST",
  1265. "mode": "cors",
  1266. "credentials": "include"
  1267. }).then(() => {
  1268. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true }, () => { })
  1269. }).catch(() => {
  1270. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false }, () => { })
  1271. })
  1272. }
  1273. export const TwitterApiUserByScreenName = (params) => {
  1274. let { screen_name } = params;
  1275. 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`, {
  1276. headers: {
  1277. "accept": "*/*",
  1278. "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
  1279. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1280. "content-type": "application/json",
  1281. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
  1282. "sec-ch-ua-mobile": "?0",
  1283. "sec-ch-ua-platform": "\"Windows\"",
  1284. "sec-fetch-dest": "empty",
  1285. "sec-fetch-mode": "cors",
  1286. "sec-fetch-site": "same-origin",
  1287. "x-csrf-token": getCookie('ct0'),
  1288. "x-twitter-active-user": "yes",
  1289. "x-twitter-auth-type": "OAuth2Session",
  1290. "x-twitter-client-language": "en"
  1291. },
  1292. }).then(function (response) {
  1293. chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: response.data.data || {} }, () => { })
  1294. }).catch(function (response) {
  1295. });
  1296. }
  1297. let click_old_time = new Date().getTime()
  1298. export const showTwitterPost = (data) => {
  1299. let click_new_time = new Date().getTime()
  1300. if ((click_new_time - click_old_time) < 3000) {
  1301. return
  1302. }
  1303. click_old_time = click_new_time
  1304. showEditTweet(() => {
  1305. clearPostContent(() => {
  1306. contentGetNftPostPre({
  1307. groupId: data.groupId
  1308. })
  1309. })
  1310. })
  1311. // addPublishTipsIframe({ type: 'nft' })
  1312. setGroupTabStatus();
  1313. }
  1314. export function publishNFTTweetEvent({ groupId, postId, srcContent }, callback) {
  1315. setTimeout(() => {
  1316. let publishTweetBtn;
  1317. let dialog = document.querySelector('div[role="dialog"]');
  1318. if (dialog) {
  1319. publishTweetBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  1320. } else {
  1321. let domMain = document.querySelector('main[role="main"]');
  1322. publishTweetBtn = domMain && domMain.querySelector('div[data-testid="tweetButton"]');
  1323. }
  1324. publishTweetBtn && publishTweetBtn.addEventListener('click', function () {
  1325. // 获取文案上报
  1326. publishNFTTweetPost({ postId, srcContent, groupId })
  1327. // 绑定推文id
  1328. bindTwitterArt.needBind = true;
  1329. bindTwitterArt.postId = postId;
  1330. callback && callback()
  1331. jumpTwitterDetailByAlert()
  1332. setTimeout(() => {
  1333. setGroupTabSelfStyle({
  1334. groupColor: 'rgb(83, 100, 113)',
  1335. groupFontWeight: '500',
  1336. lineDisplay: 'none'
  1337. });
  1338. sendMessageToGroupBanner({ type: 'arrow' })
  1339. }, 2000);
  1340. });
  1341. }, 800)
  1342. }
  1343. const sendMessageToGroupBanner = (params) => {
  1344. chrome.runtime.sendMessage({
  1345. actionType: "SWITCH_GROUP_BANNER_STATUS",
  1346. data: params
  1347. }, (res) => {
  1348. if (!res) {
  1349. Report.reportLog({
  1350. objectType: Report.objectType.chrome_extension_sendmessage_error
  1351. })
  1352. }
  1353. });
  1354. }
  1355. export const publishNFTTweetPost = ({ postId, srcContent, groupId }) => {
  1356. let inputEle = document.querySelector('div[contenteditable="true"]');
  1357. let textContent = inputEle.innerText
  1358. srcContent = srcContent.replaceAll('#DNFT', '')
  1359. srcContent = srcContent.replaceAll('⬇️', '')
  1360. srcContent = srcContent.replaceAll('Join', '')
  1361. srcContent = srcContent.replaceAll('Now:', '')
  1362. let arr = srcContent.split(' ') || []
  1363. arr.forEach((item) => {
  1364. if (textContent.includes(item)) {
  1365. textContent = textContent.replaceAll(item, '')
  1366. }
  1367. })
  1368. textContent = textContent.replaceAll('#DNFT', '')
  1369. textContent = textContent.replaceAll('⬇️', '')
  1370. textContent = textContent.replaceAll('Join', '')
  1371. textContent = textContent.replaceAll('Now:', '')
  1372. textContent = textContent.trim()
  1373. let formData = {
  1374. groupId,
  1375. textContent
  1376. }
  1377. let params = {
  1378. postBizData: JSON.stringify(formData),
  1379. postSrc: 1, //1 twitter
  1380. postType: 2, //2 nft
  1381. postId
  1382. }
  1383. chrome.runtime.sendMessage({
  1384. actionType: "CONTENT_NFT_TXT_PUBLISH",
  1385. data: params
  1386. }, () => { });
  1387. }
  1388. const contentGetNftPostPre = (data) => {
  1389. chrome.runtime.sendMessage({
  1390. actionType: "CONTENT_GET_TWITTER_NFT_POST_PRE",
  1391. data
  1392. }, () => { });
  1393. }
  1394. let tweet_nft_content = {}
  1395. export const setTwitterTextarea = (params, num = 5) => {
  1396. if (num <= 0) {
  1397. return
  1398. }
  1399. tweet_nft_content = params
  1400. let inputEle = document.querySelector('div[contenteditable="true"]');
  1401. if (inputEle) {
  1402. inputEle.focus();
  1403. setGroupIconStatus();
  1404. document.execCommand("insertText", false, '');
  1405. setTimeout(() => {
  1406. document.execCommand("insertText", false, params.srcContent + ' ');
  1407. // 光标定位到起始位置
  1408. setTimeout(() => {
  1409. inputEle.focus();
  1410. let sel = window.getSelection()
  1411. let range = document.createRange()
  1412. range.setStart(inputEle, 0)
  1413. range.setEnd(inputEle, 0)
  1414. sel.removeAllRanges()
  1415. sel.addRange(range);
  1416. }, 0)
  1417. publishNFTTweetEvent(params, bindTwitterArtMethod)
  1418. }, 1000)
  1419. } else {
  1420. setTimeout(() => {
  1421. num--
  1422. setTwitterTextarea(params, num)
  1423. }, 500);
  1424. }
  1425. }
  1426. const initGroupTip = () => {
  1427. let arr = window.location.pathname.split('/') || []
  1428. if (location.pathname == '/compose/tweet') {
  1429. return
  1430. }
  1431. if (!document.querySelector('div[data-testid=UserName]')) {
  1432. return
  1433. }
  1434. if (arr.length >= 2) {
  1435. let twitterAccount = arr[1]
  1436. let iframe_banner = document.querySelector('#denet_group_banner')
  1437. if (iframe_banner) {
  1438. if (twitterAccount != getQueryStringByUrl(iframe_banner.src, 'twitterAccount')) {
  1439. iframe_banner.style.display = 'none'
  1440. // iframe_banner.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
  1441. iframe_banner.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
  1442. }
  1443. return
  1444. }
  1445. try {
  1446. let dom = document.querySelector('div[data-testid="ScrollSnap-SwipeableList"]').closest('nav')
  1447. let iframe = document.createElement('iframe')
  1448. iframe.id = 'denet_group_banner'
  1449. iframe.style.cssText = 'border: medium none; display:none; width:100%; height:100px;'
  1450. iframe.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
  1451. // iframe.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
  1452. if (dom && !dom.parentNode.children[0].querySelector('iframe')) {
  1453. // dom.parentNode.insertBefore(iframe, dom)
  1454. dom.parentNode.children[0].appendChild(iframe)
  1455. }
  1456. } catch (error) {
  1457. }
  1458. }
  1459. }
  1460. export const showGroupTip = () => {
  1461. let dom_denet_group_banner = document.querySelector('#denet_group_banner')
  1462. dom_denet_group_banner.style.display = 'block';
  1463. groupBtnStyleChange();
  1464. }
  1465. export const hideBuyNFT = () => {
  1466. let iframe = document.querySelector('#nftProjectId')
  1467. iframe.style.display = 'none'
  1468. iframe.src = ''
  1469. }
  1470. export const showBuyNFT = ({ nft_project_Id }) => {
  1471. if (!nft_project_Id) {
  1472. return
  1473. }
  1474. let iframe = document.querySelector('#nftProjectId')
  1475. iframe.style.display = 'block'
  1476. iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/?nftProjectId=${nft_project_Id}`)
  1477. }
  1478. const initBuyNFT = () => {
  1479. let url = ''
  1480. let id = `nftProjectId`
  1481. createNFTIframe({ url, id })
  1482. }
  1483. export const showNFTCard = () => {
  1484. let urlInfo = new URL(window.location.href)
  1485. let isTwitter = urlInfo.hostname === 'twitter.com'
  1486. let userElem = document.querySelector('div[data-testid="UserName"]');
  1487. let sideElem = document.querySelector('div[data-testid="sidebarColumn"]')
  1488. let tabIndex = sideElem && sideElem.querySelector('div[tabindex="0"]');
  1489. let isAppend = document.querySelector('div[id="de-nft-node"]');
  1490. let where = isTwitter && userElem && tabIndex;
  1491. if (where) {
  1492. let iframe = document.createElement('iframe');
  1493. iframe.src = chrome.runtime.getURL(`/iframe/nft-card.html`)
  1494. iframe.style.cssText = 'border:medium none; width:100%; height:290px;';
  1495. let nftElement = document.createElement('div');
  1496. nftElement.id = 'de-nft-node';
  1497. nftElement.innerHTML = `
  1498. ${iframe.outerHTML}
  1499. <style>
  1500. #de-nft-node {height:290px; margin-bottom:17px; display:none;}
  1501. </style>
  1502. `;
  1503. if (tabIndex && tabIndex.firstChild && tabIndex.firstChild.childNodes && !isAppend) {
  1504. tabIndex.firstChild.insertBefore(nftElement, tabIndex.firstChild.childNodes[2]);
  1505. }
  1506. }
  1507. }
  1508. export const showNFTSale = () => {
  1509. document.querySelector('div[id="de-nft-node"]').style.display = 'block';
  1510. }
  1511. export const addEventAction = () => {
  1512. let urlInfo = new URL(window.location.href)
  1513. let isTwitter = urlInfo.hostname === 'twitter.com'
  1514. // 页面滚动
  1515. if (isTwitter) {
  1516. // 首页
  1517. if (urlInfo.pathname === '/home') {
  1518. window.addEventListener('scroll', () => {
  1519. hideNFTGroupList()
  1520. })
  1521. }
  1522. }
  1523. }
  1524. export const appendPopupPage = (params = {}) => {
  1525. let { path = '' } = params;
  1526. let iframe = document.createElement('iframe');
  1527. iframe.id = 'de-popup-page';
  1528. iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
  1529. iframe.style.cssText = `border: medium none; width: 375px !important;
  1530. 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;
  1531. animation-duration: 0.5s !important;
  1532. animation-timing-function: ease-in-out !important;
  1533. animation-fill-mode: forwards !important;
  1534. transition: all 1s ease 0s !important;right: -385px;transform: translateX(385px);`
  1535. let iframeContent = document.getElementById('de-popup-page');
  1536. let overlayDom = document.createElement('div');
  1537. overlayDom.id = 'de-popup-overlay';
  1538. overlayDom.style.cssText = `position: fixed;z-index: 88888;top: 0;
  1539. left: 0;width: 100%;height: 100%;opacity: 0;display: none`;
  1540. let overlay = document.getElementById('de-popup-overlay');
  1541. let body = document.querySelector('body');
  1542. if (!iframeContent && body) {
  1543. document.querySelector('body').appendChild(iframe);
  1544. if (!overlay) {
  1545. document.querySelector('body').appendChild(overlayDom);
  1546. overlayDom.addEventListener('click', function () {
  1547. hidePopupPage();
  1548. })
  1549. } else {
  1550. overlay.addEventListener('click', function () {
  1551. hidePopupPage();
  1552. })
  1553. }
  1554. }
  1555. }
  1556. let showPopupPageFrom = '';
  1557. export const showPopupPage = (params = {}) => {
  1558. let { path = '', from, showJoinGroupFinish = false } = params;
  1559. showPopupPageFrom = from;
  1560. hidePinTips();
  1561. hideNoticeBindTweet();
  1562. let iframe = document.getElementById('de-popup-page');
  1563. if (!iframe) {
  1564. appendPopupPage();
  1565. iframe = document.getElementById('de-popup-page');
  1566. }
  1567. if (iframe) {
  1568. if (path) {
  1569. iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
  1570. }
  1571. iframe.style.transform = 'translateX(-' + 395 + 'px)';
  1572. chrome.runtime.sendMessage({
  1573. actionType: "CONTENT_POPUP_PAGE_SHOW",
  1574. data: {
  1575. path,
  1576. showJoinGroupFinish,
  1577. }
  1578. }, () => { });
  1579. chrome.runtime.sendMessage({
  1580. actionType: "CONTENT_SET_POPUP_CONFIG",
  1581. data: {
  1582. popup: ''
  1583. }
  1584. }, () => { });
  1585. let overlay = document.getElementById('de-popup-overlay');
  1586. overlay.style.display = 'block';
  1587. let htmlDom = document.querySelector('html');
  1588. if (htmlDom) {
  1589. htmlDom.style.overflowY = 'hidden';
  1590. }
  1591. }
  1592. }
  1593. export const hidePopupPage = () => {
  1594. let iframe = document.getElementById('de-popup-page');
  1595. if (iframe) {
  1596. iframe.style.transform = 'translateX(' + 385 + 'px)';
  1597. let overlay = document.getElementById('de-popup-overlay');
  1598. overlay.style.display = 'none';
  1599. let htmlDom = document.querySelector('html');
  1600. if (htmlDom) {
  1601. htmlDom.style.overflowY = 'auto';
  1602. }
  1603. chrome.runtime.sendMessage({
  1604. actionType: "CONTENT_SET_POPUP_CONFIG",
  1605. data: {
  1606. popup: 'popup.html'
  1607. }
  1608. }, () => { });
  1609. if (showPopupPageFrom == 'BUY_NFT_FINISH') {
  1610. chrome.runtime.sendMessage({
  1611. actionType: "CONTENT_GET_PINED",
  1612. data: {}
  1613. }, () => { });
  1614. showPopupPageFrom = '';
  1615. }
  1616. }
  1617. }
  1618. export const tiggerInjectPopupPage = () => {
  1619. let iframeContent = document.getElementById('de-popup-page');
  1620. if (iframeContent) {
  1621. hidePinTips();
  1622. hideNoticeBindTweet();
  1623. let { transform = '' } = iframeContent.style;
  1624. if (transform == 'translateX(385px)' || !transform) {
  1625. showPopupPage();
  1626. } else {
  1627. hidePopupPage();
  1628. }
  1629. } else {
  1630. appendPopupPage();
  1631. setTimeout(() => {
  1632. let iframe = document.getElementById('de-popup-page');
  1633. let { transform = '' } = iframe.style;
  1634. if (transform == 'translateX(385px)' || !transform) {
  1635. showPopupPage();
  1636. } else {
  1637. hidePopupPage();
  1638. }
  1639. }, 300)
  1640. }
  1641. }
  1642. export const setPopupConfByPopupPage = () => {
  1643. let iframe = document.getElementById('de-popup-page');
  1644. if (iframe) {
  1645. let { transform = '' } = iframe.style;
  1646. if (transform && transform == 'translateX(-395px)') {
  1647. chrome.runtime.sendMessage({
  1648. actionType: "CONTENT_SET_POPUP_CONFIG",
  1649. data: {
  1650. popup: ''
  1651. }
  1652. }, () => { });
  1653. } else {
  1654. chrome.runtime.sendMessage({
  1655. actionType: "CONTENT_SET_POPUP_CONFIG",
  1656. data: {
  1657. popup: 'popup.html'
  1658. }
  1659. }, () => { });
  1660. }
  1661. } else {
  1662. chrome.runtime.sendMessage({
  1663. actionType: "CONTENT_SET_POPUP_CONFIG",
  1664. data: {
  1665. popup: 'popup.html'
  1666. }
  1667. }, () => { });
  1668. }
  1669. }
  1670. /**
  1671. *
  1672. * Group Tab List Start
  1673. */
  1674. /**
  1675. *
  1676. * 创建 Group Tab
  1677. */
  1678. const createGroupTabNode = () => {
  1679. let groupIcon = document.createElement('img');
  1680. groupIcon.id = 'de-group-tab-icon'
  1681. groupIcon.src = require("@/assets/img/icon-group-tab-item.png");
  1682. groupIcon.style.cssText = 'width:20px;height: 20px;margin-right:4px;';
  1683. let divNode = document.createElement('div');
  1684. divNode.style.cssText = 'display: flex; align-items: center;height: 100%';
  1685. divNode.appendChild(groupIcon);
  1686. divNode.appendChild(document.createTextNode('Group'));
  1687. let lineDom = document.createElement('div');
  1688. lineDom.id = 'de-tab-line';
  1689. lineDom.style.cssText = `border-radius: 9999px;
  1690. position: absolute;
  1691. bottom: 0px;
  1692. min-width: 56px;
  1693. align-self: center;
  1694. height: 4px;
  1695. background-color: rgb(29, 155, 240);
  1696. display: none`;
  1697. let groupTab = document.createElement('div');
  1698. groupTab.id = 'de-nav-tab-group';
  1699. groupTab.style.cssText = `z-index: 1;
  1700. position: relative;
  1701. display: flex;
  1702. min-width: 56px;
  1703. -webkit-box-pack: center;
  1704. justify-content: center;
  1705. -webkit-box-align: center;
  1706. align-items: center;
  1707. text-align: center;
  1708. padding: 0px 16px;
  1709. color: rgb(83, 100, 113);
  1710. font-weight: 700;
  1711. height: 53px;
  1712. cursor: pointer;
  1713. font: 500 15px / 20px TwitterChirp, -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;`;
  1714. groupTab.appendChild(divNode);
  1715. groupTab.appendChild(lineDom);
  1716. return groupTab;
  1717. }
  1718. const groupBtnStyleChange = () => {
  1719. let tab = getGroupTabNode();
  1720. if (tab) {
  1721. let line = tab.querySelector('#de-tab-line');
  1722. if (line) {
  1723. let { display } = line.style;
  1724. if (display != 'none') {
  1725. sendMessageToGroupBanner({ type: 'btn' })
  1726. }
  1727. }
  1728. }
  1729. }
  1730. const getGroupTabNode = () => {
  1731. let tab = document.querySelector('#de-nav-tab-group');
  1732. return tab;
  1733. }
  1734. const addGroupTab = () => {
  1735. if (!document.querySelector('div[data-testid=UserName]')) {
  1736. return
  1737. }
  1738. let tabListDom = document.querySelector('div[role="tablist"]');
  1739. let groupItemTab = getGroupTabNode();
  1740. if (tabListDom && !groupItemTab) {
  1741. let groupTab = createGroupTabNode();
  1742. tabListDom.appendChild(groupTab);
  1743. groupTab.addEventListener('mouseenter', function () {
  1744. groupTab.style.background = 'rgba(15, 20, 25, 0.1)'
  1745. });
  1746. groupTab.addEventListener('mouseleave', function () {
  1747. groupTab.style.background = 'none'
  1748. });
  1749. setTimeout(() => {
  1750. let count = 0;
  1751. hiddenMaskWeb3Tab(count);
  1752. }, 1300)
  1753. addGroupTabEventListener();
  1754. }
  1755. removeTweetTabEvent({
  1756. tabListDom
  1757. });
  1758. addTweetTabEventListener({
  1759. tabListDom
  1760. });
  1761. addTabGroupContent(() => {
  1762. checkNeedSelectGroupTab();
  1763. });
  1764. }
  1765. const hiddenMaskWeb3Tab = (count) => {
  1766. setTimeout(() => {
  1767. count++;
  1768. if (count < 6) {
  1769. let tab = getMaskWeb3Tab();
  1770. if (tab) {
  1771. tab.style.display = 'none'
  1772. } else {
  1773. hiddenMaskWeb3Tab(count);
  1774. }
  1775. }
  1776. }, 1000);
  1777. }
  1778. /**
  1779. * 跳转到个人主页 检查是否需要选中 Group tab
  1780. */
  1781. const checkNeedSelectGroupTab = () => {
  1782. if (window.location.pathname != '/home') {
  1783. setTimeout(() => {
  1784. getChromeStorage('groupTabData', (res) => {
  1785. console.log('groupTabData', res);
  1786. if (res && res.deTabVal == 'deGroupTab') {
  1787. chrome.storage.local.remove("groupTabData");
  1788. setTimeout(() => {
  1789. selectGroupTab();
  1790. }, 300)
  1791. }
  1792. })
  1793. }, 1300)
  1794. }
  1795. }
  1796. /** 选中 Group tab */
  1797. export const selectGroupTab = () => {
  1798. let groupTab = getGroupTabNode();
  1799. if (groupTab) {
  1800. groupTab.click();
  1801. }
  1802. };
  1803. export const groupTipsSelectGroupTab = (params = {}) => {
  1804. if (params.type == 'btn') {
  1805. let groupTab = getGroupTabNode();
  1806. if (groupTab) {
  1807. let line = groupTab.querySelector('#de-tab-line');
  1808. if (line) {
  1809. let { display } = line.style;
  1810. if (display == 'none') {
  1811. groupTab.click();
  1812. }
  1813. }
  1814. }
  1815. } else {
  1816. selectGroupTab();
  1817. }
  1818. }
  1819. /**
  1820. *
  1821. * Group tab点击事件监听
  1822. */
  1823. const addGroupTabEventListener = () => {
  1824. let groupTab = getGroupTabNode();
  1825. groupTab.addEventListener('click', function () {
  1826. let bgColor = document.querySelector('body').style.backgroundColor;
  1827. let groupColor = systemInfo.theme == 'dark' && bgColor == 'rgb(0, 0, 0)' ? '#fff' : 'rgb(15, 20, 25)';
  1828. // let groupColor = systemInfo.theme == 'light' ? 'rgb(15, 20, 25)' : '#fff';
  1829. setGroupTabSelfStyle({
  1830. groupColor: groupColor,
  1831. groupFontWeight: '700',
  1832. lineDisplay: 'block'
  1833. });
  1834. setTweetActiveTabStyle({
  1835. color: 'rgb(83, 100, 113)',
  1836. display: 'none'
  1837. });
  1838. setTabContentStyle({
  1839. tweetTabContentDisply: 'none',
  1840. iframeContentDisplay: 'block'
  1841. });
  1842. refreshTabGroup();
  1843. window.addEventListener('scroll', addPageScrollEvent);
  1844. let tipsDom = document.querySelector('#denet_group_banner');
  1845. if (tipsDom) {
  1846. sendMessageToGroupBanner({ type: 'btn' })
  1847. } else {
  1848. onShowGroupBanner();
  1849. }
  1850. })
  1851. }
  1852. const onShowGroupBanner = () => {
  1853. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  1854. switch (req.actionType) {
  1855. case 'IFRAME_SHOW_GROUP_TIP':
  1856. sendMessageToGroupBanner({ type: 'btn' })
  1857. if (!getGroupTabNode()) {
  1858. addGroupTab();
  1859. }
  1860. break
  1861. }
  1862. })
  1863. }
  1864. const addPageScrollEvent = () => {
  1865. let wrapperDom = document.querySelector('html');
  1866. let contentDom = document.querySelector('main[role="main"]');
  1867. let data = {
  1868. wrapperHeight: wrapperDom.offsetHeight,
  1869. wrapperScrollTop: wrapperDom.scrollTop,
  1870. contentHeight: contentDom.offsetHeight
  1871. }
  1872. chrome.runtime.sendMessage({
  1873. actionType: "CONTENT_GROUP_LIST_SCROLL",
  1874. data: data
  1875. }, () => { });
  1876. };
  1877. const removeTweetTabEvent = (params) => {
  1878. let { tabListDom } = params;
  1879. if (tabListDom) {
  1880. let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
  1881. if (tweetTabItem.length) {
  1882. for (let i = 0; i < tweetTabItem.length; i++) {
  1883. let item = tweetTabItem[i];
  1884. item.removeEventListener('click', TweetTabEventHandler)
  1885. }
  1886. }
  1887. }
  1888. }
  1889. /**
  1890. *
  1891. * twitter tab点击事件监听
  1892. */
  1893. const addTweetTabEventListener = (params) => {
  1894. let { tabListDom } = params;
  1895. let groupItemTab = getGroupTabNode();
  1896. if (tabListDom && groupItemTab) {
  1897. // 监听twitter tab点击事件
  1898. let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
  1899. if (tweetTabItem.length) {
  1900. for (let i = 0; i < tweetTabItem.length; i++) {
  1901. let item = tweetTabItem[i];
  1902. item.addEventListener('click', TweetTabEventHandler)
  1903. }
  1904. }
  1905. }
  1906. }
  1907. const TweetTabEventHandler = () => {
  1908. window.removeEventListener('scroll', addPageScrollEvent);
  1909. setGroupTabSelfStyle({
  1910. groupColor: 'rgb(83, 100, 113)',
  1911. groupFontWeight: '500',
  1912. lineDisplay: 'none'
  1913. });
  1914. setTabContentStyle({
  1915. tweetTabContentDisply: 'block',
  1916. iframeContentDisplay: 'none'
  1917. });
  1918. setTweetActiveTabStyle({
  1919. color: 'rgb(15, 20, 25)',
  1920. display: 'block'
  1921. });
  1922. sendMessageToGroupBanner({ type: 'arrow' })
  1923. };
  1924. /**
  1925. * 设置 Group Tab 样式
  1926. * */
  1927. const setGroupTabSelfStyle = (params = {}) => {
  1928. let { groupColor, groupFontWeight, lineDisplay } = params;
  1929. let groupTab = getGroupTabNode();
  1930. if (groupTab) {
  1931. groupTab.style.color = groupColor;
  1932. groupTab.style.fontWeight = groupFontWeight;
  1933. let lineDom = groupTab.querySelector('#de-tab-line');
  1934. if (lineDom) {
  1935. lineDom.style.display = lineDisplay;
  1936. }
  1937. }
  1938. };
  1939. /**
  1940. * 切换到 Group tab时 刷新列表
  1941. */
  1942. export const refreshTabGroup = () => {
  1943. chrome.runtime.sendMessage({
  1944. actionType: "CONTENT_REFRESH_TAB_GROUP_LIST",
  1945. data: {}
  1946. }, () => { });
  1947. }
  1948. /**
  1949. *
  1950. * tab选中时设置 激活 的字体样式和选中条
  1951. */
  1952. const setTweetActiveTabStyle = (params) => {
  1953. let { color, display } = params || {};
  1954. let tab = document.querySelector('a[aria-selected="true"]');
  1955. if (tab) {
  1956. let tweetActiveTab = tab.querySelector('div');
  1957. if (tweetActiveTab) {
  1958. tweetActiveTab.style.color = color;
  1959. let tweetTabLine = tweetActiveTab.querySelector('div');
  1960. if (tweetTabLine) {
  1961. tweetTabLine.style.display = display;
  1962. }
  1963. }
  1964. }
  1965. }
  1966. /**
  1967. *
  1968. * 设置 tab 切换时 tab内容的样式(显示隐藏)
  1969. */
  1970. const setTabContentStyle = (params) => {
  1971. let { tweetTabContentDisply, iframeContentDisplay } = params;
  1972. let tweetTabContent = getTweetTabContent();
  1973. if (tweetTabContent) {
  1974. if (tweetTabContentDisply == 'block') {
  1975. let { visibility } = tweetTabContent.style;
  1976. if (visibility == 'hidden') {
  1977. tweetTabContent.style.visibility = 'visible';
  1978. tweetTabContent.style.height = 'auto';
  1979. tweetTabContent.style.overflow = 'auto';
  1980. }
  1981. } else {
  1982. tweetTabContent.style.visibility = 'hidden';
  1983. tweetTabContent.style.height = '0px';
  1984. tweetTabContent.style.overflow = 'hidden';
  1985. tweetTabContent.style.margin = '0';
  1986. }
  1987. }
  1988. let iframeContent = getGroupTabContentNode();
  1989. if (!iframeContent) {
  1990. addTabGroupContent();
  1991. }
  1992. setTimeout(() => {
  1993. iframeContent = getGroupTabContentNode();
  1994. if (iframeContent) {
  1995. iframeContent.style.display = iframeContentDisplay;
  1996. }
  1997. })
  1998. };
  1999. /**
  2000. *
  2001. * 获取 twitter tab 下的内容
  2002. */
  2003. const getTweetTabContent = () => {
  2004. let tweetTabContent = document.querySelector('[data-testid="primaryColumn"] [role="navigation"] + * > div[aria-label]:not([role="progressbar"])') || document.querySelector('div[data-testid="emptyState"]');
  2005. return tweetTabContent;
  2006. }
  2007. /**
  2008. * 注入 Group List 内容
  2009. */
  2010. const addTabGroupContent = (cb) => {
  2011. let params = {
  2012. windowLocation: window.location
  2013. }
  2014. let iframe = document.createElement('iframe');
  2015. iframe.id = 'de-tab-group-content';
  2016. iframe.src = chrome.runtime.getURL('/iframe/tab-group.html') + `?params=${JSON.stringify(params)}`;
  2017. iframe.style.cssText = `border: medium none; height: 500px;display: none`
  2018. let iframeContent = getGroupTabContentNode();
  2019. let tweetTabContent = getTweetTabContent();
  2020. if (!iframeContent) {
  2021. if (tweetTabContent && tweetTabContent.parentElement) {
  2022. tweetTabContent.parentElement.appendChild(iframe);
  2023. cb && cb();
  2024. }
  2025. }
  2026. };
  2027. const getGroupTabContentNode = () => {
  2028. let content = document.getElementById('de-tab-group-content');
  2029. return content;
  2030. }
  2031. const setGroupTabStatus = () => {
  2032. let groupTab = getGroupTabNode();
  2033. if (groupTab) {
  2034. let line = groupTab.querySelector('#de-tab-line');
  2035. if (line) {
  2036. let { display } = line.style;
  2037. if (display != 'none') {
  2038. groupTab.click();
  2039. }
  2040. }
  2041. } else {
  2042. setTimeout(() => {
  2043. addGroupTab();
  2044. }, 2000)
  2045. }
  2046. clearInterval(fixProfileTabAutoTimer);
  2047. fixProfileTabAutoSwitch();
  2048. };
  2049. const fixProfileTabAutoSwitch = () => {
  2050. fixProfileTabAutoTimer = setInterval(() => {
  2051. let groupTab = getGroupTabNode();
  2052. let tweetTab = document.querySelector('a[aria-selected="true"]');
  2053. if (groupTab) {
  2054. let line = groupTab.querySelector('#de-tab-line');
  2055. if (line) {
  2056. let { display } = line.style;
  2057. if (display != 'none' && tweetTab) {
  2058. let groupContent = getGroupTabContentNode();
  2059. if (groupContent) {
  2060. let tweetTabContent = getTweetTabContent();
  2061. let { visibility } = tweetTabContent.style;
  2062. let { display } = groupContent.style;
  2063. if (display == 'block' && visibility != 'hidden') {
  2064. groupTab.click();
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }, 1000)
  2071. }
  2072. /**
  2073. *
  2074. * 设置Tab Group Iframe 样式
  2075. */
  2076. export const setTabGroupIframeStyle = (params, isReSize = false) => {
  2077. if (!isReSize) {
  2078. getSysTheme();
  2079. }
  2080. let iframeContent = getGroupTabContentNode();
  2081. if (iframeContent) {
  2082. let htmlHeight = document.querySelector('html').offsetHeight;
  2083. let primaryColumnHeightn = document.querySelector('div[data-testid="primaryColumn"]').offsetHeight;
  2084. let height = primaryColumnHeightn > htmlHeight ? primaryColumnHeightn : htmlHeight;
  2085. iframeContent.style.height = height + 'px';
  2086. }
  2087. }
  2088. /**
  2089. * mask web3 Tab
  2090. *
  2091. */
  2092. const getMaskWeb3Tab = () => {
  2093. let tab = document.querySelector('div[data-testid="ScrollSnap-nextButtonWrapper"] + span');
  2094. return tab;
  2095. }
  2096. export const pageJumpHandler = (params) => {
  2097. let { url } = params
  2098. if (url) {
  2099. window.open(url)
  2100. }
  2101. }
  2102. export const getTweetProfileNavTop = (params) => {
  2103. let top = document.querySelector('div[role="tablist"]').closest('nav').getBoundingClientRect().top;
  2104. chrome.runtime.sendMessage({
  2105. actionType: "CONTENT_SEND_GROUP_NAV_TOP", data: {
  2106. top,
  2107. scrollTop: params.scrollTop
  2108. }
  2109. }, () => { })
  2110. }
  2111. export const setGroupInfo = (params = {}) => {
  2112. tweetAccountBindGroupInfo.groupInfo = params;
  2113. let groupTab = getGroupTabNode();
  2114. if (!params.nftGroupId) {
  2115. let { pathname = '' } = window.location;
  2116. if (pathname == "/compose/tweet") {
  2117. return;
  2118. };
  2119. if (groupTab) {
  2120. groupTab.style.display = 'none';
  2121. } else {
  2122. setTimeout(() => {
  2123. groupTab = getGroupTabNode();
  2124. if (groupTab) {
  2125. groupTab.style.display = 'none';
  2126. }
  2127. }, 800)
  2128. }
  2129. } else {
  2130. if (groupTab) {
  2131. let { display } = groupTab.style;
  2132. if (display == 'none') {
  2133. groupTab.style.display = 'block';
  2134. }
  2135. }
  2136. }
  2137. }
  2138. const getSysTheme = () => {
  2139. const themeMedia = window.matchMedia("(prefers-color-scheme: light)");
  2140. if (themeMedia.matches) {
  2141. systemInfo.theme = 'light'
  2142. } else {
  2143. systemInfo.theme = 'dark'
  2144. }
  2145. sysThemeChange();
  2146. themeMedia.addListener(e => {
  2147. addGroupTab()
  2148. if (e.matches) {
  2149. systemInfo.theme = 'light'
  2150. } else {
  2151. systemInfo.theme = 'dark'
  2152. }
  2153. sysThemeChange();
  2154. });
  2155. }
  2156. const sysThemeChange = () => {
  2157. setTimeout(() => {
  2158. let bgColor = document.querySelector('body').style.backgroundColor;
  2159. chrome.runtime.sendMessage({
  2160. actionType: "CONTENT_SYS_THEME_CHANGE", data: {
  2161. theme: systemInfo.theme,
  2162. twitterTheme: bgColor == 'rgb(0, 0, 0)' ? 'dark' : 'light'
  2163. }
  2164. }, () => { })
  2165. }, 800)
  2166. }
  2167. /**
  2168. *
  2169. * Group Tab List End
  2170. *
  2171. */
  2172. export const loginSuccessHandle = () => {
  2173. // 检查是否漏出group图标
  2174. checkUserJoinGroup(() => {
  2175. showNFTGroupIcon()
  2176. addEventAction()
  2177. addJoinedGroupList();
  2178. })
  2179. }
  2180. export const showPublishDialog = () => {
  2181. let smallBtn = document.getElementById('de-btn1');
  2182. if (smallBtn) {
  2183. smallBtn.click();
  2184. }
  2185. }