twitter.js 71 KB

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