twitter.js 73 KB

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