Skip to content

Commit 1aa985c

Browse files
committed
opt code
1 parent 197b808 commit 1aa985c

10 files changed

Lines changed: 199 additions & 169 deletions

File tree

dist/build.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/build.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/background.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,39 @@ function request_proxy({ url, method, data }) {
4444
};
4545
}
4646

47+
const wbSpiderConfig = {};
48+
49+
chrome.storage.onChanged.addListener((changes, namespace) => {
50+
console.log('change ======');
51+
for (const [key, { oldValue, newValue }] of Object.entries(changes)) {
52+
console.log('change key', key, newValue);
53+
if (key === 'wbSpider' || key === 'wbSpiderStart') {
54+
if (key === 'wbSpider') {
55+
wbSpiderConfig.url = newValue;
56+
} else if (key === 'wbSpiderStart') {
57+
wbSpiderConfig.start = newValue;
58+
}
59+
}
60+
console.log(wbSpiderConfig);
61+
}
62+
});
63+
4764
chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
48-
const url = 'http://127.0.0.1:8081/api/chrome-extension/save-spider?token=zhimin-studio-save-spider';
49-
fetch(url, {
50-
method: 'POST',
51-
body: JSON.stringify(data),
52-
headers: {
53-
'Content-Type': 'application/json;charset=UTF-8',
54-
},
55-
}).then((resp) => {
56-
console.log(resp);
57-
});
58-
// request_proxy({ url, method: 'POST', data });
65+
if (wbSpiderConfig.url !== '' && wbSpiderConfig.start) {
66+
fetch(wbSpiderConfig.url, {
67+
method: 'POST',
68+
body: JSON.stringify(data),
69+
headers: {
70+
'Content-Type': 'application/json;charset=UTF-8',
71+
},
72+
}).then((resp) => {
73+
console.log(resp);
74+
sendResponse({ code: 200 });
75+
})
76+
.catch((err) => {
77+
console.log(err);
78+
sendResponse({ code: 500 });
79+
});
80+
}
5981
sendResponse({ code: 200 });
6082
});

js/content_script.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,8 @@ setInterval(() => {
208208
});
209209
}
210210
chrome.runtime.sendMessage({ list: saveData }, (data) => {
211-
// if (data.code !== undefined && data.code !== 200) {
212-
console.log(data);
213-
// }
214211
});
215-
}, 2000);
212+
}, 3000);
216213
}
217214
if(nowHost === 'www.baidu.com'){
218215
setTimeout(() => {

src/App.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
</div>
1818
<div class="normal-item">
1919
<div class="normal-title">链接</div>
20-
<Link hideMenuBar=true />
20+
<Link hideMenuBar="true" />
2121
</div>
2222
</div>
2323
</el-tab-pane>
2424
<el-tab-pane label="提醒" name="link"><Notice /></el-tab-pane>
25-
<el-tab-pane label="链接" name="notice"><Link hideMenuBar=false /></el-tab-pane>
25+
<el-tab-pane label="链接" name="notice"><Link hideMenuBar="false" /></el-tab-pane>
2626
<el-tab-pane label="模拟请求" v-if="isFull" name="sim"><Sim /></el-tab-pane>
2727
<el-tab-pane label="JsonStuff" name="jsonStuff"><JsonStuff :isFull = "isFull" /></el-tab-pane>
2828
<el-tab-pane label="SqlToModel" name="sqlToModel"><SqlToModel /></el-tab-pane>
2929
<el-tab-pane label="HtmlShow" v-if="isFull" name="HtmlShow"><HtmlShow /></el-tab-pane>
30+
<el-tab-pane label="设置" name="setting"><Setting /></el-tab-pane>
3031
</el-tabs>
3132
</div>
3233
</template>
@@ -40,6 +41,7 @@ import HtmlShow from './components/Html.vue';
4041
import Link from './components/Link.vue';
4142
import SqlToModel from './components/SqlToModel.vue';
4243
import Notice from './components/Notice.vue';
44+
import Setting from './components/Setting.vue';
4345
import JsonStuff from './components/JsonStuff.vue';
4446
4547
export default {
@@ -66,6 +68,7 @@ export default {
6668
SqlToModel,
6769
Notice,
6870
JsonStuff,
71+
Setting,
6972
},
7073
};
7174
</script>

src/components/Decode.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<el-button class="one-btn" size="mini" @click="urlEncode">UrlEncode</el-button>
1212
<el-button class="one-btn" size="mini" @click="urlDecode">UrlDecode</el-button>
1313
</div>
14+
<div class="btn-item">
15+
<el-button class="one-btn" size="mini" @click="base64Encode">base64Encode</el-button>
16+
<el-button class="one-btn" size="mini" @click="base64Decode">base64Decode</el-button>
17+
</div>
1418
<div class="btn-item">
1519
<el-button class="one-btn" size="mini" @click="cnToUtf8">中文转UTF-8</el-button>
1620
<el-button class="one-btn" size="mini" @click="utf8ToCn">UTF-8转中文</el-button>
@@ -79,6 +83,14 @@ export default {
7983
const str = this.originalText.replace(/\\/g, '%');
8084
this.outputText = unescape(str);
8185
},
86+
base64Encode() {
87+
if (this.originalText === '') { return; }
88+
this.outputText = btoa(encodeURIComponent(this.originalText));
89+
},
90+
base64Decode() {
91+
if (this.originalText === '') { return; }
92+
this.outputText = decodeURIComponent(atob(this.originalText));
93+
},
8294
},
8395
};
8496
</script>

src/components/Link.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<div style="display: flex;justify-content: flex-end;" v-if="!hideMenuBar">
3+
<div style="display: flex;justify-content: flex-end;" v-if="hideMenuBar==='false'">
44
<div v-if="!showExport">
55
<el-button icon="el-icon-edit" size="mini" v-if="nowType !== 0"
66
@click="cancelLinkFun">取消</el-button>
@@ -63,7 +63,7 @@
6363
<script>
6464
export default {
6565
props: {
66-
hideMenuBar: Boolean,
66+
hideMenuBar: String,
6767
},
6868
data() {
6969
return {

src/components/Setting.vue

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<template>
2+
<div class="setting-conatiner">
3+
<div class="one-setting">
4+
<div class="one-setting-head">wb爬虫设置</div>
5+
<div class="one-item">
6+
<div class="item-head">回调接口</div>
7+
<div class="item-content">
8+
<el-input
9+
v-model="wbSpider"
10+
class="one-input"
11+
size="small"
12+
placeholder=""
13+
@change="setWbSpider"
14+
></el-input>
15+
</div>
16+
</div>
17+
<div class="one-item">
18+
<div class="item-head">是否开始任务</div>
19+
<div class="item-content">
20+
<el-switch
21+
v-model="startSpider"
22+
@change="startSpiderCall"
23+
active-text="开始"
24+
inactive-text="关闭"
25+
>
26+
</el-switch>
27+
</div>
28+
</div>
29+
</div>
30+
</div>
31+
</template>
32+
33+
<script>
34+
export default {
35+
data() {
36+
return {
37+
wbSpider: '',
38+
startSpider: false,
39+
wbSpiderKey: 'l:wbSpider',
40+
};
41+
},
42+
created() {
43+
this.wbSpider = localStorage.getItem(this.wbSpiderKey);
44+
},
45+
methods: {
46+
startSpiderCall() {
47+
if (chrome.storage !== undefined && this.wbSpider !== '') {
48+
chrome.storage.local.set({
49+
wbSpider: this.wbSpider,
50+
}, () => {
51+
console.log('设置回调接口爬成功');
52+
});
53+
chrome.storage.local.set({
54+
wbSpiderStart: this.startSpider,
55+
}, () => {
56+
console.log('设置任务成功,请浏览相关页面!');
57+
});
58+
}
59+
},
60+
setWbSpider() {
61+
localStorage.setItem(this.wbSpiderKey, this.wbSpider);
62+
},
63+
},
64+
};
65+
</script>
66+
67+
<style lang="sass" scoped>
68+
.setting-conatiner
69+
display: flex
70+
flex-direction: column
71+
.one-setting
72+
display: flex
73+
flex-direction: column
74+
align-items: baseline
75+
.one-setting-head
76+
width: 100%
77+
border-bottom: 1px solid #eee
78+
text-align: left
79+
.one-item
80+
display: flex
81+
margin-bottom: 5px
82+
flex-direction: column
83+
align-items: baseline
84+
.item-head
85+
margin-bottom: 5px
86+
.item-content
87+
margin-left: 50px
88+
.one-input
89+
width: 500px
90+
</style>

0 commit comments

Comments
 (0)