Skip to content

Commit 6ebb974

Browse files
committed
opt code
1 parent ebba412 commit 6ebb974

11 files changed

Lines changed: 119 additions & 74 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- it has some useful functions you will use it frequently
77
- you can add your custom script to some websites
88

9+
## environment
10+
11+
This project need node <= `15.14.0`, we recommend you use `15.14.0` to develop
12+
913
## Add your custom script
1014

1115
1. find `src/script/content/`folder
@@ -30,8 +34,3 @@ npm run dev
3034
# build for production with minification
3135
npm run build
3236
```
33-
34-
## changelog
35-
36-
- 09-20 add `global time` in `time conversion``text decoder`, make `content_script.js` more developed
37-
- 09-19 add `time conversion``json formater`, `text gegex`

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.

src/App.vue

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
<template>
22
<div id="app" :class='{"fixedWidth": !isFull, "fullWidth" :isFull }'>
33
<el-tabs v-model="nowType">
4-
<el-tab-pane label="时间转换" name="time"><Time /></el-tab-pane>
4+
<el-tab-pane label="常用" name="normal">
5+
<div class="normal-container">
6+
<div class="normal-item">
7+
<div class="normal-title">时间处理</div>
8+
<Time />
9+
</div>
10+
<hr />
11+
<div class="normal-item">
12+
<div class="normal-title">计算器</div>
13+
<Cal />
14+
</div>
15+
<hr />
16+
<div class="normal-item">
17+
<div class="normal-title">编解码</div>
18+
<Decode />
19+
</div>
20+
</div>
21+
</el-tab-pane>
522
<el-tab-pane label="Json格式化" name="json"><Json :isFull = "isFull"/></el-tab-pane>
6-
<el-tab-pane label="解码" name="decode"><Decode /></el-tab-pane>
7-
<el-tab-pane label="计算" name="cal"><Cal /></el-tab-pane>
823
<el-tab-pane label="链接" name="link"><Link /></el-tab-pane>
9-
<el-tab-pane label="其他" name="about"><Other /></el-tab-pane>
1024
<el-tab-pane label="模拟请求" v-if="isFull" name="sim"><Sim /></el-tab-pane>
1125
<el-tab-pane label="JsonToGo" name="jsonToGo"><JsonToGo /></el-tab-pane>
1226
<el-tab-pane label="HtmlShow" name="HtmlShow"><HtmlShow /></el-tab-pane>
13-
<el-tab-pane label="Iptv" name="Iptv"><Iptv /></el-tab-pane>
27+
<el-tab-pane label="Iptv" v-if="isFull" name="Iptv"><Iptv /></el-tab-pane>
1428
</el-tabs>
1529
</div>
1630
</template>
@@ -19,7 +33,6 @@
1933
import Time from './components/Time.vue';
2034
import Json from './components/Json.vue';
2135
import Decode from './components/Decode.vue';
22-
import Other from './components/Other.vue';
2336
import Cal from './components/Cal.vue';
2437
import Sim from './components/Sim.vue';
2538
import JsonToGo from './components/JsonToGo.vue';
@@ -31,8 +44,8 @@ export default {
3144
name: 'app',
3245
data() {
3346
return {
34-
nowType: 'time',
35-
isFull: true,
47+
nowType: 'normal',
48+
isFull: false,
3649
};
3750
},
3851
created() {
@@ -44,7 +57,6 @@ export default {
4457
components: {
4558
Time,
4659
Json,
47-
Other,
4860
Decode,
4961
Cal,
5062
Sim,
@@ -88,4 +100,14 @@ li {
88100
a {
89101
color: #42b983;
90102
}
103+
.normal-container{
104+
.normal-item{
105+
display: flex;
106+
flex-direction: column;
107+
align-items: flex-start;
108+
.normal-title{
109+
font-size: 14px;
110+
}
111+
}
112+
}
91113
</style>

src/components/Decode.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
v-model="originalText">
88
</el-input>
99
<div class="btn-container">
10-
<div>
10+
<div class="btn-item">
1111
<el-button class="one-btn" size="mini" @click="urlEncode">UrlEncode</el-button>
12+
<el-button class="one-btn" size="mini" @click="urlDecode">UrlDecode</el-button>
13+
</div>
14+
<div class="btn-item">
1215
<el-button class="one-btn" size="mini" @click="cnToUtf8">中文转UTF-8</el-button>
13-
<el-button class="one-btn" size="mini" @click="cnToUnicode">中文转Unicode</el-button>
16+
<el-button class="one-btn" size="mini" @click="utf8ToCn">UTF-8转中文</el-button>
1417
</div>
15-
<div>
16-
<el-button class="one-btn" size="mini" @click="urlDecode">UrlDecode</el-button>
17-
<el-button class="one-btn" size="mini" @click="utf8ToCn">UTF-8转中文</el-button>
18+
<div class="btn-item">
19+
<el-button class="one-btn" size="mini" @click="cnToUnicode">中文转Unicode</el-button>
1820
<el-button class="one-btn" size="mini" @click="unicodeToCn">Unicode转中文</el-button>
1921
</div>
20-
<div>
22+
<div class="btn-item">
2123
<el-button class="one-btn" size="mini" @click="md5Fun">MD5</el-button>
2224
</div>
2325
</div>
@@ -82,8 +84,14 @@ export default {
8284
</script>
8385
<style lang="sass" scoped>
8486
.decode-container
87+
width: 100%
8588
.btn-container
86-
padding: 10px 0
89+
display: flex
90+
padding: 5Px 0
91+
.btn-item
92+
display: flex;
93+
flex-direction: column;
94+
margin-right: 5px
8795
.one-btn
88-
margin-bottom: 10px
96+
margin-left: 0
8997
</style>

src/components/Html.vue

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
type="textarea"
66
placeholder="请输入html"
77
v-model="showHtml"
8-
:autosize="true"
98
></el-input>
109
</div>
1110
<div class="show-json" v-html="showHtml"></div>
@@ -23,13 +22,4 @@ export default {
2322
</script>
2423
<style lang="sass" scoped>
2524
.full-width
26-
display: flex
27-
flex-wrap: wrap
28-
justify-content: space-between
29-
.or-json
30-
width: 48%
31-
margin-right: 10px
32-
.show-json
33-
width: 48%
34-
padding-top: 0
3525
</style>

src/components/Iptv.vue

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
</div>
2828
<div>
2929
<el-table
30+
v-if="list.length > 0"
3031
ref="dataTable"
3132
@selection-change="handleSelectionChange"
3233
:data="list"
@@ -144,8 +145,11 @@ export default {
144145
for (let i = 0; i < this.list.length; i += 1) {
145146
this.nowIsCheck = true;
146147
fetchGet(this.list[i].url).then((res) => {
147-
console.log(res);
148-
this.list[i].status = 1;
148+
if (this.checkFirstLineIsRight(res.data)) {
149+
this.list[i].status = 1;
150+
} else {
151+
throw new Error('first line is not m3u');
152+
}
149153
this.nowCheckCount += 1;
150154
}).catch((err) => {
151155
console.log(err);
@@ -158,10 +162,13 @@ export default {
158162
if (this.source !== '') {
159163
this.list = [];
160164
const spiStr = this.source.split('\n');
161-
this.firstTitle = spiStr[0];
165+
this.firstTitle = '';
166+
if (spiStr.length > 0) {
167+
[this.firstTitle] = spiStr;
168+
}
162169
if (spiStr.length > 1) {
163170
const len = (spiStr.length - 1) / 2;
164-
for (let i = 1; i < len; i += 1) {
171+
for (let i = 0; i < len; i += 1) {
165172
const index = 1 + (i * 2);
166173
this.parseRowToData(spiStr[index], spiStr[index + 1]);
167174
}
@@ -196,7 +203,7 @@ export default {
196203
regex = /tvg-id="(.*)"/mg;
197204
}
198205
let m;
199-
let value;
206+
let value = '';
200207
while ((m = regex.exec(str)) !== null) {
201208
if (m.index === regex.lastIndex) {
202209
regex.lastIndex++;
@@ -207,7 +214,22 @@ export default {
207214
}
208215
});
209216
}
210-
return value.split('" ')[0];
217+
if (value !== '') {
218+
return value.split('" ')[0];
219+
}
220+
return '';
221+
},
222+
checkFirstLineIsRight(content) {
223+
const contextExp = content.split('\n');
224+
if (contextExp.length > 0) {
225+
const firstLine = contextExp[0];
226+
console.log(firstLine);
227+
if (firstLine.replace('#EXTM3U', '') === firstLine) {
228+
return false;
229+
}
230+
return true;
231+
}
232+
return false;
211233
},
212234
parseName(name) {
213235
const row = name.split(',');

src/components/Json.vue

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
placeholder="请输入json"
77
@change="inputJson"
88
v-model="orJson"
9-
:autosize="true"
109
></el-input>
1110
</div>
1211
<div class="show-json">
1312
<el-input
1413
type="textarea"
14+
v-if="orJson !== ''"
1515
placeholder="显示的json"
1616
v-model="showJson"
1717
:autosize="true"
@@ -33,7 +33,9 @@ export default {
3333
},
3434
methods: {
3535
inputJson() {
36-
this.doSort(1);
36+
if (this.orJson !== '') {
37+
this.doSort(1);
38+
}
3739
},
3840
doSort(type) {
3941
let obj;
@@ -97,56 +99,56 @@ export default {
9799
// json对象转换为字符串变量
98100
let jsonString = JSON.stringify(jsonObj);
99101
// 存储需要特殊处理的字符串段
100-
const _index = [];
102+
const tempIndex = [];
101103
// 存储需要特殊处理的“再数组中的开始位置变量索引
102-
let _indexStart = null;
104+
let tempIndexStart = null;
103105
// 存储需要特殊处理的“再数组中的结束位置变量索引
104-
let _indexEnd = null;
106+
let tempIndexEnd = null;
105107
// 将jsonString字符串内容通过\r\n符分割成数组
106108
let jsonArray = [];
107109
// 正则匹配到{,}符号则在两边添加回车换行
108-
jsonString = jsonString.replace(/([\{\}])/g, '\r\n$1\r\n');
110+
jsonString = jsonString.replace(/([{}])/g, '\r\n$1\r\n');
109111
// 正则匹配到[,]符号则在两边添加回车换行
110-
jsonString = jsonString.replace(/([\[\]])/g, '\r\n$1\r\n');
112+
jsonString = jsonString.replace(/([[\]])/g, '\r\n$1\r\n');
111113
// 正则匹配到,符号则在两边添加回车换行
112-
jsonString = jsonString.replace(/(\,)/g, '$1\r\n');
114+
jsonString = jsonString.replace(/(,)/g, '$1\r\n');
113115
// 正则匹配到要超过一行的换行需要改为一行
114116
jsonString = jsonString.replace(/(\r\n\r\n)/g, '\r\n');
115117
// 正则匹配到单独处于一行的,符号时需要去掉换行,将,置于同行
116-
jsonString = jsonString.replace(/\r\n\,/g, ',');
118+
jsonString = jsonString.replace(/\r\n,/g, ',');
117119
// 特殊处理双引号中的内容
118120
jsonArray = jsonString.split('\r\n');
119121
jsonArray.forEach((node, index) => {
120122
// 获取当前字符串段中"的数量
121-
const num = node.match(/\"/g) ? node.match(/\"/g).length : 0;
123+
const num = node.match(/"/g) ? node.match(/"/g).length : 0;
122124
// 判断num是否为奇数来确定是否需要特殊处理
123-
if (num % 2 && !_indexStart) {
124-
_indexStart = index;
125+
if (num % 2 && !tempIndexStart) {
126+
tempIndexStart = index;
125127
}
126-
if (num % 2 && _indexStart && _indexStart != index) {
127-
_indexEnd = index;
128+
if (num % 2 && tempIndexStart && tempIndexStart !== index) {
129+
tempIndexEnd = index;
128130
}
129131
// 将需要特殊处理的字符串段的其实位置和结束位置信息存入,并对应重置开始时和结束变量
130-
if (_indexStart && _indexEnd) {
131-
_index.push({
132-
start: _indexStart,
133-
end: _indexEnd,
132+
if (tempIndexStart && tempIndexEnd) {
133+
tempIndex.push({
134+
start: tempIndexStart,
135+
end: tempIndexEnd,
134136
});
135-
_indexStart = null;
136-
_indexEnd = null;
137+
tempIndexStart = null;
138+
tempIndexEnd = null;
137139
}
138140
});
139141
// 开始处理双引号中的内容,将多余的"去除
140-
_index.reverse().forEach((item) => {
142+
tempIndex.reverse().forEach((item) => {
141143
const newArray = jsonArray.slice(item.start, item.end + 1);
142144
jsonArray.splice(item.start, item.end + 1 - item.start, newArray.join(''));
143145
});
144146
// 奖处理后的数组通过\r\n连接符重组为字符串
145147
jsonString = jsonArray.join('\r\n');
146148
// 将匹配到:后为回车换行加大括号替换为冒号加大括号
147-
jsonString = jsonString.replace(/\:\r\n\{/g, ':{');
149+
jsonString = jsonString.replace(/:\r\n\{/g, ':{');
148150
// 将匹配到:后为回车换行加中括号替换为冒号加中括号
149-
jsonString = jsonString.replace(/\:\r\n\[/g, ':[');
151+
jsonString = jsonString.replace(/:\r\n\[/g, ':[');
150152
// 将上述转换后的字符串再次以\r\n分割成数组
151153
jsonArray = jsonString.split('\r\n');
152154
// 将转换完成的字符串根据PADDING值来组合成最终的形态

src/components/JsonToGo.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div class="json-container">
33
<div class="json-text">
4-
<el-input type="textarea" rows=8 placeholder="请输入json" @change="inputJson" v-model="jsonText">
4+
<el-input type="textarea" rows=2 placeholder="请输入json" @change="inputJson" v-model="jsonText">
55
</el-input>
66
</div>
7-
<div class="show-go">
7+
<div class="show-go" v-if="goStruct !== ''">
88
<el-input type="textarea" rows=8 placeholder="显示的GoStruct" v-model="goStruct"></el-input>
99
</div>
1010
</div>

src/components/Link.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
export default {
6565
data() {
6666
return {
67-
linkList: [],
67+
linkList: [{ url: 'https://regex101.com/', title: '正则' }, { url: 'http://github.com/zhimin-dev/chrome-extension', title: '本插件Github' }],
6868
showExport: false,
6969
exportJson: '',
7070
nowType: 0,

0 commit comments

Comments
 (0)