twitter.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
  2. import { throttle, getQueryString, getCookie, nextTick } 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. let dom = {};
  8. function twitterPinLogin() {
  9. if (window.location.href == 'https://api.twitter.com/oauth/authorize') {
  10. let code = document.querySelector('code')
  11. if (code) {
  12. chrome.runtime.sendMessage({ actionType: "CONTENT_SEND_CODE", code: code.innerText }, () => { })
  13. // port.postMessage({ state: 'CONTENT_SEND_CODE', code: code.innerText })
  14. }
  15. }
  16. }
  17. function getDiscordAuthCode() {
  18. if (window.location.href.indexOf(discordAuthRedirectUri) > -1) {
  19. const urlParams = new URLSearchParams(window.location.search);
  20. const code = urlParams.get('code');
  21. if (code) {
  22. chrome.runtime.sendMessage({ actionType: "CONTENT_SEND_DISCORD_AUTH_CODE", code }, () => { })
  23. }
  24. }
  25. };
  26. /**
  27. * 渲染要插入的dom,初始化逻辑
  28. * @param port
  29. */
  30. function renderDom() {
  31. if (window.location.href.indexOf('https://twitter.com') > -1) {
  32. _createBtnDom();
  33. onWindowResize();
  34. checkHasDeBtn();
  35. setTimeout(() => {
  36. _addIframe();
  37. _addDeNetBtn();
  38. _getSliderTwitterBtn();
  39. }, 800)
  40. }
  41. }
  42. /**
  43. * 展示give弹窗
  44. */
  45. export function showGiveDialogHandler(userInfo) {
  46. let iframe = document.getElementById('iframe-content');
  47. if (iframe) {
  48. iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG', userInfo }, '*');
  49. } else {
  50. _addIframe();
  51. let iframe = document.getElementById('iframe-content');
  52. iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG', userInfo }, '*');
  53. }
  54. }
  55. export function showIframeHandler() {
  56. document.getElementById('iframe-content').style.display = 'block';
  57. }
  58. export function hideIframeHandler() {
  59. document.getElementById('iframe-content').style.display = 'none';
  60. }
  61. /**
  62. * 展示twitter原生发布框
  63. */
  64. let tweetPublishStore = {
  65. showPublishDialog: false
  66. }
  67. export function showTwitterPublishDialogHandler(publishRes) {
  68. let bigBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  69. if (bigBtn) {
  70. bigBtn.click();
  71. tweetPublishStore.showPublishDialog = true;
  72. } else {
  73. let smallBtn = document.querySelector('a[href="/compose/tweet"]')
  74. smallBtn && smallBtn.click();
  75. tweetPublishStore.showPublishDialog = true;
  76. }
  77. setChromeStorage({ publishData: JSON.stringify(publishRes) })
  78. addPublishTipsIframe({
  79. srcContent: publishRes.copyContent
  80. })
  81. _setPublishContent(publishRes.srcContent);
  82. _publishTweetEvent(publishRes, bindTwitterArtMethod);
  83. }
  84. export function twitterPublishHandler(res) {
  85. let bigBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  86. if (bigBtn) {
  87. bigBtn.click();
  88. } else {
  89. let smallBtn = document.querySelector('a[href="/compose/tweet"]')
  90. smallBtn && smallBtn.click();
  91. }
  92. nextTick(() => {
  93. document.execCommand('selectAll');
  94. }, 100).then(() => {
  95. document.execCommand('delete');
  96. _setPublishContent(res.srcContent);
  97. })
  98. }
  99. export function showPinTips() {
  100. getChromeStorage('pinData', (res) => {
  101. if (!res || res.show) {
  102. let domPop = document.getElementById('de-pin-pop');
  103. domPop.style.display = 'block';
  104. }
  105. })
  106. }
  107. function addPinedPop() {
  108. let domPop = document.getElementById('de-pin-pop');
  109. if (domPop) {
  110. return;
  111. }
  112. let popWrapper = document.createElement('div');
  113. 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';
  114. popWrapper.id = 'de-pin-pop'
  115. let img = document.createElement('img');
  116. img.src = require("@/assets/img/img-pined-guide.png");
  117. img.width = 253;
  118. let contentDom = document.createElement('div');
  119. 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>"
  120. popWrapper.appendChild(img);
  121. popWrapper.appendChild(contentDom);
  122. let layersDom = document.getElementById('layers');
  123. if (layersDom) {
  124. layersDom.appendChild(popWrapper);
  125. } else {
  126. document.querySelector('body').appendChild(popWrapper);
  127. }
  128. let deCheck = document.querySelector('#de-check');
  129. let deRemind = document.querySelector('#de-remind');
  130. deCheck.onclick = function (e) {
  131. e && e.stopPropagation && e.stopPropagation();
  132. setChromeStorage({ pinData: JSON.stringify({ show: !this.checked }) })
  133. }
  134. deRemind.onclick = function () {
  135. deCheck.checked = !deCheck.checked;
  136. setChromeStorage({ pinData: JSON.stringify({ show: !deCheck.checked }) })
  137. }
  138. document.querySelector('.de-pin-skip').onclick = function () {
  139. document.querySelector('#de-pin-pop').style.display = 'none';
  140. }
  141. }
  142. function getUserInfo(cb) {
  143. getChromeStorage('userInfo', (res) => {
  144. cb && cb(res);
  145. })
  146. }
  147. // 绑定推文id所需参数
  148. let bindTwitterArt = {
  149. needBind: false,
  150. postId: '',
  151. isBindIng: false
  152. };
  153. /**
  154. * 监听dialog内点击原生发布按钮事件
  155. * @private
  156. */
  157. function _publishTweetEvent(params, cb) {
  158. setTimeout(() => {
  159. let publishTweetBtn;
  160. let dialog = document.querySelector('div[role="dialog"]');
  161. if (dialog) {
  162. publishTweetBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  163. onClosePublishDialogHandle(dialog, params)
  164. } else {
  165. let domMain = document.querySelector('main[role="main"]');
  166. publishTweetBtn = domMain && domMain.querySelector('div[data-testid="tweetButton"]');
  167. }
  168. publishTweetBtn && publishTweetBtn.addEventListener('click', function () {
  169. bindTwitterArt.needBind = true;
  170. bindTwitterArt.postId = params.postId;
  171. tweetPublishStore.showPublishDialog = false;
  172. // checkIsShowReSend(dialog, params);
  173. cb && cb()
  174. });
  175. }, 800)
  176. }
  177. function onClosePublishDialogHandle(dom, params) {
  178. dom.querySelector('div[role="group"]').addEventListener('click', function () {
  179. setTimeout(() => {
  180. let parent = document.querySelector('div[data-testid="confirmationSheetDialog"]');
  181. if (parent) {
  182. let btnArr = parent.querySelectorAll('div[role=button]')
  183. for (let i = 0; i < btnArr.length; i++) {
  184. let btn = btnArr[i];
  185. btn.addEventListener('click', function () {
  186. tweetPublishStore.showPublishDialog = false;
  187. let taskLuckdropId = JSON.parse(params.postBizData).taskLuckdropId;
  188. noticeBindTweet({ postId: params.postId, taskLuckdropId });
  189. })
  190. }
  191. } else {
  192. setTimeout(() => {
  193. let dialog = document.querySelector('div[role="dialog"]');
  194. if (!dialog) {
  195. tweetPublishStore.showPublishDialog = false;
  196. }
  197. }, 800)
  198. }
  199. }, 1000)
  200. })
  201. }
  202. function checkIsShowReSend(dom, params) {
  203. let str = dom.querySelector('div[data-contents="true"]').innerHTML;
  204. if (str.indexOf(params.postId) < 0) {
  205. let taskLuckdropId = JSON.parse(params.postBizData).taskLuckdropId;
  206. noticeBindTweet({ postId: params.postId, taskLuckdropId });
  207. }
  208. }
  209. /**
  210. * 在输入推文区插入deNet按钮
  211. * @param parent
  212. * @param dom
  213. * @param isClick
  214. * @private
  215. */
  216. function _addDeNetEditBtn(parent, dom, isClick = false) {
  217. setTimeout(() => {
  218. if (parent && parent.parentNode) {
  219. Report.reportLog({
  220. pageSource: Report.pageSource.mainPage,
  221. businessType: Report.businessType.buttonView,
  222. objectType: Report.objectType.buttonSecond
  223. });
  224. parent.parentNode.insertBefore(dom, parent.nextElementSibling);
  225. } else {
  226. setTimeout(() => {
  227. parent = _getScheduleDom(isClick);
  228. if (parent && parent.parentNode) {
  229. Report.reportLog({
  230. pageSource: Report.pageSource.mainPage,
  231. businessType: Report.businessType.buttonView,
  232. objectType: Report.objectType.buttonSecond
  233. });
  234. let innerDeIcon = document.getElementById('de-btn1');
  235. if (!innerDeIcon) {
  236. parent.parentNode.insertBefore(dom, parent.nextElementSibling);
  237. }
  238. }
  239. }, 1000)
  240. }
  241. })
  242. }
  243. /**
  244. * 在dialog插入deNet按钮
  245. * @private
  246. */
  247. // function _addDeNetBtnToDialog() {
  248. // setTimeout(() => {
  249. // let dialogScheduleBtn = _getScheduleDom(true);
  250. // _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn2);
  251. // }, 800)
  252. // }
  253. /**
  254. * 获取左侧twitter按钮
  255. * @private
  256. */
  257. function _getSliderTwitterBtn() {
  258. dom.tweetBtn = document.querySelector('a[data-testid="SideNav_NewTweet_Button"]');
  259. dom.tweetBtn.addEventListener('click', function () {
  260. // _addDeNetBtnToDialog();
  261. })
  262. }
  263. /**
  264. * 添加deNet按钮
  265. * @private
  266. */
  267. function _addDeNetBtn() {
  268. setTimeout(() => {
  269. let navWidth = document.querySelector('nav[role="navigation"]').offsetWidth;
  270. addSliderNavDeBtn(navWidth < 245);
  271. let innerDeIcon = document.getElementById('de-btn1');
  272. if (!innerDeIcon) {
  273. let dialogScheduleBtn = _getScheduleDom(false);
  274. _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
  275. }
  276. }, 800)
  277. }
  278. /**
  279. * 获取推文输入框内dom,用于插入deNet
  280. * @param isDialogInner
  281. * @returns {Element}
  282. * @private
  283. */
  284. function _getScheduleDom(isDialogInner = false) {
  285. let scheduleBtn;
  286. if (isDialogInner) {
  287. scheduleBtn = document.querySelector('div[role="dialog"]').querySelector('[data-testid="createPollButton"]');
  288. } else {
  289. let toolBar = document.querySelector('div[data-testid="toolBar"]');
  290. if (toolBar) {
  291. scheduleBtn = toolBar.querySelector('div[data-testid="geoButton"]');
  292. }
  293. }
  294. return scheduleBtn;
  295. }
  296. /**
  297. * 插入iframe到页面
  298. * @private
  299. */
  300. function _addIframe() {
  301. // let span = document.createElement('span');
  302. // const shadowRoot = span.attachShadow({mode: 'closed'})
  303. let iframe = document.createElement('iframe');
  304. iframe.src = chrome.runtime.getURL('/iframe/publish.html')
  305. iframe.id = 'iframe-content'
  306. iframe.style.cssText = 'position:fixed;top:0px;right:0;display:block; width:100%;height:100%;z-index:10000; border: medium none;display:none';
  307. // shadowRoot.appendChild(iframe);
  308. // document.body.appendChild(span)
  309. dom.iframe = iframe;
  310. let iframeContent = document.getElementById('iframe-content');
  311. if (!iframeContent) {
  312. let layersDom = document.getElementById('layers');
  313. if (layersDom) {
  314. layersDom.appendChild(iframe);
  315. } else {
  316. document.querySelector('body').appendChild(iframe);
  317. }
  318. }
  319. }
  320. function addPublishTipsIframe(params = {}) {
  321. let { time = 1000 } = params;
  322. setTimeout(() => {
  323. let dialog = document.querySelector('div[role="dialog"]').querySelector('div[role="dialog"]')
  324. if (dialog) {
  325. let right = dialog.offsetLeft - 15 - 266;
  326. let iframe = document.createElement('iframe');
  327. iframe.id = 'de-publish-tips'
  328. iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html');
  329. iframe.style.cssText = `border: medium none; width:270px;height:500px;position: fixed; right: ${right}px; top: 5%;z-index: -1`
  330. let iframeContent = document.getElementById('de-publish-tips');
  331. if (!iframeContent) {
  332. dialog.appendChild(iframe)
  333. }
  334. }
  335. }, time)
  336. }
  337. export function noticeBindTweet(params) {
  338. let iframe = document.createElement('iframe');
  339. iframe.id = 'de-notice-bind-tweet';
  340. iframe.src = chrome.runtime.getURL('/iframe/bind-tweet.html') + `?params=${JSON.stringify(params)}`;
  341. iframe.style.cssText = `border: medium none; width:400px;min-height:313px;position: fixed; right: 16px; top: 16px;`
  342. let iframeContent = document.getElementById('de-notice-bind-tweet');
  343. if (!iframeContent) {
  344. document.querySelector('body').appendChild(iframe)
  345. }
  346. }
  347. export function hideNoticeBindTweet() {
  348. let iframeContent = document.getElementById('de-notice-bind-tweet');
  349. if (iframeContent) {
  350. document.querySelector('body').removeChild(iframeContent)
  351. }
  352. }
  353. /**
  354. * 点击deNet按钮处理
  355. * @private
  356. */
  357. function _deNetBtnClick() {
  358. getUserInfo((res) => {
  359. if (res) {
  360. if (window.location.pathname != '/home') {
  361. if (!dom.homeBtn) {
  362. dom.homeBtn = document.querySelector('a[data-testid="AppTabBar_Home_Link"]');
  363. }
  364. dom.homeBtn.click();
  365. }
  366. showGiveDialogHandler(res);
  367. } else {
  368. let loadIcon = document.getElementById('de-btn-loading');
  369. if (loadIcon) {
  370. return;
  371. }
  372. dom.deBtn.insertBefore(dom.loadingImg, dom.deBtn.querySelector('span'));
  373. setTimeout(() => {
  374. dom.loadingImg.style.transform = 'rotate(1080deg)'
  375. });
  376. setTimeout(() => {
  377. dom.loadingImg.style.transform = 'rotate(0deg)'
  378. dom.deBtn.innerHTML = '<span>DeNet<span>';
  379. }, 2000)
  380. chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_LOGIN", data: '1' }, (res) => { console.log(res) })
  381. }
  382. })
  383. }
  384. /**
  385. * 设置发布内容
  386. * @param content
  387. * @private
  388. */
  389. let isSetContent = false;
  390. const _setPublishContent = throttle(function (content) {
  391. if (!isSetContent) {
  392. isSetContent = true;
  393. let inputEle = document.querySelector('div[contenteditable="true"]');
  394. if (inputEle) {
  395. inputEle.focus();
  396. }
  397. setTimeout(() => {
  398. document.execCommand("insertText", false, content);
  399. setTimeout(() => {
  400. isSetContent = false;
  401. }, 2000)
  402. }, 1000);
  403. }
  404. }, 800);
  405. /**
  406. * 创建deNet按钮 添加到页面
  407. * @returns {{deBtn2: HTMLDivElement, deBtn1: HTMLDivElement, deBtn: HTMLSpanElement}}
  408. * @private
  409. */
  410. function _createBtnDom() {
  411. let loadingImg = document.createElement('img');
  412. loadingImg.id = 'de-btn-loading'
  413. loadingImg.src = require("@/assets/img/icon-btn-loading.png");
  414. loadingImg.style.cssText = 'width:20px;height: 20px;margin-right:3px;transition-duration: 3s;';
  415. let style = document.createElement('style');
  416. style.innerHTML = "#de-btn:hover{opacity: .9;};@-webkit-keyframes load{from{ transform: rotate(0deg);} to{transform: rotate(360deg);}}";
  417. document.getElementsByTagName('head').item(0).appendChild(style);
  418. // 左侧大屏按钮
  419. let deBtn = document.createElement('span');
  420. // const shadowDiv = document.createElement('div');
  421. deBtn.innerHTML = '<span>DeNet</span>';
  422. deBtn.id = 'de-btn';
  423. 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;';
  424. // 编辑框内按钮
  425. const deBtn1 = document.createElement('img');
  426. let src = require("@/assets/img/icon-gift-pack.png");
  427. const smallDeBtnStyle = 'width:20px;height: 20px;cursor: pointer;padding: 0px 8px';
  428. deBtn1.id = 'de-btn1';
  429. deBtn1.style.cssText = smallDeBtnStyle;
  430. deBtn1.src = src
  431. const deBtn2 = document.createElement('div');
  432. deBtn2.id = 'de-btn2';
  433. deBtn2.style.cssText = smallDeBtnStyle;
  434. deBtn2.src = "@/assets/img/icon-gift-pack.png"
  435. // 小屏按钮
  436. const deBtn3 = document.createElement('img');
  437. deBtn3.id = 'de-btn3'
  438. deBtn3.src = require("@/assets/logo/128.png");
  439. deBtn3.style.cssText = 'width:52px;height: 52px;margin-top:20px;cursor: pointer;';
  440. deBtn.addEventListener('click', () => {
  441. // chrome.runtime.sendMessage({
  442. // actionType: 'CONTENT_SET_BADGE',
  443. // data: {
  444. // text: '2'
  445. // }
  446. // }, res => {
  447. // console.log(res);
  448. // })
  449. Report.reportLog({
  450. pageSource: Report.pageSource.mainPage,
  451. businessType: Report.businessType.buttonClick,
  452. objectType: Report.objectType.buttonMain
  453. });
  454. _deNetBtnClick();
  455. })
  456. deBtn1.addEventListener('click', () => {
  457. Report.reportLog({
  458. pageSource: Report.pageSource.mainPage,
  459. businessType: Report.businessType.buttonClick,
  460. objectType: Report.objectType.buttonSecond
  461. });
  462. _deNetBtnClick();
  463. })
  464. deBtn2.addEventListener('click', () => {
  465. _deNetBtnClick();
  466. })
  467. deBtn3.addEventListener('click', () => {
  468. Report.reportLog({
  469. pageSource: Report.pageSource.mainPage,
  470. businessType: Report.businessType.buttonClick,
  471. objectType: Report.objectType.buttonMain
  472. });
  473. _deNetBtnClick();
  474. })
  475. dom.deBtn = deBtn;
  476. dom.deBtn1 = deBtn1;
  477. dom.deBtn2 = deBtn2;
  478. dom.deBtn3 = deBtn3;
  479. dom.loadingImg = loadingImg;
  480. }
  481. function addSliderNavDeBtn(isSmall = false) {
  482. if (!isSmall) {
  483. let bigDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
  484. let deBtn = document.getElementById('de-btn');
  485. if (bigDom && !deBtn) {
  486. bigDom.appendChild(dom.deBtn);
  487. Report.reportLog({
  488. pageSource: Report.pageSource.mainPage,
  489. businessType: Report.businessType.buttonView,
  490. objectType: Report.objectType.buttonMain
  491. });
  492. }
  493. } else {
  494. let smallDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
  495. let deBtn3 = document.getElementById('de-btn3');
  496. if (smallDom && !deBtn3) {
  497. smallDom.appendChild(dom.deBtn3);
  498. Report.reportLog({
  499. pageSource: Report.pageSource.mainPage,
  500. businessType: Report.businessType.buttonView,
  501. objectType: Report.objectType.buttonMain
  502. });
  503. }
  504. }
  505. }
  506. function onWindowResize() {
  507. window.onresize = throttle(function () {
  508. try {
  509. if (tweetPublishStore.showPublishDialog) {
  510. let dialog = document.querySelector('div[role="dialog"]');
  511. let dePublishTips = document.getElementById('de-publish-tips');
  512. if (dialog && !dePublishTips) {
  513. addPublishTipsIframe({ time: 0 });
  514. } else if (dialog && dePublishTips) {
  515. let dialogContent = dialog.querySelector('div[role=dialog]')
  516. if (dialogContent) {
  517. let right = dialogContent.offsetLeft - 15 - 266;
  518. dePublishTips.style.right = right + 'px';
  519. }
  520. }
  521. }
  522. if (window.innerWidth < 1273) {
  523. let bigBtn = document.querySelector('#de-btn');
  524. bigBtn && bigBtn.remove();
  525. setTimeout(() => {
  526. addSliderNavDeBtn(true);
  527. })
  528. } else {
  529. let smallBtn = document.querySelector('#de-btn3');
  530. smallBtn && smallBtn.remove();
  531. setTimeout(() => {
  532. addSliderNavDeBtn()
  533. })
  534. }
  535. } catch (e) {
  536. console.log(e)
  537. }
  538. }, 800)
  539. }
  540. function checkHasDeBtn() {
  541. try {
  542. let toolBar = document.querySelector('div[data-testid="toolBar"]');
  543. let innerDeIcon = document.getElementById('de-btn1');
  544. if (toolBar && !innerDeIcon) {
  545. let dialogScheduleBtn = _getScheduleDom(false);
  546. _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
  547. }
  548. } catch (e) {
  549. console.log(e)
  550. }
  551. }
  552. /**
  553. * 点击发推,后端绑定推特id
  554. */
  555. function bindTwitterArtMethod() {
  556. if (!bindTwitterArt.postId) {
  557. return
  558. }
  559. if (bindTwitterArt.needBind && !bindTwitterArt.isBindIng) {
  560. bindTwitterArt.isBindIng = true;
  561. reportSrcPublishEvent({
  562. params: {
  563. postId: bindTwitterArt.postId,
  564. }
  565. }).then((res) => {
  566. if (res.code == 0) {
  567. Report.reportLog({
  568. objectType: Report.objectType.tweetPostBinded
  569. });
  570. bindTwitterArt.needBind = false;
  571. bindTwitterArt.postId = '';
  572. bindTwitterArt.isBindIng = false;
  573. }
  574. })
  575. }
  576. }
  577. import parseCard from './ParseCard'
  578. // 检测dom改变
  579. // 获取短链接
  580. // 查看本地是否有postid
  581. // 如果有 修改dom 返回
  582. // 如果没有 网络请求
  583. // 获取postid
  584. // 获取twitterid
  585. // 检测当前所有dom 如果没有
  586. let queue_num = 1
  587. export const changeQueueNum = (num = 0) => {
  588. queue_num = queue_num + num
  589. if (queue_num > 5) {
  590. queue_num = 5
  591. }
  592. }
  593. let main_observer = null
  594. function onChangePageMain(targetNode) {
  595. try {
  596. const config = { attributes: false, childList: true, subtree: true };
  597. const callback = (mutationsList, observer) => {
  598. changeQueueNum(1)
  599. }
  600. main_observer = new MutationObserver(callback);
  601. main_observer.observe(targetNode, config);
  602. } catch (error) {
  603. main_observer = null
  604. }
  605. }
  606. // 1.监听main改变
  607. // 2.监听卡片是否可见
  608. // 3.如果可见了 去找
  609. function setIframeRedPacket(type = 'twitter') {
  610. // 获取所有卡片参数
  611. let card_json_data
  612. switch (type) {
  613. case 'facebook':
  614. card_json_data = parseCard.parseFacebookCardParmas()
  615. for (let i in card_json_data) {
  616. parseCard.replaceFacebookPacket(card_json_data[i])
  617. }
  618. break;
  619. default:
  620. card_json_data = parseCard.parseAllDeNetCardParmas()
  621. // 过滤出可以请求的短链接
  622. parseCard.getCardParmas(card_json_data).then((res) => {
  623. for (let i in res.has_post_Id_card_data) {
  624. parseCard.replaceDOMRedPacket(res.has_post_Id_card_data[i])
  625. }
  626. if (res.need_net_short_url.length > 0) {
  627. // 请求短链接
  628. chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_SHORT_LINK", data: "", arr_url: res.need_net_short_url }, () => { })
  629. }
  630. })
  631. break;
  632. }
  633. }
  634. // 监听点击发推 按钮绑定事件
  635. // document.addEventListener('click', (e) => {
  636. // try {
  637. // if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == 'tweetButton') {
  638. // bindTwitterArtMethod()
  639. // } else if (e.target.closest('div[data-testid=tweetButton]')) {
  640. // bindTwitterArtMethod()
  641. // }
  642. // } catch (error) {
  643. // console.error('error', error)
  644. // }
  645. // })
  646. export function initExecuteScript(changes) {
  647. if (changes.executeScript) {
  648. let item = JSON.parse(changes.executeScript.newValue)
  649. if (item.executeScript) {
  650. init()
  651. }
  652. }
  653. }
  654. const createIframe = ({ url, tweet_Id }, callback) => {
  655. let iframe = document.createElement('iframe')
  656. iframe.id = `tweetId${tweet_Id}`
  657. iframe.src = url
  658. iframe.onload = () => {
  659. callback()
  660. }
  661. }
  662. function initParseCard() {
  663. let timer = setInterval(() => {
  664. let inTwitter = window.location.href.includes('twitter.com');
  665. let inTwitterNode = document.querySelector('main');
  666. let inFacebook = window.location.href.includes('facebook.com');
  667. let inFacebookNode = document.querySelector('#facebook');
  668. if (inTwitter && inTwitterNode) {
  669. clearInterval(timer)
  670. setInterval(() => {
  671. if (!main_observer) {
  672. onChangePageMain(inTwitterNode)
  673. changeQueueNum(1)
  674. }
  675. if (queue_num <= 0) {
  676. return
  677. }
  678. setIframeRedPacket()
  679. checkHasDeBtn()
  680. checkHasSliderDeBtn();
  681. changeQueueNum(-1)
  682. showNFTCard()
  683. }, 1000)
  684. } else if (inFacebook && inFacebookNode) {
  685. clearInterval(timer)
  686. setInterval(() => {
  687. if (!main_observer) {
  688. onChangePageMain(inFacebookNode)
  689. changeQueueNum(1)
  690. }
  691. if (queue_num <= 0) {
  692. return
  693. }
  694. setIframeRedPacket('facebook')
  695. changeQueueNum(-1)
  696. }, 1000)
  697. }
  698. }, 1000);
  699. }
  700. let inited = false
  701. // 初始化
  702. export function init() {
  703. if(inited){
  704. return
  705. }
  706. inited = true
  707. console.log('init')
  708. getDiscordAuthCode();
  709. let where = window.location.href.indexOf('twitter.com') < 0 && window.location.href.indexOf('facebook.com') < 0;
  710. if (where) {
  711. return
  712. }
  713. twitterPinLogin();
  714. // 渲染dom
  715. initParseCard()
  716. showNFTCard()
  717. renderDom();
  718. checkTwitterTaskState();
  719. getChromeStorage("popupShowPublishDialog", (res) => {
  720. console.log("popupShowPublishDialog", res);
  721. if (res && res.show) {
  722. setTimeout(() => {
  723. showTwitterPublishDialogHandler({
  724. srcContent: res.srcContent,
  725. postId: res.postId,
  726. copyContent: res.copyContent || ''
  727. });
  728. }, 1500);
  729. chrome.storage.local.remove("popupShowPublishDialog");
  730. }
  731. });
  732. getChromeStorage("userSettings", (res) => {
  733. setTimeout(() => {
  734. addPinedPop();
  735. if (res && !res.isOnToolbar) {
  736. setTimeout(() => {
  737. showPinTips();
  738. chrome.storage.local.remove("userSettings");
  739. }, 800);
  740. }
  741. }, 800);
  742. });
  743. }
  744. function checkHasSliderDeBtn() {
  745. let deBtn = document.getElementById('de-btn');
  746. let deBtn3 = document.getElementById('de-btn3');
  747. if (!deBtn && !deBtn3) {
  748. addSliderNavDeBtn();
  749. }
  750. }
  751. export function facebookReplyTweet(params) {
  752. if (window.location.origin.indexOf('twitter.com')) {
  753. const urlParams = new URLSearchParams(window.location.search);
  754. const actionType = urlParams.get('actionType');
  755. let deReplyParams = urlParams.get('deReplyParams') || '{}';
  756. deReplyParams = JSON.parse(deReplyParams);
  757. if (actionType == 'denetFacebookToTwitterReply') {
  758. if (params.postId == deReplyParams.postId) {
  759. let iframe = document.getElementById(params.postId);
  760. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_FACEBOOK_REPLY', data: deReplyParams }, '*');
  761. }
  762. }
  763. }
  764. }
  765. export function replyHandle(params) {
  766. let iframe = window.parent.document.getElementById(params.postId);
  767. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  768. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  769. if (replyBtn) {
  770. replyBtn.click();
  771. }
  772. onReplyDialogOpen(params, iframe);
  773. // 详情页推文底部评论处理
  774. let pathNameArr = window.location.pathname.split('/');
  775. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  776. let tweetReply = document.querySelector('div[data-testid="tweetButtonInline"]');
  777. if (tweetReply) {
  778. tweetReply.addEventListener('click', function () {
  779. let eleList = tweetReply.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('span[data-text="true"]');
  780. reportReplyResult(eleList, params, () => {
  781. // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
  782. chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
  783. });
  784. })
  785. }
  786. }
  787. }
  788. export function onTweetReplyClick(params) {
  789. let iframe = window.parent.document.getElementById(params.postId);
  790. let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
  791. iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
  792. if (replyBtn) {
  793. replyBtn.addEventListener('click', () => {
  794. onReplyDialogOpen(params, iframe);
  795. })
  796. }
  797. }
  798. function onReplyDialogOpen(params, iframe) {
  799. setTimeout(() => {
  800. let dialog = document.querySelector('div[role="dialog"]');
  801. let replyBtn;
  802. if (dialog) {
  803. let dialogContent = dialog.querySelector('div[role="dialog"]');
  804. replyBtn = dialog.querySelector('div[data-testid="toolBar"]').querySelector('div[data-testid="tweetButton"]');
  805. if (dialogContent) {
  806. let width = dialogContent.offsetWidth;
  807. let ele = document.createElement('div');
  808. ele.innerText = 'Tag 3 friends to complete the task';
  809. ele.style.cssText = `width: ${width}px; height: 38px; color: #fff; font-weight: 600;
  810. font-size: 16px; display: flex; align-items: center; justify-content: center; background: #1D9BF0;
  811. opacity: 0.8; position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1000`;
  812. dialogContent.style.top = '80px';
  813. dialogContent.parentNode.appendChild(ele);
  814. }
  815. } else {
  816. dialog = document.querySelector('main[role="main"]');
  817. if (dialog) {
  818. replyBtn = dialog.querySelector('div[data-testid="tweetButton"]');
  819. }
  820. }
  821. if (dialog && replyBtn) {
  822. replyBtn.addEventListener('click', function () {
  823. let eleList = dialog.querySelector('div[contenteditable="true"]').querySelectorAll('span[data-text="true"]');
  824. reportReplyResult(eleList, params, () => {
  825. // 上報完成
  826. // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
  827. chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
  828. })
  829. });
  830. }
  831. }, 1000);
  832. }
  833. const reportReplyResult = throttle(function (eleList, params, cb) {
  834. if (eleList && eleList.length) {
  835. let atList = [];
  836. for (let i = 0; i < eleList.length; i++) {
  837. let item = eleList[i];
  838. // 是否有中文
  839. let reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
  840. if (item && item.innerText.startsWith('@') && !reg.test(item.innerText)) {
  841. atList.push(item.innerText);
  842. }
  843. }
  844. atList = Array.from(new Set(atList));
  845. if (atList.length >= 3) {
  846. fetchAddFinishEvent({
  847. eventType: params.type,
  848. luckdropId: params.taskLuckdropId
  849. }).then(res => {
  850. if (res.code == 0) {
  851. cb && cb();
  852. }
  853. })
  854. }
  855. }
  856. }, 800);
  857. // 根据推特id找到dom,完成任务
  858. export function findTweetByIdDoTask({ tweet_Id = '', follow_names = [] }, task_type = 'like') {
  859. // 1.根据推特ID寻找推文,获取卡片
  860. // 获取所有卡片参数
  861. let card_json_data = parseCard.parseAllDeNetCardParmas()
  862. let result = card_json_data.filter((item) => { return item.tweet_Id == tweet_Id }) || []
  863. if (result.length < 1) {
  864. return
  865. }
  866. result = result[0]
  867. switch (task_type) {
  868. case 'like':
  869. // https://twitter.com/intent/retweet?tweet_id=1525900221628223491
  870. if (result.dom_card) {
  871. result.dom_card.querySelector('div[data-testid=like]').click()
  872. result.dom_card.querySelector('iframe').contentWindow.postMessage({ actionType: 'CONTENT_DONE_TASK', task_type, }, '*');
  873. }
  874. break;
  875. case 'retweet':
  876. if (result.dom_card) {
  877. result.dom_card.querySelector('div[data-testid=retweet]').click()
  878. result.dom_card.querySelector('div[data-testid=retweetConfirm]').click()
  879. }
  880. break
  881. case 'follow':
  882. follow_names.forEach((item) => {
  883. window.open(`https://twitter.com/intent/follow?screen_name=${item}&tweet_Id=${tweet_Id}`)
  884. })
  885. break
  886. }
  887. }
  888. function clickByDataTestId(e, id, callback) {
  889. if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == id) {
  890. callback()
  891. } else if (e.target.closest('div[data-testid=' + id + ']')) {
  892. callback()
  893. }
  894. }
  895. // 校验关注推特状态
  896. export function checkTwitterTaskState() {
  897. let task_type = ''
  898. let url = window.location.href
  899. let tweet_Id
  900. let task_data = {
  901. follow_name: ''
  902. }
  903. // 校验当前链接
  904. if (url.includes('https://twitter.com/intent/retweet')) {
  905. task_type = 'retweet'
  906. } else if (url.includes('https://twitter.com/intent/follow')) {
  907. task_type = 'follow'
  908. task_data.follow_name = getQueryString('screen_name')
  909. } else if (url.includes('https://twitter.com/intent/like')) {
  910. task_type = 'like'
  911. } else {
  912. return
  913. }
  914. tweet_Id = getQueryString('tweet_id')
  915. // let root_status
  916. document.body.addEventListener('click', (e) => {
  917. // 点击 确认
  918. clickByDataTestId(e, 'confirmationSheetConfirm', () => {
  919. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  920. })
  921. // 点击取消
  922. clickByDataTestId(e, 'confirmationSheetCancel', () => {
  923. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  924. })
  925. // 点击 蒙层
  926. if (e.target && e.target.nextSibling && e.target.nextSibling.dataset && e.target.nextSibling.dataset.testid == 'confirmationSheetDialog') {
  927. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
  928. }
  929. }, true)
  930. let timer = setInterval(() => {
  931. // 喜欢
  932. if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
  933. clearInterval(timer)
  934. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  935. }
  936. // 转推
  937. if (document.querySelector('div[data-testid=unretweet]') && task_type == 'retweet') {
  938. clearInterval(timer)
  939. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  940. }
  941. // 关注
  942. if (task_type == 'follow') {
  943. let follow_area = document.querySelector('div[data-testid=placementTracking]')
  944. if (follow_area && follow_area.querySelectorAll('div')) {
  945. follow_area = follow_area.querySelectorAll('div')
  946. clearInterval(timer)
  947. for (let i in follow_area) {
  948. if (follow_area[i] && follow_area[i].dataset && follow_area[i].dataset.testid && follow_area[i].dataset.testid.indexOf('unfollow') > 0) {
  949. chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
  950. break
  951. }
  952. }
  953. }
  954. }
  955. }, 1000)
  956. }
  957. export function getTweetAuthorByDom(params) {
  958. let iframe = document.getElementById(params.postId);
  959. if (!iframe) {
  960. return;
  961. }
  962. let fullNameDom;
  963. let pathNameArr = window.location.pathname.split('/');
  964. if (pathNameArr.length >= 2 && pathNameArr[pathNameArr.length - 2] == 'status') {
  965. fullNameDom = iframe.parentNode.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  966. } else {
  967. fullNameDom = iframe.parentNode.parentNode.parentNode.querySelector('a[role=link]');
  968. }
  969. if (fullNameDom) {
  970. let arr = fullNameDom.href.split('/');
  971. if (arr.length) {
  972. let fullName = arr[arr.length - 1];
  973. if (fullName) {
  974. iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_GET_TWEET_AUTHOR', data: { fullName } }, '*');
  975. }
  976. }
  977. }
  978. }
  979. export function doTaskTwitterAPI({ task_data, task_type }) {
  980. switch (task_type) {
  981. case 'like':
  982. TwitterLikeAPI(task_data.tweet_Id)
  983. break
  984. case 'retweet':
  985. TwitterRetweetAPI(task_data.tweet_Id)
  986. break
  987. case 'follow':
  988. task_data.follow_data.forEach((item) => {
  989. if (item.name && item.twitterUserId) {
  990. TwitterFollowAPI(item, task_data.tweet_Id)
  991. }
  992. })
  993. break
  994. }
  995. }
  996. const TwitterFollowAPI = (item, tweet_Id) => {
  997. fetch("https://twitter.com/i/api/1.1/friendships/create.json", {
  998. "headers": {
  999. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1000. "content-type": "application/x-www-form-urlencoded",
  1001. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1002. "sec-ch-ua-mobile": "?0",
  1003. "sec-ch-ua-platform": "\"macOS\"",
  1004. "x-csrf-token": getCookie('ct0'),
  1005. "x-twitter-active-user": "yes",
  1006. "x-twitter-auth-type": "OAuth2Session",
  1007. "x-twitter-client-language": "zh-cn"
  1008. },
  1009. "referrer": "https://twitter.com/home",
  1010. "referrerPolicy": "strict-origin-when-cross-origin",
  1011. "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 + "",
  1012. "method": "POST",
  1013. "mode": "cors",
  1014. "credentials": "include"
  1015. }).then(() => {
  1016. let task_data = {
  1017. follow_name: item.name
  1018. }
  1019. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: true }, () => { })
  1020. }).catch(() => {
  1021. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: false }, () => { })
  1022. })
  1023. }
  1024. const TwitterRetweetAPI = (tweet_Id) => {
  1025. fetch("https://twitter.com/i/api/graphql/ojPdsZsimiJrUGLR1sjUtA/CreateRetweet", {
  1026. "headers": {
  1027. "accept": "*/*",
  1028. "accept-language": "zh,en;q=0.9,zh-CN;q=0.8",
  1029. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1030. "content-type": "application/json",
  1031. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
  1032. "sec-ch-ua-mobile": "?0",
  1033. "sec-ch-ua-platform": "\"macOS\"",
  1034. "sec-fetch-dest": "empty",
  1035. "sec-fetch-mode": "cors",
  1036. "sec-fetch-site": "same-origin",
  1037. "x-csrf-token": getCookie('ct0'),
  1038. "x-twitter-active-user": "yes",
  1039. "x-twitter-auth-type": "OAuth2Session",
  1040. "x-twitter-client-language": "zh-cn"
  1041. },
  1042. "referrer": "https://twitter.com/home",
  1043. "referrerPolicy": "strict-origin-when-cross-origin",
  1044. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\",\"dark_request\":false},\"queryId\":\"ojPdsZsimiJrUGLR1sjUtA\"}",
  1045. "method": "POST",
  1046. "mode": "cors",
  1047. "credentials": "include"
  1048. }).then(() => {
  1049. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true }, () => { })
  1050. }).catch(() => {
  1051. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: false }, () => { })
  1052. })
  1053. }
  1054. const TwitterLikeAPI = (tweet_Id) => {
  1055. fetch("https://twitter.com/i/api/graphql/lI07N6Otwv1PhnEgXILM7A/FavoriteTweet", {
  1056. "headers": {
  1057. "accept": "*/*",
  1058. "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
  1059. "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
  1060. "content-type": "application/json",
  1061. "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
  1062. "sec-ch-ua-mobile": "?0",
  1063. "sec-ch-ua-platform": "\"Windows\"",
  1064. "sec-fetch-dest": "empty",
  1065. "sec-fetch-mode": "cors",
  1066. "sec-fetch-site": "same-origin",
  1067. "x-csrf-token": getCookie('ct0'),
  1068. "x-twitter-active-user": "yes",
  1069. "x-twitter-auth-type": "OAuth2Session",
  1070. "x-twitter-client-language": "en"
  1071. },
  1072. "referrer": "https://twitter.com/home",
  1073. "referrerPolicy": "strict-origin-when-cross-origin",
  1074. "body": "{\"variables\":{\"tweet_id\":\"" + tweet_Id + "\"},\"queryId\":\"lI07N6Otwv1PhnEgXILM7A\"}",
  1075. "method": "POST",
  1076. "mode": "cors",
  1077. "credentials": "include"
  1078. }).then(() => {
  1079. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true }, () => { })
  1080. }).catch(() => {
  1081. chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false }, () => { })
  1082. })
  1083. }
  1084. export const showNFTCard = () => {
  1085. let urlInfo = new URL(window.location.href)
  1086. let isTwitter = urlInfo.hostname === 'twitter.com'
  1087. let userElem = document.querySelector('div[data-testid="UserName"]');
  1088. let sideElem = document.querySelector('div[data-testid="sidebarColumn"]')
  1089. let tabIndex = sideElem && sideElem.querySelector('div[tabindex="0"]');
  1090. let isAppend = document.querySelector('div[id="de-nft-node"]');
  1091. let where = isTwitter && userElem && tabIndex;
  1092. if (where) {
  1093. let iframe = document.createElement('iframe');
  1094. iframe.src = chrome.runtime.getURL(`/iframe/nft-card.html?pathname=${encodeURIComponent(urlInfo.pathname)}`)
  1095. iframe.style.cssText = 'border:medium none; width:100%; height:297px;';
  1096. let nftElement = document.createElement('div');
  1097. nftElement.id = 'de-nft-node';
  1098. nftElement.innerHTML = `
  1099. ${iframe.outerHTML}
  1100. <style>
  1101. #de-nft-node {height:297px; margin-bottom:17px; display:none;}
  1102. </style>
  1103. `;
  1104. if (tabIndex && tabIndex.firstChild && tabIndex.firstChild.childNodes && !isAppend) {
  1105. tabIndex.firstChild.insertBefore(nftElement, tabIndex.firstChild.childNodes[2]);
  1106. }
  1107. }
  1108. }
  1109. export const showNFTSale = () => {
  1110. document.querySelector('div[id="de-nft-node"]').style.display = 'block';
  1111. }