twitter.js 81 KB

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