twitter.js 82 KB

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