cover.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <!-- 封面页 -->
  3. <div class="cover" v-show-log="state.log_show">
  4. <v-head :left-data="state.detail.postUserInfo || null"></v-head>
  5. <div class="waring" v-if="state.cover_status == '奖励已被领光'">
  6. <div>All treasures</div>
  7. <div>are hunted</div>
  8. </div>
  9. <!-- 邀请人 -->
  10. <template v-else>
  11. <div class="invite"
  12. v-if="state.detail.inviteUserInfo && state.detail.inviteUserInfo.nickName != state.detail.postUserInfo.nickName">
  13. <img :src="state.detail.inviteUserInfo.avatarUrl" alt="" />
  14. <span>@{{ state.detail.inviteUserInfo.nickName }} invites you</span>
  15. </div>
  16. <div class="in-invite" v-else></div>
  17. <div class="treasure">
  18. <component-zoom width="335" fontSize="34" style="margin:0 auto;">
  19. <span>Treasure</span>
  20. <span>${{ toLast(state.detail.amountUsdValue, 2) }}</span>
  21. </component-zoom>
  22. </div>
  23. <div class="gain" v-if="Number(state.detail.upGainAmountValue) > 0">
  24. <component-zoom width="335" fontSize="34" style="margin:0 auto;">
  25. <span>Your Gain Up to</span>
  26. <span>$</span>
  27. <span>{{ toLast(state.detail.upGainAmountValue, 3) }}</span>
  28. </component-zoom>
  29. </div>
  30. <div class="coin" v-if="state.detail.currencySymbol != 'USD'">
  31. <img :src="state.detail.currencyIconPath" alt="" />
  32. <span> {{ state.detail.currencySymbol }} equivalent (Crypto)</span>
  33. </div>
  34. <div class="coin" v-else></div>
  35. </template>
  36. <div class="box">
  37. <img :src="require('@/assets/img/icon-gold-close-box.png')" alt="" v-if="state.cover_status == '奖励已被领光'" />
  38. <img :src="require('@/assets/img/icon-treasure-box.png')" alt="" v-else />
  39. </div>
  40. <div class="mark" :style="{ 'opacity': state.cover_status == '奖励已被领光' ? '0' : '1' }">
  41. <img :src="require('@/assets/svg/icon-three-line.svg')" alt="" />
  42. <span>to Hunt Treasure</span>
  43. </div>
  44. <div class="footer">
  45. <v-btn :txt="state.open_btn.txt" :font-size="'17px'" :icon="true" :disabled="false" @onClick="clickBtn"
  46. :loading="state.btn_loading"></v-btn>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { inject } from 'vue'
  52. import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
  53. import VHead from '@/view/iframe/treasure-hunt/components/head.vue'
  54. import ComponentZoom from "@/view/components/component-zoom.vue";
  55. import { pageUrl } from "@/http/configAPI.js"
  56. import Report from "@/log-center/log"
  57. import { prepareStart, treasureStart } from '@/http/treasure.js'
  58. import { getChromeCookie, removeChromeCookie, getChromeStorage, sendChromeTabMessage } from '@/uilts/chromeExtension.js'
  59. import { reSetBindRepost } from '@/http/help.js'
  60. import { guid } from '@/uilts/help.js'
  61. let state = inject('state')
  62. let global_userInfo
  63. state.log_show = {
  64. businessType: Report.businessType.pageView,
  65. pageSource: Report.pageSource.pending_page,
  66. redPacketType: Report.redPacketType.treasure,
  67. shareLinkId: state.invite_code,
  68. postId: state.postId
  69. }
  70. chrome.storage.onChanged.addListener(changes => {
  71. if (changes.userInfo && changes.userInfo.newValue) {
  72. // let item = JSON.parse(changes.userInfo.newValue)
  73. state.btn_loading = false
  74. state.init()
  75. }
  76. })
  77. let to_start_time = new Date().getTime()
  78. let now_time
  79. const toStart = (req) => {
  80. now_time = new Date().getTime()
  81. if (now_time - to_start_time <= 1000) {
  82. return
  83. }
  84. to_start_time = now_time
  85. console.log('to_start_time', to_start_time)
  86. treasureStart({
  87. params: {
  88. postId: state.postId || '',
  89. inviteCode: state.invite_code || '',
  90. frontFollowRelJSON: JSON.stringify(state.usersFollowStatusList),
  91. time: new Date().getTime(),
  92. guid: guid(),
  93. channelCode: state.invite_channel
  94. }
  95. }).then((res) => {
  96. state.usersFollowStatusList = [];
  97. if (res.code == 0) {
  98. state.page = '开奖页'
  99. state.start_task = res.data
  100. state.btn_loading = false
  101. if (req.response) {
  102. let repost_tweetId = req.response.data.data.create_tweet.tweet_results.result.rest_id
  103. reSetBindRepost({
  104. inviteCode: res.data.inviteCode,
  105. tweetId: repost_tweetId
  106. })
  107. }
  108. } else {
  109. state.init()
  110. }
  111. }).catch((error) => {
  112. console.error(error)
  113. })
  114. }
  115. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  116. switch (req.actionType) {
  117. case 'DO_TASK':
  118. if (!req.task_type || state.tweetId != req.tweet_Id || state.iframeId != req.iframeId) {
  119. return
  120. }
  121. console.log('DO_TASK', req)
  122. if (req.task_type == 'createTweet1' && req.task_done == '否') {
  123. console.log('createTweet1', req)
  124. state.toast.txt = 'Seems something went wrong, please try again'
  125. state.toast.show = true
  126. state.toast.has_icon = false
  127. setTimeout(() => {
  128. state.toast.show = false
  129. }, 2000)
  130. } else if (req.task_type == 'createTweet1' && req.task_done == '是') {
  131. console.log('createTweet2', req)
  132. toStart(req);
  133. getChromeStorage('userInfo', (_userInfo) => {
  134. if (_userInfo) {
  135. sendChromeTabMessage({
  136. actionType: "IFRAME_API_GET_TWEET_USER_INFO_REQ",
  137. data: {
  138. screen_name: _userInfo.nickName,
  139. tweetId: state.tweetId,
  140. objectType: Report.objectType.repostSuccess
  141. }
  142. })
  143. }
  144. })
  145. }
  146. break
  147. case 'CONTENT_API_GET_TWEET_USER_INFO_RES':
  148. let twitterFans = 0;
  149. let { user } = req.data || {};
  150. if (user && user.result && user.result.legacy) {
  151. let legacy = user.result.legacy;
  152. twitterFans = legacy ? legacy.followers_count : 0;
  153. }
  154. if (state.tweetId == req.tweetId && req.objectType == Report.objectType.repostSuccess) {
  155. Report.reportLog({
  156. objectType: Report.objectType.repostSuccess,
  157. twitterFans: twitterFans,
  158. redPacketType: Report.redPacketType.treasure,
  159. postId: state.postId,
  160. shareLinkId: state.invite_code,
  161. });
  162. };
  163. break;
  164. case 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES':
  165. if (state.tweetId == req.tweetId && state.iframeId == req.iframeId) {
  166. if (req.type == 'pre_repost') {
  167. // 发送埋点
  168. let list = getFollowStatus(req.data)
  169. log_pre_repost.names.forEach(item => {
  170. list.forEach((item2) => {
  171. if (item.name == item2.name) {
  172. if (item.type == 'invite') {
  173. log_pre_repost.params.isFatherTwitterFans = item2.followed
  174. }
  175. if (item.type == 'post') {
  176. log_pre_repost.params.isRootTwitterFans = item2.followed
  177. }
  178. }
  179. })
  180. })
  181. // 上报埋点
  182. Report.reportLog(Object.assign({
  183. objectType: Report.objectType.preRepost,
  184. }, log_pre_repost.params))
  185. } else {
  186. state.usersFollowStatusList = getFollowStatus(req.data);
  187. // 上报埋点
  188. logPreRepost()
  189. // 做任务
  190. chrome.tabs.getCurrent((tab) => {
  191. // // 一键三连
  192. chrome.tabs.sendMessage(tab.id, {
  193. actionType: "IFRAME_TWITTER_API_DO_TASK",
  194. task_data: {
  195. tweet_Id: state.tweetId,
  196. tweet_text: state.rePostTweetContent
  197. },
  198. task_type: 'tasks',
  199. tasks: state.tasks,
  200. iframeId: state.iframeId
  201. })
  202. // double like
  203. chrome.tabs.sendMessage(tab.id, {
  204. actionType: "IFRAME_TWITTER_API_DO_TASK", task_data: {
  205. tweet_Id: state.detail.srcContentId
  206. }, task_type: 'like',
  207. iframeId: state.iframeId
  208. })
  209. })
  210. }
  211. }
  212. break;
  213. }
  214. })
  215. const getFollowStatus = (arr = []) => {
  216. let list = [];
  217. let userInfoList = arr;
  218. for (let i = 0; i < userInfoList.length; i++) {
  219. let item = userInfoList[i];
  220. if (item.user && item.user.result && item.user.result.legacy) {
  221. let legacy = item.user.result.legacy;
  222. list.push({
  223. name: legacy.screen_name,
  224. followed: legacy.following
  225. })
  226. }
  227. }
  228. return list
  229. }
  230. let log_pre_repost = {
  231. params: {},
  232. names: []
  233. }
  234. const logPreRepost = () => {
  235. log_pre_repost.params = {}
  236. log_pre_repost.names = []
  237. // rootTwitterName 上报原始发布者的name
  238. // fatherTwitterName 上报分享者的name or 原始发布者的name
  239. // isFatherTwitterFans 在原始链接或分享链接 邀请者非自己
  240. // isRootTwitterFans 在原始链接或分享链接 发布者非自己
  241. let params = {}
  242. params.postId = state.postId
  243. if (state.page_type == '邀请链接') {
  244. params.shareLinkId = state.invite_code
  245. params.fatherTwitterName = state.detail.inviteUserInfo.nickName
  246. } else if (state.page_type == '原始链接') {
  247. params.fatherTwitterName = state.detail.postUserInfo.nickName
  248. }
  249. params.rootTwitterName = state.detail.postUserInfo.nickName
  250. let names = []
  251. if (state.detail.inviteUserInfo) {
  252. if (state.detail.inviteUserInfo.uid != global_userInfo.uid) {
  253. // isFatherTwitterFans = inviteUserInfo.nickName 的关注关系
  254. // 发送事件校验关注关系
  255. names.push({
  256. type: 'invite',
  257. name: state.detail.inviteUserInfo.nickName
  258. })
  259. }
  260. } else {
  261. if (state.detail.postUserInfo.uid != global_userInfo.uid) {
  262. names.push({
  263. type: 'invite',
  264. name: state.detail.postUserInfo.nickName
  265. })
  266. }
  267. }
  268. if (state.detail.postUserInfo && (state.detail.postUserInfo.uid != global_userInfo.uid)) {
  269. // isRootTwitterFans = postUserInfo.nickName 的关注关系
  270. // 发送事件校验关注关系
  271. names.push({
  272. type: 'post',
  273. name: state.detail.postUserInfo.nickName
  274. })
  275. }
  276. sendChromeTabMessage({
  277. actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
  278. data: {
  279. userList: names,
  280. tweetId: state.tweetId
  281. },
  282. type: 'pre_repost',
  283. iframeId: state.iframeId
  284. })
  285. log_pre_repost.params = params
  286. log_pre_repost.names = names
  287. }
  288. const toLast = (num, bit) => {
  289. let str = 1
  290. for (let i = 0; i < bit; i++) {
  291. str = str + '0'
  292. }
  293. let _num = Number(str)
  294. return Math.floor(Number(num) * _num) / _num
  295. }
  296. async function clickBtn() {
  297. global_userInfo = await state.checkIsLogin()
  298. if (!global_userInfo || !global_userInfo.uid) {
  299. return
  300. }
  301. if (state.cover_status == '奖励已被领光') {
  302. Report.reportLog({
  303. pageSource: Report.pageSource.pending_page,
  304. businessType: Report.businessType.buttonClick,
  305. objectType: Report.objectType.getMoreGiveaway,
  306. postId: state.postId
  307. });
  308. window.open('https://twitter.com/search?q=%23denet');
  309. return
  310. }
  311. state.btn_loading = true
  312. Report.reportLog({
  313. businessType: Report.businessType.buttonClick,
  314. objectType: Report.objectType.open_button,
  315. pageSource: Report.pageSource.pending_page,
  316. redPacketType: Report.redPacketType.treasure,
  317. shareLinkId: state.invite_code,
  318. postId: state.postId
  319. });
  320. setTimeout(() => {
  321. if (state.btn_loading == true) {
  322. state.btn_loading = false
  323. }
  324. }, 10000)
  325. // 获取邀请码
  326. getChromeCookie({
  327. name: state.postId,
  328. url: pageUrl,
  329. }, (res) => {
  330. if (res && res.inviteCode) {
  331. state.invite_code = res.inviteCode
  332. }
  333. startBtn()
  334. })
  335. }
  336. const startBtn = () => {
  337. // 获取文本
  338. prepareStart({
  339. params: {
  340. postId: state.postId || '',
  341. inviteCode: state.invite_code || ''
  342. }
  343. }).then((res) => {
  344. if (res.code == 0) {
  345. removeChromeCookie({
  346. name: state.postId,
  347. url: pageUrl,
  348. })
  349. state.rePostTweetContent = res.data.rePostTweetContent;
  350. getUsersFollowStatus();
  351. } else {
  352. state.init()
  353. }
  354. })
  355. }
  356. const getUsersFollowStatus = () => {
  357. let userList = state.follows;
  358. if (userList && userList.length) {
  359. sendChromeTabMessage({
  360. actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
  361. data: {
  362. userList: userList,
  363. tweetId: state.tweetId,
  364. },
  365. iframeId: state.iframeId
  366. })
  367. }
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. .cover {
  372. position: relative;
  373. width: 375px;
  374. height: 580px;
  375. background: linear-gradient(179.96deg, #25180D 38.82%, #5E4025 55.4%, #876635 61.6%, #24180C 71.59%);
  376. border-radius: 20px;
  377. .head {
  378. padding: 10px;
  379. display: flex;
  380. align-items: center;
  381. img {
  382. width: 16px;
  383. height: 16px;
  384. border-radius: 100px;
  385. }
  386. span {
  387. color: #B69882;
  388. font-weight: 400;
  389. margin-left: 5px;
  390. font-size: 11px;
  391. flex-grow: 0;
  392. }
  393. }
  394. .waring {
  395. margin-top: 94px;
  396. font-weight: 900;
  397. font-size: 34px;
  398. color: #FFFFFF;
  399. text-align: center;
  400. opacity: 0.7;
  401. margin-bottom: 35px;
  402. }
  403. .in {
  404. height: 58px;
  405. }
  406. .in-invite {
  407. height: 28px;
  408. margin-top: 30px;
  409. margin-bottom: 10px;
  410. }
  411. .invite {
  412. background: rgba(255, 255, 255, 0.1);
  413. height: 28px;
  414. display: flex;
  415. align-items: center;
  416. margin: 0 auto;
  417. margin-top: 20px;
  418. margin-bottom: 10px;
  419. border-radius: 100px;
  420. width: fit-content;
  421. padding-right: 11px;
  422. img {
  423. width: 18px;
  424. height: 18px;
  425. border-radius: 100px;
  426. margin-left: 11px;
  427. margin-right: 6px;
  428. }
  429. span {
  430. color: #BE9F89;
  431. }
  432. }
  433. .treasure {
  434. text-align: center;
  435. height: 37px;
  436. display: flex;
  437. align-items: center;
  438. span {
  439. font-size: 34px;
  440. font-weight: 900;
  441. line-height: 40px;
  442. }
  443. span:first-child {
  444. color: #FFC83A;
  445. margin-right: 10px;
  446. }
  447. span:last-child {
  448. color: #FFFFFF;
  449. }
  450. }
  451. .gain {
  452. width: 100%;
  453. background: #332319;
  454. height: 37px;
  455. margin-top: 10px;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. span {
  460. color: #fff;
  461. font-weight: 500;
  462. font-size: 16px;
  463. line-height: 16px;
  464. }
  465. span:first-child {
  466. font-size: 15px;
  467. line-height: 15px;
  468. margin-right: 10px;
  469. }
  470. span:last-child {
  471. margin-left: 2px;
  472. font-weight: 800;
  473. font-size: 24px;
  474. line-height: 24px;
  475. }
  476. }
  477. .coin {
  478. height: 17px;
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. margin-top: 10px;
  483. img {
  484. width: 17px;
  485. height: 17px;
  486. }
  487. span {
  488. margin-left: 4px;
  489. font-weight: 400;
  490. font-size: 11px;
  491. line-height: 15px;
  492. color: #FFFFFF;
  493. opacity: 0.7;
  494. }
  495. }
  496. .box {
  497. text-align: center;
  498. position: absolute;
  499. width: 100%;
  500. bottom: 155px;
  501. img {
  502. width: 160px;
  503. height: 160px;
  504. }
  505. }
  506. .mark {
  507. position: absolute;
  508. bottom: 84px;
  509. display: flex;
  510. align-items: center;
  511. justify-content: center;
  512. width: 100%;
  513. img {
  514. margin-right: 9px;
  515. }
  516. span {
  517. font-weight: 500;
  518. font-size: 12px;
  519. line-height: 17px;
  520. color: #65C1FF;
  521. }
  522. }
  523. .footer {
  524. width: 100%;
  525. position: absolute;
  526. bottom: 16px;
  527. }
  528. }
  529. </style>