瀏覽代碼

[add][twitter-pin]

zhangwei 3 年之前
父節點
當前提交
164b70c77e
共有 7 個文件被更改,包括 143 次插入15 次删除
  1. 3 0
      package.json
  2. 42 1
      src/entry/background.js
  3. 10 6
      src/entry/content.js
  4. 3 0
      src/manifest.development.json
  5. 57 0
      src/server/twitter.js
  6. 20 7
      src/view/popup.vue
  7. 8 1
      yarn.lock

+ 3 - 0
package.json

@@ -9,6 +9,7 @@
     "build-watch": "vue-cli-service  --env.NODE_ENV=development build-watch --mode development"
   },
   "dependencies": {
+    "axios": "^0.26.1",
     "core-js": "^3.8.3",
     "vue": "^3.2.13"
   },
@@ -20,6 +21,8 @@
     "@vue/cli-service": "~5.0.0",
     "eslint": "^7.32.0",
     "eslint-plugin-vue": "^8.0.3",
+    "node-sass": "^7.0.1",
+    "sass-loader": "^12.6.0",
     "vue-cli-plugin-chrome-extension-cli": "~1.1.2"
   },
   "eslintConfig": {

+ 42 - 1
src/entry/background.js

@@ -1 +1,42 @@
-console.log('hello world background todo something~')
+console.log('hello world background todo something~')
+
+// twitter
+// import { getTtwitterRequestToken,twitterLogin } from '../server/twitter.js'
+
+// getTtwitterRequestToken().then((res)=>{
+//     chrome.tabs.create({
+//         url:`https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
+//     },()=>{
+
+//     })
+// })
+
+// chrome.tabs.onUpdated.addListener((tabId,changeInfo,tab)=>{
+//     // console.log()
+//     if(tab.url == 'https://api.twitter.com/oauth/authorize'){
+
+//     }
+// })
+
+// chrome.tabs.getAllInWindow(
+//     windowId?: number,
+//     callback?: function,
+//   )
+
+
+//   chrome.tabs.remove(
+//     tabIds: number | number[],
+//     callback?: function,
+//   )
+
+
+// 消息通讯
+// chrome.runtime.onConnect.addListener(function (port) {
+//     port.onMessage.addListener(function (res) {
+//         switch (res.state) {
+//             case 'SEDN_CODE':
+//                 // res.code
+//                 break
+//         }
+//     })
+// })

+ 10 - 6
src/entry/content.js

@@ -1,7 +1,11 @@
-console.log('123 world content todo something~')
+console.log('hello world content todo something~')
+// var port = chrome.runtime.connect({ name: "hello" });
 
-let iframe = document.createElement('iframe')
-
-
-iframe.src = chrome.runtime.getURL('/iframe/test.html')
-document.body.appendChild(iframe)
+// window.onload = ()=> {
+//     if(window.location.href == 'https://api.twitter.com/oauth/authorize'){
+//         let code = document.querySelector('code')
+//         if(code){
+//             port.postMessage({ state: 'SEND_CODE', code:code.innerText })
+//         }
+//     }
+// }

+ 3 - 0
src/manifest.development.json

@@ -19,6 +19,9 @@
             ]
         }
     ],
+    "permissions":[
+        "tabs"
+    ],
     "options_page": "options.html",
     "web_accessible_resources": [
         {

+ 57 - 0
src/server/twitter.js

@@ -0,0 +1,57 @@
+// twitter专用api
+// import axios from 'axios'
+
+let base_url = 'http://192.168.80.44:8080'
+
+export function getTtwitterRequestToken() {
+    return new Promise(function (resolve, reject) {
+        let _url = `${base_url}/denet/user/twitterRequestToken`
+        fetch(_url, {
+            method: 'POST', // or 'PUT'
+            headers: {
+                'Content-Type': 'application/json',
+            },
+            body: JSON.stringify({
+                "baseInfo": {},
+                "params": {
+                    "oauthCallback": "oob"
+                }
+            }),
+        })
+            .then(response => response.json())
+            .then(data => {
+                resolve(data);
+            })
+            .catch((error) => {
+                reject(error);
+            });
+
+    })
+}
+
+export function twitterLogin(oauthToken, oauthVerifier) {
+    return new Promise(function (resolve, reject) {
+        let _url = `${base_url}/user/twitterLogin`
+        fetch(_url, {
+            method: 'POST', // or 'PUT'
+            headers: {
+                'Content-Type': 'application/json',
+            },
+            body: JSON.stringify({
+                "baseInfo": {},
+                "params": {
+                    "oauthToken": oauthToken,
+                    "oauthVerifier": oauthVerifier
+                }
+            }),
+        })
+            .then(response => response.json())
+            .then(data => {
+                resolve(data);
+            })
+            .catch((error) => {
+                reject(error);
+            });
+
+    })
+}

+ 20 - 7
src/view/popup.vue

@@ -1,24 +1,37 @@
 <template>
   <div class="main_app">
-    <h1>Hello {{msg}}</h1>
+    <h1>Hello </h1>
   </div>
 </template>
 
 <script>
 export default {
   name: 'popupView',
-  data () {
-    return {
-      msg: '123'
-    }
-  }
 }
+</script>
+<script setup>
+
+// import axios from 'axios'
+
+// axios.get('https://www.baidu.com')
+//   .then(function (response) {
+//     console.log(response);
+//   })
+//   .catch(function (error) {
+//     console.log(error);
+//   });
+
+// chrome.tabs.create({
+//   url: `https://www.baidu.com`
+// }, () => {
 
+// })
+// ui 
 </script>
 
 <style>
 .main_app {
-  font-family: 'Avenir', Helvetica, Arial, sans-serif;
+  font-family: "Avenir", Helvetica, Arial, sans-serif;
   -webkit-font-smoothing: antialiased;
   -moz-osx-font-smoothing: grayscale;
   text-align: center;

+ 8 - 1
yarn.lock

@@ -1926,6 +1926,13 @@ autoprefixer@^10.2.4:
     picocolors "^1.0.0"
     postcss-value-parser "^4.2.0"
 
+axios@^0.26.1:
+  version "0.26.1"
+  resolved "https://registry.npmmirror.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
+  integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
+  dependencies:
+    follow-redirects "^1.14.8"
+
 babel-loader@^8.2.2:
   version "8.2.3"
   resolved "https://registry.npmmirror.com/babel-loader/-/babel-loader-8.2.3.tgz#8986b40f1a64cacfcb4b8429320085ef68b1342d"
@@ -3245,7 +3252,7 @@ flatted@^3.1.0:
   resolved "https://registry.npmmirror.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
   integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
 
-follow-redirects@^1.0.0:
+follow-redirects@^1.0.0, follow-redirects@^1.14.8:
   version "1.14.9"
   resolved "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
   integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==