Quellcode durchsuchen

Merge branch 'feature-get-red-packet-2022.3.29' into test

zhangwei vor 3 Jahren
Ursprung
Commit
493c29b52a

+ 4 - 0
src/assets/svg/icon-dollar.svg

@@ -0,0 +1,4 @@
+<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect width="40" height="40" rx="20" fill="#FFB443"/>
+<path d="M20.9762 30.8195V29.0664C24.9871 28.7477 27.2848 26.6891 27.2848 23.382C27.2848 20.5797 25.6379 18.8797 22.291 18.0828L20.9762 17.8039V12.2922C22.5965 12.5047 23.7254 13.6203 23.7652 15.0281H26.9395C26.873 12.0398 24.5621 9.90156 20.9762 9.58281V7.75H19.1434V9.58281C15.3848 9.91484 13.127 11.9602 13.127 15.0945C13.127 17.7508 14.8004 19.557 17.8684 20.3008L19.1434 20.6195V26.4234C17.2707 26.2109 16.0621 25.1352 15.9426 23.6211H12.702C12.7152 26.7555 15.1855 28.8406 19.1434 29.093V30.8195H20.9762ZM24.0574 23.7273C24.0574 25.3211 22.9285 26.3305 20.9762 26.45V20.9648C23.0879 21.3898 24.0574 22.2664 24.0574 23.7273ZM16.3941 14.8289C16.3941 13.4211 17.5496 12.3719 19.1434 12.2789V17.4187C17.3504 17.0469 16.3941 16.157 16.3941 14.8289Z" fill="white"/>
+</svg>

Datei-Diff unterdrückt, da er zu groß ist
+ 6 - 0
src/assets/svg/icon-follow.svg


Datei-Diff unterdrückt, da er zu groß ist
+ 6 - 0
src/assets/svg/icon-king-hat.svg


+ 4 - 0
src/assets/svg/icon-like.svg

@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect width="24" height="24" rx="12" fill="white"/>
+<path d="M17.1868 6.62632L17.1868 6.62636L17.1944 6.63034C19.5242 7.85072 19.8338 10.6959 18.3253 12.3239L17.6735 12.9757L14.4987 16.1505L12.3822 18.267C12.2295 18.4197 12.1141 18.4442 12.0527 18.4442C11.9913 18.4442 11.8759 18.4197 11.7232 18.267L9.60666 16.1505L6.43189 12.9757L5.77048 12.3143C4.14695 10.6908 4.44662 7.8568 6.7723 6.63369C8.04636 6.00053 9.81466 6.30985 10.9271 7.42227L11.4562 7.9514L11.9865 8.48173L12.5169 7.9514L13.046 7.42227C14.1886 6.2797 15.8208 5.89078 17.1868 6.62632Z" fill="#389AFF" fill-opacity="0.01" stroke="#51A7FF" stroke-width="1.5"/>
+</svg>

+ 4 - 0
src/assets/svg/icon-retweet.svg

@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect width="24" height="24" rx="12" fill="white"/>
+<path d="M7.14903 6.09573C6.95472 5.90142 6.63969 5.90142 6.44538 6.09573L4.1285 8.41261C3.8905 8.65061 3.8905 9.03649 4.1285 9.27449C4.3665 9.51249 4.75238 9.51249 4.99038 9.27449L6.18776 8.07711V14.6617C6.18776 16.2342 7.4625 17.5089 9.03497 17.5089H12.6154C12.952 17.5089 13.2248 17.2361 13.2248 16.8995C13.2248 16.5629 12.952 16.2901 12.6154 16.2901H9.03497C8.13567 16.2901 7.40664 15.561 7.40664 14.6617V8.07711L8.60403 9.27449C8.84203 9.51249 9.2279 9.51249 9.4659 9.27449C9.70391 9.03649 9.70391 8.65061 9.4659 8.41261L7.14903 6.09573ZM16.851 17.5214C17.0453 17.7157 17.3603 17.7157 17.5546 17.5214L19.8715 15.2045C20.1095 14.9665 20.1095 14.5806 19.8715 14.3426C19.6335 14.1046 19.2476 14.1046 19.0096 14.3426L17.8122 15.54V8.9554C17.8122 7.38294 16.5375 6.1082 14.965 6.1082H11.3846C11.048 6.1082 10.7752 6.38106 10.7752 6.71764C10.7752 7.05422 11.048 7.32708 11.3846 7.32708H14.965C15.8643 7.32708 16.5934 8.05611 16.5934 8.9554V15.54L15.396 14.3426C15.158 14.1046 14.7721 14.1046 14.5341 14.3426C14.2961 14.5806 14.2961 14.9665 14.5341 15.2045L16.851 17.5214Z" fill="#389AFF" stroke="#389AFF" stroke-width="0.1" stroke-linecap="round"/>
+</svg>

+ 13 - 12
src/entry/content.js

@@ -1,19 +1,22 @@
 var port = chrome.runtime.connect({ name: "hello" });
 
-import { contentTwitterPinLogin, renderDom, showGiveDialogHandler, showIframeHandler, hideIframeHandler,
-	showTwitterPublishDialogHandler } from '../logic/twitter.js'
+import {
+	contentTwitterPinLogin, renderDom, showGiveDialogHandler, showIframeHandler, hideIframeHandler,
+	showTwitterPublishDialogHandler, setIframeRedPacket
+} from '../logic/twitter.js'
 
 port.onMessage.addListener(function (res) {
-    switch (res.state) {
-			case 'BACK_TWITTER_LOGIN_SUCCESS':
-				showGiveDialogHandler();
-				break;
-    }
+	switch (res.state) {
+		case 'BACK_TWITTER_LOGIN_SUCCESS':
+			showGiveDialogHandler();
+			break;
+	}
 })
 
 window.onload = () => {
-    contentTwitterPinLogin(port)
-		renderDom(port);
+	contentTwitterPinLogin(port)
+	renderDom(port);
+	setIframeRedPacket()
 }
 
 window.onmessage = (res) => {
@@ -30,6 +33,4 @@ window.onmessage = (res) => {
 				break;
 		}
 	}
-}
-
-
+}

+ 4 - 0
src/iframe/red-packet.js

@@ -0,0 +1,4 @@
+import { createApp } from 'vue'
+import App from '../view/red-packet.vue'
+
+createApp(App).mount('#app')

+ 37 - 1
src/logic/twitter.js

@@ -39,7 +39,6 @@ export function backTwitterPinLoginCode(code) {
             console.log(tab[i])
             if (tab[i].url == 'https://api.twitter.com/oauth/authorize') {
                 chrome.tabs.remove(tab[i].id)
-                break
             }
         }
     })
@@ -299,3 +298,40 @@ function _createBtnDom (port) {
 		// _addDeNetEditBtn(dialogScheduleBtn, deBtn1);
 	}
 }, 800) */
+
+function parseDOMRedPacket() {
+    let denet_arr = document.querySelector('article[data-testid=tweet]').querySelectorAll('a')
+    let _dom = null
+    for (let i in denet_arr) {
+        if (denet_arr[i].innerText == '#denet') {
+            _dom = denet_arr[i].parentNode.parentNode.parentNode.parentNode.children[1]
+            // 是否有有红包秘文
+        }
+    }
+    console.log(_dom)
+    return _dom
+}
+
+function replaceDOMRedPacket(_dom) {
+    if (!_dom || _dom.querySelector('iframe')) {
+        return
+    }
+    _dom.innerHTML = ''
+    let _iframe = document.createElement('iframe')
+    _iframe.src = chrome.runtime.getURL('/iframe/red-packet.html');
+    _iframe.style.cssText = 'border: medium none; width:375px;height:500px;'
+    _dom.appendChild(_iframe)
+}
+
+
+export function setIframeRedPacket() {
+    // if(window.location.href != 'https://twitter.com/home'){
+    //     return
+    // }
+    document.addEventListener('scroll', () => {
+        // 1.解析推文
+        // 2.替换推文
+        replaceDOMRedPacket(parseDOMRedPacket())
+    })
+}
+

+ 2 - 1
src/manifest.development.json

@@ -28,7 +28,8 @@
     "web_accessible_resources": [
         {
           "resources": [
-            "/iframe/test.html"
+            "/iframe/test.html",
+            "/iframe/red-packet.html"
           ],
           "matches": [
             "<all_urls>"

+ 330 - 0
src/view/red-packet.vue

@@ -0,0 +1,330 @@
+<template>
+  <div class="content">
+    <!-- open -->
+    <div v-if="data.status == 'opened'" class="opened">
+      <div class="header">
+        <div class="title">Awesome! You Will Get</div>
+        <div class="money">
+          <img :src="require('../assets/svg/icon-dollar.svg')" alt />
+          <span class="big">1.23</span>
+          <span class="small">USD</span>
+        </div>
+      </div>
+
+      <div class="list">
+        <div class="item" v-for="item,i in data.list" :key="i">
+          <img :src="item.url" alt />
+          <div class="item-content">
+            <div class="item-title">{{ item.title }}</div>
+            <span>@shasid \!@asd</span>
+          </div>
+          <div class="btn">{{ item.title }}</div>
+        </div>
+      </div>
+      <div class="people">
+        <span>Total $100 USD,173/1000 People Got</span>
+      </div>
+      <div class="footer">
+        <div class="first">
+          <div class="validity">Validity</div>
+          <div class="time">23:57:32</div>
+        </div>
+        <div class="btn">Get Giveaways</div>
+      </div>
+    </div>
+    <!-- success -->
+    <div v-if="data.status == 'success'" class="success">
+      <div class="header">
+        <div class="money">
+          <img :src="require('../assets/svg/icon-dollar.svg')" alt />
+          <span class="big">1.23</span>
+          <span class="small">USD</span>
+        </div>
+      </div>
+
+      <div class="list">
+        <div class="item" v-for="item,i in data.list" :key="i">
+          <img :src="item.url" alt />
+          <div class="item-content">
+            <div class="item-title">{{ item.title }}</div>
+            <span>@shasid \!@asd</span>
+          </div>
+          <div class="btn">{{ item.title }}</div>
+        </div>
+      </div>
+    </div>
+    <!-- no-open -->
+    <div v-if="data.status == 'not-open'" class="not-open">
+      <div class="top">
+        <div class>
+          <img src alt />
+          <span></span>
+        </div>
+        <div></div>
+      </div>
+      <div class="open">OPEN</div>
+      <div class="bottom"></div>
+    </div>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'redPacket',
+}
+</script>
+<script setup>
+import { reactive } from "vue";
+
+
+let data = reactive({
+  status: 'opened',
+  list: [
+    {
+      title: 'Follow',
+      url: require('../assets/svg/icon-follow.svg')
+    },
+    {
+      title: 'Like',
+      url: require('../assets/svg/icon-like.svg')
+    }, {
+      title: 'Retweet',
+      url: require('../assets/svg/icon-retweet.svg')
+    }
+
+  ]
+})
+
+</script>
+ 
+<style scoped lang="scss">
+.content {
+  width: 375px;
+  height: 500px;
+  background: #fafafa;
+  border-radius: 11px;
+  font-family: "SF Pro Display";
+  font-style: normal;
+  .success {
+    filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
+    width: 100%;
+    height: 100%;
+    .header {
+      text-align: center;
+      height: 120px;
+      width: 100%;
+      background: #ef4545;
+      padding-top: 30px;
+
+      .title {
+        color: #fff7e4;
+        opacity: 0.6;
+
+        font-weight: 700;
+        font-size: 18px;
+        line-height: 21px;
+        letter-spacing: -0.3px;
+      }
+       .money {
+        img {
+          width: 40px;
+          height: 40px;
+        }
+        .big {
+          font-weight: 700;
+          font-size: 46px;
+          line-height: 55px;
+          /* identical to box height */
+
+          letter-spacing: 0.3px;
+
+          color: #fff8e6;
+        }
+        .small {
+          font-weight: 700;
+          font-size: 13px;
+          line-height: 16px;
+          /* identical to box height */
+
+          letter-spacing: 0.5px;
+
+          color: #fff8e6;
+        }
+      }
+    }
+  }
+  .opened {
+    filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
+    width: 100%;
+    height: 100%;
+    .header {
+      text-align: center;
+      height: 120px;
+      width: 100%;
+      background: #ef4545;
+      padding-top: 30px;
+      .title {
+        color: #fff7e4;
+        opacity: 0.6;
+
+        font-weight: 700;
+        font-size: 18px;
+        line-height: 21px;
+        letter-spacing: -0.3px;
+      }
+      .money {
+        img {
+          width: 40px;
+          height: 40px;
+        }
+        .big {
+          font-weight: 700;
+          font-size: 46px;
+          line-height: 55px;
+          /* identical to box height */
+
+          letter-spacing: 0.3px;
+
+          color: #fff8e6;
+        }
+        .small {
+          font-weight: 700;
+          font-size: 13px;
+          line-height: 16px;
+          /* identical to box height */
+
+          letter-spacing: 0.5px;
+
+          color: #fff8e6;
+        }
+      }
+    }
+    .list {
+      padding: 0 16px 0 16px;
+      background: #ffffff;
+
+      .item {
+        display: flex;
+        align-items: center;
+        min-height: 50px;
+        border-bottom: 1px solid #f0f0f0;
+        img {
+          width: 24px;
+          height: 24px;
+        }
+        .item-content {
+          flex: 1;
+
+          .item-title {
+            font-weight: 500;
+            font-size: 16px;
+            letter-spacing: 0.3px;
+            color: #000000;
+          }
+          span {
+            font-weight: 400;
+            font-size: 11px;
+            line-height: 13px;
+            letter-spacing: 0.3px;
+
+            color: #000000;
+
+            opacity: 0.4;
+          }
+        }
+        .btn {
+          width: 72px;
+          height: 29px;
+          line-height: 29px;
+          background: #389aff;
+          border-radius: 500px;
+          text-align: center;
+          letter-spacing: 0.3px;
+          color: #ffffff;
+          cursor: pointer;
+        }
+      }
+
+      .item:last-child {
+        border: 0;
+      }
+    }
+    .people {
+      padding-left: 16px;
+      height: 44px;
+      line-height: 44px;
+      background: #faf9f8;
+      box-shadow: 0px 1px 0px #f2f2f2;
+      span {
+        font-weight: 400;
+        font-size: 12px;
+        line-height: 14px;
+        letter-spacing: 0.3px;
+
+        color: #000000;
+
+        opacity: 0.4;
+      }
+    }
+    .footer {
+      background: #ffffff;
+      display: flex;
+      padding: 20px 22px 20px 17px;
+      .first {
+        flex: 1;
+
+        .validity {
+          font-weight: 400;
+          font-size: 12px;
+          line-height: 14px;
+          letter-spacing: 0.3px;
+          color: #000000;
+          opacity: 0.4;
+          margin: 2px 0 8px 0;
+        }
+        .time {
+          font-weight: 500;
+          font-size: 13px;
+          line-height: 16px;
+          /* identical to box height */
+
+          color: #000000;
+        }
+      }
+      .btn {
+        background: #ef4545;
+        border-radius: 100px;
+        color: #fff;
+        width: 258px;
+        height: 52px;
+        font-weight: 600;
+        font-size: 18px;
+        line-height: 52px;
+        text-align: center;
+        cursor: pointer;
+      }
+    }
+  }
+  .not-open {
+    filter: drop-shadow(0px 4px 94px rgba(0, 0, 0, 0.3));
+    .top {
+      width: 375px;
+      height: 292px;
+      background: #ef4545;
+      box-shadow: 0px 4px 44px rgba(0, 0, 0, 0.1);
+    }
+    .open {
+      width: 110px;
+      height: 110px;
+      text-align: center;
+      font-size: 26px;
+      font-weight: 600;
+      background: #ffe9b5;
+      color: #ef4545;
+      cursor: pointer;
+      border-radius: 50%;
+      line-height: 110px;
+    }
+  }
+}
+</style>

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.