Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夜猫逐梦
1024程序员开源挑战赛
提交
369a2779
1
1024程序员开源挑战赛
项目概览
夜猫逐梦
/
1024程序员开源挑战赛
与 Fork 源项目一致
Fork自
GitCode / 1024程序员开源挑战赛(10.23-11.14)
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
1024程序员开源挑战赛
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
369a2779
编写于
4月 19, 2021
作者:
B
baiy
提交者:
ninecents
10月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
初步支持utools
上级
18057f2a
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
230 addition
and
494 deletion
+230
-494
README.md
README.md
+3
-2
package.json
package.json
+1
-1
public/utools.html
public/utools.html
+33
-0
src/adapter/chrome/manifest.json
src/adapter/chrome/manifest.json
+0
-1
src/adapter/utools/plugin.json
src/adapter/utools/plugin.json
+6
-6
src/config.js
src/config.js
+29
-126
src/helper.js
src/helper.js
+43
-25
src/setting.js
src/setting.js
+0
-12
src/tool.js
src/tool.js
+15
-3
src/tool.vue
src/tool.vue
+4
-3
src/tool/adapter.js
src/tool/adapter.js
+44
-209
src/tool/config.js
src/tool/config.js
+16
-32
src/views/setting/block.vue
src/views/setting/block.vue
+25
-14
vue.config.js
vue.config.js
+11
-60
未找到文件。
README.md
浏览文件 @
369a2779
# 程序开发常用工具
使用过程中的任何问题或者需要新的工具欢迎提交
`Issue`
,新工具如果可以提供实现代码就完美了O(∩_∩)O
## 安装
##
chrome
安装
-
方法1: 在
[
Chrome 网上应用店
](
https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh
)
安装
-
方法2:
[
下载 .crx 安装包
](
https://github.com/baiy/Ctool/releases/latest
)
手动安装
[
猛戳这里查看手动安装教程
](
http://www.cnplugins.com/tool/outline-install-crx-file.html
)
-
方法3:
[
百度网盘下载
](
https://pan.baidu.com/s/1mhWbqWC
)
安装方法和方法2一致
> 方法2 / 方法3 不定期维护 仅供网络环境特别恶劣的同学使用
## 支持 utools
## 功能列表
|功能|说明|离线使用|
|---|---|---|
...
...
package.json
浏览文件 @
369a2779
{
"name"
:
"c-tool"
,
"version"
:
"1.4.
3
"
,
"version"
:
"1.4.
4
"
,
"private"
:
true
,
"scripts"
:
{
"serve"
:
"vue-cli-service serve --port 8081"
,
...
...
public/utools.html
0 → 100644
浏览文件 @
369a2779
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1.0"
>
<title>
Ctool 程序开发常用工具
</title>
</head>
<body>
</body>
<script>
function
setToolCode
(
name
){
let
data
=
utools
.
db
.
get
(
"
_current_tool_
"
);
let
rev
=
data
?
{
'
_rev
'
:
data
.
_rev
}
:
{}
utools
.
db
.
put
({
'
_id
'
:
'
_current_tool_
'
,
'
data
'
:
name
,
...
rev
})
}
window
.
utools
.
onPluginEnter
(({
code
})
=>
{
let
tool
=
""
;
if
(
code
.
indexOf
(
'
ctool-
'
)
!==
-
1
){
tool
=
code
.
replace
(
/ctool-/g
,
""
)
}
setToolCode
(
tool
)
window
.
utools
.
createBrowserWindow
(
'
tool.html
'
,{
width
:
1200
})
window
.
utools
.
hideMainWindow
()
window
.
utools
.
outPlugin
()
})
</script>
</html>
\ No newline at end of file
src/adapter/chrome/manifest.json
浏览文件 @
369a2779
...
...
@@ -12,7 +12,6 @@
"default_title"
:
"常用开发工具"
,
"default_popup"
:
"index.html"
},
"options_page"
:
"setting.html"
,
"icons"
:
{
"16"
:
"img/icon128.png"
,
"48"
:
"img/icon128.png"
,
...
...
src/adapter/utools/plugin.json
浏览文件 @
369a2779
...
...
@@ -3,14 +3,14 @@
"description"
:
"Ctool 程序开发常用工具"
,
"author"
:
"baiy"
,
"homepage"
:
"https://github.com/baiy/Ctool"
,
"main"
:
"
tool
.html"
,
"main"
:
"
utools
.html"
,
"version"
:
"##version##"
,
"logo"
:
"img/icon
_utools
.png"
,
"logo"
:
"img/icon
128
.png"
,
"pluginSetting"
:
{
"single"
:
fals
e
"single"
:
tru
e
},
"features"
:
"##features##"
,
"development"
:
{
"main"
:
"http://localhost:8081/tool.html"
},
"features"
:
"##features##"
"main"
:
"http://localhost:8081/utools.html"
}
}
\ No newline at end of file
src/config.js
浏览文件 @
369a2779
// 工具缓存数据过期时间(秒)
const
TOOL_DATA_EXPIRY
=
3600
*
24
// 徽章过期时间(天)
const
BADGE_EXPIRY
=
5
// 分类徽章
const
BADGE_CATEGORY
=
[]
// 工具徽章
const
BADGE_TOOL
=
[]
// 默认常用工具
const
DEFAULT_COMMON_TOOL
=
[
'
hash
'
,
'
encrypt
'
,
'
json
'
,
'
base64
'
,
'
url
'
,
'
timestamp
'
,
'
qrCode
'
,
'
pinyin
'
,
'
ip
'
,
'
code
'
,
'
unicode
'
,
'
text
'
,
'
randomString
'
,
'
diffs
'
,
]
const
category
=
[
{
'
name
'
:
'
common
'
},
{
'
name
'
:
'
encryption
'
},
{
'
name
'
:
'
conversion
'
},
{
'
name
'
:
'
serialize
'
},
{
'
name
'
:
'
check
'
},
{
'
name
'
:
'
generate
'
},
{
'
name
'
:
'
other
'
},
{
'
name
'
:
'
common
'
,
'
title
'
:
'
常用工具
'
},
{
'
name
'
:
'
encryption
'
,
'
title
'
:
'
加密解密
'
},
{
'
name
'
:
'
conversion
'
,
'
title
'
:
'
编码转换
'
},
{
'
name
'
:
'
serialize
'
,
'
title
'
:
'
序列化
'
},
{
'
name
'
:
'
other
'
,
'
title
'
:
'
其他工具
'
},
]
const
tool
=
[
{
'
name
'
:
'
hash
'
,
'
cat
'
:
[
'
encryption
'
]
},
{
'
name
'
:
'
encrypt
'
,
'
cat
'
:
[
'
encryption
'
]
},
{
'
name
'
:
'
sign
'
,
'
cat
'
:
[
'
encryption
'
,
'
check
'
]},
{
'
name
'
:
'
base64
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
json
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
url
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
timestamp
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
qrCode
'
,
'
cat
'
:
[
'
generate
'
]},
{
'
name
'
:
'
barcode
'
,
'
cat
'
:
[
'
generate
'
]},
{
'
name
'
:
'
pinyin
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
ip
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
code
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unicode
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
decimalConvert
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
regex
'
,
'
cat
'
:
[
'
check
'
]},
{
'
name
'
:
'
randomString
'
,
'
cat
'
:
[
'
generate
'
]},
{
'
name
'
:
'
serializeConversion
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
diffs
'
,
'
cat
'
:
[
'
check
'
]},
{
'
name
'
:
'
crontab
'
,
'
cat
'
:
[
'
check
'
]},
{
'
name
'
:
'
websocket
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unit
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
time
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
uuid
'
,
'
cat
'
:
[
'
generate
'
]},
{
'
name
'
:
'
jsonToObject
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
ascii
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
variableConversion
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
jwt
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
hexString
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
text
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
html
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
hash
'
,
'
title
'
:
'
哈希(hash)
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
encrypt
'
,
'
title
'
:
'
加密/解密
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
base64
'
,
'
title
'
:
'
BASE64编码
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
json
'
,
'
title
'
:
'
JSON工具
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
url
'
,
'
title
'
:
'
URL编码
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
timestamp
'
,
'
title
'
:
'
时间戳
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
qrCode
'
,
'
title
'
:
'
二维码
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
pinyin
'
,
'
title
'
:
'
汉字转拼音
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
ip
'
,
'
title
'
:
'
IP地址查询
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
code
'
,
'
title
'
:
'
代码格式化
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unicode
'
,
'
title
'
:
'
Unicode
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
decimalConvert
'
,
'
title
'
:
'
进制转换
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
regex
'
,
'
title
'
:
'
正则表达式
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
randomString
'
,
'
title
'
:
'
随机字符生成
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
serializeConversion
'
,
'
title
'
:
'
序列化转换
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
diffs
'
,
'
title
'
:
'
文本差异化对比
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
crontab
'
,
'
title
'
:
'
crontab校验
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
websocket
'
,
'
title
'
:
'
websocket调试
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unit
'
,
'
title
'
:
'
单位换算
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
time
'
,
'
title
'
:
'
时间计算器
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
uuid
'
,
'
title
'
:
'
UUID生成
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
jsonToObject
'
,
'
title
'
:
'
JSON转实体类
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
]
// 工具类功能配置
const
feature
=
{
qrCode
:
[
{
name
:
"
generate
"
,
title
:
'
生成
'
},
{
name
:
"
reader
"
,
title
:
'
解析
'
}
]
}
const
utools
=
{
keyword
:
{
hash
:
[
'
md5
'
,
'
sha1
'
,
'
sha256
'
,
'
sha512
'
,
'
sm3
'
],
encrypt
:
[
'
AES
'
,
'
DES
'
,
'
RC4
'
,
'
Rabbit
'
,
'
TripleDes
'
,
'
sm2
'
],
jwt
:
[
'
jwtDecode
'
],
hexString
:
[
'
hex to string
'
,
'
string to hex
'
,
'
十六进制转字符串
'
,
'
字符串转十六机制
'
],
text
:
[
'
文本处理
'
,
'
大小写转换
'
,
'
中英文标点转换
'
,
'
简繁转换
'
,
'
字符替换
'
,
'
字符统计
'
,
'
行去重
'
,
'
添加行号
'
,
'
行排序
'
,
'
过滤行首尾不可见字符
'
,
'
过滤空行
'
],
sign
:
[
'
签名
'
,
'
验签
'
,
'
rsa
'
],
},
cmds
:
{
timestamp
:
[
{
"
type
"
:
"
regex
"
,
// "label": "", //程序自动根据tool title填充
"
match
"
:
"
/(^
\\
d{10}(?:
\\
d{3})?$)|(^
\\
d{4}-
\\
d{2}-
\\
d{2}
\\
d{2}:
\\
d{2}:
\\
d{2}(?:
\\
.
\\
d{3})?$)/i
"
,
"
minLength
"
:
10
,
"
maxLength
"
:
25
}
],
qrCode
:
[
{
"
type
"
:
"
regex
"
,
"
match
"
:
"
/[a-zA-z]+://[^
\\
s]*/i
"
,
"
minLength
"
:
8
,
"
feature
"
:
'
generate
'
// 适配工具内功能
},
{
"
type
"
:
"
regex
"
,
"
match
"
:
"
/[a-zA-z]+://[^
\\
s]*/i
"
,
"
minLength
"
:
8
,
"
feature
"
:
'
reader
'
// 适配工具内功能
}
],
ip
:
[
{
"
type
"
:
"
regex
"
,
"
match
"
:
"
/
\\
d{1,3}
\\
.
\\
d{1,3}
\\
.
\\
d{1,3}
\\
.
\\
d{1,3}/i
"
,
"
minLength
"
:
7
,
"
maxLength
"
:
15
}
],
unicode
:
[
{
"
type
"
:
"
regex
"
,
"
match
"
:
"
/
\\\\
u[0-9a-f]{4}/i
"
,
"
minLength
"
:
6
}
]
}
}
module
.
exports
=
{
category
,
tool
,
feature
,
utools
,
toolDataExpiry
:
TOOL_DATA_EXPIRY
,
badgeExpiry
:
BADGE_EXPIRY
,
badgeCategory
:
BADGE_CATEGORY
,
badgeTool
:
BADGE_TOOL
,
defaultCommonTool
:
DEFAULT_COMMON_TOOL
}
tool
}
\ No newline at end of file
src/helper.js
浏览文件 @
369a2779
import
{
v4
as
uuidV4
}
from
'
uuid
'
;
import
{
openUrl
as
chromiumOpenUrl
}
from
'
./adapter/chromium/helper
'
;
import
{
openUrl
as
utoolsOpenUrl
}
from
'
./adapter/utools/helper
'
;
import
{
openUrl
as
firefoxOpenUrl
}
from
'
./adapter/firefox/helper
'
;
import
{
stringify
as
queryStringify
}
from
"
query-string
"
export
const
env
=
(
key
)
=>
{
export
const
env
=
function
(
key
)
{
return
process
[
'
ctool
'
][
key
]
?
process
[
'
ctool
'
][
key
]
:
""
;
};
export
const
isChrome
=
!!
env
(
'
isChrome
'
)
export
const
isEdge
=
!!
env
(
'
isEdge
'
)
export
const
isFirefox
=
!!
env
(
'
isFirefox
'
)
export
const
isChromium
=
!!
env
(
'
isChromium
'
)
export
const
isWeb
=
!!
env
(
'
isWeb
'
)
export
const
isUtools
=
!!
env
(
'
isUtools
'
)
export
const
uuid
=
()
=>
{
return
uuidV4
().
toLowerCase
();
}
export
const
openUrl
=
(
url
)
=>
{
if
(
isChromium
)
{
return
chromiumOpenUrl
(
url
)
export
const
trim
=
function
(
str
,
char
,
type
)
{
if
(
char
)
{
if
(
type
===
'
left
'
)
{
return
str
.
replace
(
new
RegExp
(
'
^
\\
'
+
char
+
'
+
'
,
'
g
'
),
''
);
}
else
if
(
type
===
'
right
'
)
{
return
str
.
replace
(
new
RegExp
(
'
\\
'
+
char
+
'
+$
'
,
'
g
'
),
''
);
}
return
str
.
replace
(
new
RegExp
(
'
^
\\
'
+
char
+
'
+|
\\
'
+
char
+
'
+$
'
,
'
g
'
),
''
);
}
if
(
isUtools
)
{
return
utoolsOpenUrl
(
url
)
return
str
.
replace
(
/^
\s
+|
\s
+$/g
,
''
);
};
export
const
inArray
=
function
(
value
,
arr
)
{
return
arr
.
findIndex
((
v
)
=>
{
return
value
===
v
})
!==
-
1
};
export
const
openTab
=
function
(
url
)
{
if
(
isChrome
&&
chrome
.
tabs
)
{
return
chrome
.
tabs
.
create
({
url
:
url
,
selected
:
true
});
}
if
(
is
Firefox
)
{
return
firefoxOpenUr
l
(
url
)
if
(
is
Utools
&&
window
.
utools
)
{
return
window
.
utools
.
shellOpenExterna
l
(
url
)
}
return
window
.
open
(
url
);
};
export
const
version
=
env
(
'
version
'
).
trim
()
export
const
stat
=
function
(
action
,
data
=
{})
{
setTimeout
(
function
()
{
try
{
let
img
=
new
Image
(
1
,
1
);
img
.
src
=
'
https://www.baiy.org/chrome_tool/stat/?
'
+
queryStringify
(
Object
.
assign
(
{
v
:
env
(
'
version
'
),
a
:
action
,
r
:
Math
.
random
()
},
data
)
);
}
catch
(
e
)
{
// todo
}
},
3000
)
};
export
const
setDisplayMode
=
(
mode
)
=>
{
mode
=
[
'
light
'
,
'
dark
'
,
'
auto
'
].
includes
(
mode
)
?
mode
:
'
light
'
console
.
log
(
`set display mode:
${
mode
}
`
)
document
.
getElementsByTagName
(
'
html
'
)[
0
].
setAttribute
(
'
theme-mode
'
,
mode
);
}
src/setting.js
已删除
100644 → 0
浏览文件 @
18057f2a
import
Vue
from
'
vue
'
import
ViewUI
from
'
view-design
'
;
import
'
view-design/dist/styles/iview.css
'
;
import
App
from
'
./setting.vue
'
Vue
.
config
.
productionTip
=
false
;
Vue
.
use
(
ViewUI
);
new
Vue
({
render
:
h
=>
h
(
App
)
}).
$mount
(
'
#app
'
);
src/tool.js
浏览文件 @
369a2779
...
...
@@ -3,8 +3,10 @@ import ViewUI from 'view-design'
import
'
view-design/dist/styles/iview.css
'
import
router
from
'
./tool.router
'
import
optionBlock
from
'
./components/optionBlock
'
import
{
plugin
as
modelPlugin
}
from
'
./tool/model
'
import
model
,
{
plugin
as
modelPlugin
}
from
'
./tool/model
'
import
App
from
'
./tool.vue
'
import
{
isUtools
}
from
'
./helper
'
import
config
from
"
./tool/config
"
;
Vue
.
config
.
productionTip
=
false
...
...
@@ -13,7 +15,18 @@ Vue.use(modelPlugin)
Vue
.
component
(
'
option-block
'
,
optionBlock
);
(
function
()
{
if
(
document
.
body
.
clientWidth
>
900
)
{
if
(
isUtools
)
{
let
tool
=
window
.
utools
.
db
.
get
(
"
_current_tool_
"
);
if
(
tool
&&
tool
.
data
)
{
let
cat
=
config
.
getToolDefaultCategory
(
tool
.
data
);
if
(
cat
)
{
model
.
setCategoryHistory
(
cat
)
model
.
setToolHistory
(
cat
,
tool
.
data
)
}
}
}
if
(
document
.
body
.
clientWidth
>
900
||
isUtools
)
{
console
.
log
(
'
调整窗口大小
'
)
const
page
=
document
.
getElementById
(
'
page
'
)
page
.
style
.
width
=
'
auto
'
...
...
@@ -21,7 +34,6 @@ Vue.component('option-block', optionBlock);
page
.
style
.
height
=
'
auto
'
}
})()
new
Vue
({
router
,
render
:
h
=>
h
(
App
),
...
...
src/tool.vue
浏览文件 @
369a2779
...
...
@@ -10,7 +10,7 @@
{{
cat
.
title
}}
</
template
>
</MenuItem>
<MenuItem
style=
"padding: 0 5px;float: right"
name=
"_new"
>
<MenuItem
style=
"padding: 0 5px;float: right"
name=
"_new"
v-if=
"!isUtools"
>
<Icon
type=
"md-expand"
:size=
"24"
/>
</MenuItem>
<MenuItem
style=
"padding: 0 5px;float: right"
name=
"_feedback"
>
...
...
@@ -70,7 +70,7 @@ import settingBlock from "./views/setting/block"
import
model
from
'
./tool/model
'
import
historyFactory
from
'
./tool/history
'
import
{
setLoadHistoryIndex
}
from
'
./tool/history
'
import
{
openTab
}
from
'
./helper
'
import
{
openTab
,
isUtools
}
from
'
./helper
'
export
default
{
components
:
{
...
...
@@ -78,6 +78,7 @@ export default {
},
data
()
{
return
{
isUtools
:
isUtools
,
category
:
config
.
category
,
currentCategory
:
''
,
currentTool
:
''
,
...
...
@@ -145,7 +146,7 @@ export default {
this
.
settingShow
=
true
;
break
case
'
_new
'
:
openTab
(
window
.
location
.
href
)
openTab
(
window
.
location
.
href
)
break
case
'
_history
'
:
this
.
history
()
...
...
src/tool/adapter.js
浏览文件 @
369a2779
const
path
=
require
(
'
path
'
);
const
_
=
require
(
'
lodash
'
);
const
fs
=
require
(
'
fs
'
);
const
i18nBuild
=
require
(
'
../i18n/build
'
)
let
path
=
require
(
'
path
'
);
// 运行平台适配
let
platform
=
process
.
env
.
hasOwnProperty
(
'
npm_config_adapter
'
)
?
process
.
env
.
npm_config_adapter
:
""
;
platform
=
[
'
chrome
'
,
'
utools
'
,
'
edge
'
,
'
firefox
'
,
'
web
'
].
includes
(
platform
)
?
platform
:
"
web
"
platform
=
[
"
chrome
"
,
'
utools
'
].
includes
(
platform
)
?
platform
:
"
web
"
const
IS_CHROME
=
"
chrome
"
===
platform
const
IS_EDGE
=
"
edge
"
===
platform
const
IS_FIREFOX
=
"
firefox
"
===
platform
const
IS_UTOOLS
=
"
utools
"
===
platform
const
IS_CHROMIUM
=
[
'
chrome
'
,
'
edge
'
].
includes
(
platform
)
const
IS_WEB
=
"
web
"
===
platform
const
toolConfig
=
require
(
'
../config
'
)
const
tools
=
toolConfig
.
tool
const
utoolsConfig
=
toolConfig
.
utools
const
featureConfig
=
toolConfig
.
feature
const
getToolFeatureTitle
=
(
name
,
features
=
[])
=>
{
for
(
let
i
=
0
;
i
<
features
.
length
;
i
++
)
{
if
(
features
[
i
][
'
name
'
]
===
name
)
{
return
features
[
i
].
title
}
}
return
name
}
// 删除文件
const
removeFile
=
(
filePath
)
=>
{
fs
.
existsSync
(
filePath
)
&&
fs
.
unlinkSync
(
filePath
)
}
// 删除目录
const
removeDir
=
function
(
directoryPath
)
{
if
(
fs
.
existsSync
(
directoryPath
))
{
fs
.
readdirSync
(
directoryPath
).
forEach
((
file
)
=>
{
const
curPath
=
path
.
join
(
directoryPath
,
file
);
if
(
fs
.
lstatSync
(
curPath
).
isDirectory
())
{
removeDir
(
curPath
);
}
else
{
fs
.
unlinkSync
(
curPath
);
}
const
chromeConfigWrite
=
()
=>
{
let
fs
=
require
(
'
fs
'
);
// 移除环境配置文件
let
manifestPath
=
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
);
fs
.
unlink
(
manifestPath
,
()
=>
{
});
if
(
IS_CHROME
)
{
fs
.
readFile
(
path
.
join
(
__dirname
,
"
../adapter/chrome/manifest.json
"
),
'
utf8
'
,
function
(
err
,
files
)
{
if
(
err
)
return
console
.
log
(
err
);
let
result
=
files
.
replace
(
/##version##/g
,
process
.
env
.
npm_package_version
);
fs
.
writeFile
(
manifestPath
,
result
,
'
utf8
'
,
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
);
});
});
fs
.
rmdirSync
(
directoryPath
);
}
};
const
chromeConfigWrite
=
{
remove
()
{
},
write
()
{
if
(
!
IS_CHROME
)
{
return
;
}
fs
.
writeFileSync
(
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
),
fs
.
readFileSync
(
path
.
join
(
__dirname
,
"
../adapter/chrome/manifest.json
"
)).
toString
().
replace
(
/##version##/g
,
process
.
env
.
npm_package_version
)
);
}
}
const
edgeConfigWrite
=
{
remove
()
{
},
write
()
{
if
(
!
IS_EDGE
)
{
return
;
}
fs
.
writeFileSync
(
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
),
fs
.
readFileSync
(
path
.
join
(
__dirname
,
"
../adapter/edge/manifest.json
"
)).
toString
().
replace
(
/##version##/g
,
process
.
env
.
npm_package_version
)
);
}
}
const
chromiumConfigWrite
=
{
remove
()
{
removeFile
(
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
));
removeFile
(
path
.
join
(
__dirname
,
'
../../public/background.js
'
));
// 移除语言包目录
removeDir
(
path
.
join
(
__dirname
,
'
../../public/_locales/
'
))
},
write
()
{
if
(
!
IS_CHROMIUM
)
{
return
;
}
fs
.
copyFileSync
(
path
.
join
(
__dirname
,
"
../adapter/chromium/background.js
"
),
path
.
join
(
__dirname
,
'
../../public/background.js
'
)
);
// 生成语言包
const
locales
=
i18nBuild
.
getLocales
().
detail
const
localeDir
=
path
.
join
(
__dirname
,
'
../../public/_locales/
'
)
fs
.
mkdirSync
(
localeDir
);
Object
.
keys
(
locales
).
forEach
((
_locale
)
=>
{
fs
.
mkdirSync
(
path
.
join
(
localeDir
,
_locale
));
let
messages
=
{}
Object
.
keys
(
locales
[
_locale
]).
forEach
((
key
)
=>
{
let
message
=
{
message
:
locales
[
_locale
][
key
][
'
message
'
].
replace
(
new
RegExp
(
"
{.+?}
"
,
'
g
'
),
(
item
)
=>
{
return
`$
${
item
.
replace
(
"
{
"
,
""
).
replace
(
"
}
"
,
""
).
toUpperCase
()}
$`
;
})
}
if
(
"
placeholders
"
in
locales
[
_locale
][
key
])
{
message
.
placeholders
=
{}
let
index
=
1
;
locales
[
_locale
][
key
][
'
placeholders
'
].
forEach
((
placeholder
)
=>
{
message
.
placeholders
[
placeholder
]
=
{
content
:
"
$
"
+
(
index
++
)}
})
}
messages
[
key
]
=
message
})
fs
.
writeFileSync
(
path
.
join
(
localeDir
,
`
${
_locale
}
/messages.json`
),
JSON
.
stringify
(
messages
,
null
,
4
));
})
}
}
const
firefoxConfigWrite
=
{
remove
()
{
removeFile
(
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
));
removeFile
(
path
.
join
(
__dirname
,
'
../../public/background.js
'
));
},
write
()
{
if
(
!
IS_FIREFOX
)
{
return
;
}
fs
.
copyFileSync
(
path
.
join
(
__dirname
,
"
../adapter/firefox/background.js
"
),
path
.
join
(
__dirname
,
'
../../public/background.js
'
)
);
fs
.
writeFileSync
(
path
.
join
(
__dirname
,
'
../../public/manifest.json
'
),
fs
.
readFileSync
(
path
.
join
(
__dirname
,
"
../adapter/firefox/manifest.json
"
)).
toString
().
replace
(
/##version##/g
,
process
.
env
.
npm_package_version
)
);
}
}
const
utoolsConfigWrite
=
()
=>
{
let
fs
=
require
(
'
fs
'
);
// 移除环境配置文件
let
fileArr
=
[
'
plugin.json
'
,
'
README.md
'
]
fileArr
.
forEach
((
file
)
=>
{
let
filePath
=
path
.
join
(
__dirname
,
'
../../public/
'
+
file
);
fs
.
unlink
(
filePath
,
()
=>
{
});
})
const
utoolsConfigWrite
=
{
remove
()
{
removeFile
(
path
.
join
(
__dirname
,
'
../../public/plugin.json
'
));
},
write
()
{
if
(
!
IS_UTOOLS
)
{
return
;
}
if
(
IS_UTOOLS
)
{
const
toolConfig
=
require
(
'
../config
'
)
let
pluginPath
=
path
.
join
(
__dirname
,
'
../../public/plugin.json
'
);
fs
.
readFile
(
path
.
join
(
__dirname
,
"
../adapter/utools/plugin.json
"
),
'
utf8
'
,
function
(
err
,
files
)
{
if
(
err
)
return
console
.
log
(
err
);
let
utoolsToolFeature
=
{};
for
(
let
tool
of
tools
)
{
// 初始化数据
let
code
=
"
ctool-
"
+
tool
.
name
;
let
toolTitle
=
i18nBuild
.
translate
(
`main_tool_
${
tool
.
name
}
`
)
let
toolFeatures
=
featureConfig
.
hasOwnProperty
(
tool
.
name
)
?
featureConfig
[
tool
.
name
]
:
[]
if
(
!
utoolsToolFeature
.
hasOwnProperty
(
code
))
{
utoolsToolFeature
[
code
]
=
{
"
code
"
:
code
,
"
explain
"
:
toolTitle
,
"
cmds
"
:
[]
}
if
(
toolFeatures
.
length
>
0
)
{
for
(
let
toolFeature
of
toolFeatures
)
{
let
toolFeatureCode
=
code
+
'
-
'
+
toolFeature
[
'
name
'
]
utoolsToolFeature
[
toolFeatureCode
]
=
{
"
code
"
:
toolFeatureCode
,
"
explain
"
:
toolTitle
+
'
-
'
+
toolFeature
[
'
title
'
],
"
cmds
"
:
[]
}
}
}
}
// 关键字
let
keyword
=
utoolsConfig
[
'
keyword
'
].
hasOwnProperty
(
tool
.
name
)
?
utoolsConfig
[
'
keyword
'
][
tool
.
name
]
:
[]
utoolsToolFeature
[
code
].
cmds
.
push
(
...
Array
.
from
(
new
Set
([
tool
.
name
,
toolTitle
,
"
ctool-
"
+
tool
.
name
,
...
keyword
]))
)
// cmds手动配置
let
cmds
=
utoolsConfig
[
'
cmds
'
].
hasOwnProperty
(
tool
.
name
)
?
utoolsConfig
[
'
cmds
'
][
tool
.
name
]
:
[]
if
(
!
cmds
.
length
)
{
continue
;
}
for
(
let
_cmd
of
cmds
)
{
let
cmd
=
_
.
cloneDeep
(
_cmd
);
if
(
!
cmd
.
hasOwnProperty
(
'
feature
'
))
{
cmd
[
'
label
'
]
=
toolTitle
utoolsToolFeature
[
code
].
cmds
.
push
(
cmd
)
continue
;
}
let
toolFeatureCode
=
code
+
'
-
'
+
cmd
.
feature
if
(
utoolsToolFeature
.
hasOwnProperty
(
toolFeatureCode
))
{
cmd
[
'
label
'
]
=
toolTitle
+
'
-
'
+
getToolFeatureTitle
(
cmd
.
feature
,
toolFeatures
)
delete
cmd
.
feature
utoolsToolFeature
[
toolFeatureCode
].
cmds
.
push
(
cmd
)
}
}
}
let
features
=
[
{
...
...
@@ -207,13 +46,24 @@ const utoolsConfigWrite = {
"
explain
"
:
"
程序开发常用工具
"
,
"
cmds
"
:
[
'
ctool
'
,
'
程序开发常用工具
'
]
},
...
Object
.
values
(
utoolsToolFeature
)
];
...
toolConfig
.
tool
.
map
((
item
)
=>
{
return
{
"
code
"
:
"
ctool-
"
+
item
.
name
,
"
explain
"
:
item
.
title
,
"
cmds
"
:
[
item
.
name
,
item
.
title
,
"
ctool-
"
+
item
.
name
]
}
})
]
let
result
=
files
.
replace
(
/##version##/g
,
process
.
env
.
npm_package_version
)
.
replace
(
/"##features##"/g
,
JSON
.
stringify
(
features
));
fs
.
writeFileSync
(
pluginPath
,
result
);
fs
.
writeFile
(
pluginPath
,
result
,
'
utf8
'
,
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
);
});
});
let
readmePath
=
path
.
join
(
__dirname
,
'
../../public/README.md
'
);
fs
.
copyFile
(
path
.
join
(
__dirname
,
"
../../README.md
"
),
readmePath
,
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
);
});
}
}
...
...
@@ -221,25 +71,10 @@ const utoolsConfigWrite = {
module
.
exports
=
{
platform
:
platform
,
isChrome
:
IS_CHROME
,
isChromium
:
IS_CHROMIUM
,
isFirefox
:
IS_FIREFOX
,
isEdge
:
IS_EDGE
,
isWeb
:
IS_WEB
,
isUtools
:
IS_UTOOLS
,
initialize
:
function
()
{
// 移除配置文件
chromiumConfigWrite
.
remove
();
chromeConfigWrite
.
remove
();
edgeConfigWrite
.
remove
();
firefoxConfigWrite
.
remove
();
utoolsConfigWrite
.
remove
();
// 添加配置文件
chromiumConfigWrite
.
write
();
chromeConfigWrite
.
write
();
edgeConfigWrite
.
write
();
firefoxConfigWrite
.
write
();
utoolsConfigWrite
.
write
();
// 生成运行时语言包
i18nBuild
.
generate
()
chromeConfigWrite
();
utoolsConfigWrite
();
}
}
}
\ No newline at end of file
src/tool/config.js
浏览文件 @
369a2779
...
...
@@ -6,9 +6,9 @@ export const TOOL_DATA_EXPIRY = 3600 * 24
// 徽章过期时间(天)
export
const
BADGE_EXPIRY
=
10
// 分类徽章
export
const
BADGE_CATEGORY
=
[
'
serialize
'
,
'
other
'
]
export
const
BADGE_CATEGORY
=
[]
// 工具徽章
export
const
BADGE_TOOL
=
[
'
uuid
'
,
'
serializeConversion
'
]
export
const
BADGE_TOOL
=
[]
// 默认常用工具
export
const
DEFAULT_COMMON_TOOL
=
[
'
hash
'
,
'
encrypt
'
,
'
json
'
,
'
base64
'
,
'
url
'
,
'
timestamp
'
,
...
...
@@ -16,37 +16,11 @@ export const DEFAULT_COMMON_TOOL = [
'
decimalConvert
'
,
'
randomString
'
,
'
diffs
'
,
]
const
category
=
[
{
'
name
'
:
'
common
'
,
'
title
'
:
'
常用工具
'
},
{
'
name
'
:
'
encryption
'
,
'
title
'
:
'
加密解密
'
},
{
'
name
'
:
'
conversion
'
,
'
title
'
:
'
编码转换
'
},
{
'
name
'
:
'
serialize
'
,
'
title
'
:
'
序列化
'
},
{
'
name
'
:
'
other
'
,
'
title
'
:
'
其他工具
'
},
]
const
toolConfig
=
require
(
'
../config
'
)
const
tool
=
[
{
'
name
'
:
'
hash
'
,
'
title
'
:
'
哈希(hash)
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
encrypt
'
,
'
title
'
:
'
加密/解密
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
base64
'
,
'
title
'
:
'
BASE64编码
'
,
'
cat
'
:
[
'
encryption
'
]},
{
'
name
'
:
'
json
'
,
'
title
'
:
'
JSON工具
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
url
'
,
'
title
'
:
'
URL编码
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
timestamp
'
,
'
title
'
:
'
时间戳
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
qrCode
'
,
'
title
'
:
'
二维码
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
pinyin
'
,
'
title
'
:
'
汉字转拼音
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
ip
'
,
'
title
'
:
'
IP地址查询
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
code
'
,
'
title
'
:
'
代码格式化
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unicode
'
,
'
title
'
:
'
Unicode
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
decimalConvert
'
,
'
title
'
:
'
进制转换
'
,
'
cat
'
:
[
'
conversion
'
]},
{
'
name
'
:
'
regex
'
,
'
title
'
:
'
正则表达式
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
randomString
'
,
'
title
'
:
'
随机字符生成
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
serializeConversion
'
,
'
title
'
:
'
序列化转换
'
,
'
cat
'
:
[
'
conversion
'
,
'
serialize
'
]},
{
'
name
'
:
'
diffs
'
,
'
title
'
:
'
文本差异化对比
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
crontab
'
,
'
title
'
:
'
crontab校验
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
websocket
'
,
'
title
'
:
'
websocket调试
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
unit
'
,
'
title
'
:
'
单位换算
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
time
'
,
'
title
'
:
'
时间计算器
'
,
'
cat
'
:
[
'
other
'
]},
{
'
name
'
:
'
uuid
'
,
'
title
'
:
'
UUID生成
'
,
'
cat
'
:
[
'
other
'
]},
]
const
category
=
toolConfig
.
category
const
tool
=
toolConfig
.
tool
// 徽章是否显示
const
badgeIsShow
=
function
()
{
...
...
@@ -72,6 +46,15 @@ const getToolTitle = function (name) {
return
''
}
const
getToolDefaultCategory
=
function
(
name
)
{
for
(
let
i
=
0
;
i
<
tool
.
length
;
i
++
)
{
if
(
tool
[
i
].
name
===
name
)
{
return
tool
[
i
].
cat
[
0
]
}
}
return
''
}
const
getSetting
=
function
(
name
,
defaultValue
=
null
)
{
let
setting
=
cache
.
getNoVersion
(
'
setting
'
,
{})
return
!
setting
.
hasOwnProperty
(
name
)
?
defaultValue
:
setting
[
name
]
...
...
@@ -99,6 +82,7 @@ export default {
return
inArray
(
cat
,
t
.
cat
)
})
},
getToolDefaultCategory
,
badgeToolIsShow
(
tool
)
{
return
badgeIsShow
()
&&
inArray
(
tool
,
BADGE_TOOL
)
},
...
...
src/views/setting/block.vue
浏览文件 @
369a2779
<
template
>
<div>
<CellGroup
@
on-click=
"open"
>
<Cell
title=
"常用工具设置"
name=
"setting"
/>
<Cell
title=
"快捷键设置"
name=
"shortcuts"
/>
</CellGroup>
<CellGroup>
<Cell
title=
"自动复制结果到剪贴板"
>
<i-switch
v-model=
"auto_save_copy"
slot=
"extra"
/>
</Cell>
<Cell
title=
"自动读取剪贴板内容"
>
<i-switch
v-model=
"auto_read_copy"
slot=
"extra"
/>
</Cell>
</CellGroup>
<div>
<CellGroup
@
on-click=
"open"
>
<Cell
title=
"常用工具设置"
name=
"setting"
/>
<Cell
v-if=
"isChrome"
title=
"快捷键设置"
name=
"shortcuts"
/>
</CellGroup>
<CellGroup>
<Cell
title=
"自动复制结果到剪贴板"
>
<i-switch
v-model=
"auto_save_copy"
slot=
"extra"
/>
</Cell>
<Cell
title=
"自动读取剪贴板内容"
>
<i-switch
v-model=
"auto_read_copy"
slot=
"extra"
/>
</Cell>
</CellGroup>
</div>
<Drawer
title=
"设置"
placement=
"left"
v-model=
"settingShow"
:width=
"90"
>
<setting-block
v-if=
"settingShow"
></setting-block>
</Drawer>
</div>
</
template
>
<
script
>
import
{
openTab
}
from
'
../../helper
'
import
{
openTab
,
isChrome
}
from
'
../../helper
'
import
setting
from
'
../../tool/setting
'
import
settingBlock
from
'
./setting
'
export
default
{
components
:
{
"
setting-block
"
:
settingBlock
},
data
()
{
return
{
settingShow
:
false
,
auto_save_copy
:
true
,
auto_read_copy
:
true
,
isChrome
:
isChrome
,
}
},
created
()
{
...
...
@@ -42,7 +53,7 @@ export default {
openTab
(
'
chrome://extensions/shortcuts
'
)
break
case
'
setting
'
:
openTab
(
'
/setting.html
'
)
this
.
settingShow
=
true
break
}
},
...
...
vue.config.js
浏览文件 @
369a2779
const
adapter
=
require
(
'
./src/tool/adapter
'
);
const
pages
=
{
tool
:
{
entry
:
'
src/tool.js
'
,
template
:
'
public/tool.html
'
,
}
}
let
adapter
=
require
(
'
./src/tool/adapter
'
);
const
config
=
{
productionSourceMap
:
false
,
publicPath
:
"
./
"
,
pages
:
pages
,
productionSourceMap
:
true
,
publicPath
:
"
./
"
,
pages
:
{
tool
:
{
entry
:
'
src/tool.js
'
,
template
:
'
public/tool.html
'
,
}
},
chainWebpack
:
config
=>
{
config
.
plugin
(
'
define
'
).
tap
(
args
=>
{
args
[
0
][
'
process.ctool
'
]
=
JSON
.
stringify
({
...
...
@@ -16,61 +16,12 @@ const config = {
updateTime
:
Date
.
parse
((
new
Date
()).
toString
())
/
1000
,
platform
:
adapter
.
platform
,
isChrome
:
adapter
.
isChrome
,
isFirefox
:
adapter
.
isFirefox
,
isEdge
:
adapter
.
isEdge
,
isChromium
:
adapter
.
isChromium
,
isWeb
:
adapter
.
isWeb
,
isUtools
:
adapter
.
isUtools
,
});
return
args
})
if
(
process
.
env
.
NODE_ENV
===
'
production
'
){
// 独立打包js 防止js文件过大 影响相关平台审核
config
.
optimization
.
splitChunks
({
cacheGroups
:
{
codemirror
:
{
test
:
/
[\\/]
node_modules
[\\/]
codemirror
[\\/]
/
,
name
:
'
codemirror
'
,
chunks
:
'
all
'
,
priority
:
100
,
reuseExistingChunk
:
true
,
enforce
:
true
},
prettier
:
{
test
:
/
[\\/]
node_modules
[\\/](
prettier|@prettier|prettier-plugin-sql|sql-formatter
)[\\/]
/
,
name
:
'
prettier
'
,
chunks
:
'
all
'
,
priority
:
99
,
reuseExistingChunk
:
true
,
enforce
:
true
},
prettierParserTypescript
:
{
test
:
/
[\\/]
node_modules
[\\/]
prettier
[\\/]
parser-typescript
\.
js/
,
name
:
'
prettier-parser-typescript
'
,
chunks
:
'
all
'
,
priority
:
100
,
reuseExistingChunk
:
true
,
enforce
:
true
},
nodeSqlQarser
:
{
test
:
/
[\\/]
node_modules
[\\/](
node-sql-parser
)[\\/]
/
,
name
:
'
node-sql-qarser
'
,
chunks
:
'
all
'
,
priority
:
100
,
reuseExistingChunk
:
true
,
enforce
:
true
},
uglify
:
{
test
:
/
[\\/]
src
[\\/]
views
[\\/]
tool
[\\/]
library
[\\/]
formatter
[\\/]
uglify
\.
js/
,
name
:
'
uglify
'
,
chunks
:
'
all
'
,
priority
:
100
,
enforce
:
true
}
}
})
}
}
},
};
adapter
.
initialize
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录