twitter.js 96 KB

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