提交 3b7db145 编写于 作者: B baiy 提交者: ninecents

初步支持utools

上级 8cc2cdb2
......@@ -3,6 +3,8 @@
/desktop/node_modules
/dist
/public/manifest.json
/public/plugin.json
/public/README.md
/id_rsa.pem
# local env files
......
# 程序开发常用工具
使用过程中的任何问题或者需要新的工具欢迎提交`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
## 功能列表
|功能|说明|离线使用|
|---|---|---|
......
{
"name": "c-tool",
"version": "1.4.3",
"version": "1.4.4",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --port 8081",
......
<!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>设置</title>
</head>
<body>
<div style="width: 1000px;margin: 0 auto;padding: 0 20px">
<div id="app"></div>
</div>
</body>
</html>
<!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
......@@ -12,7 +12,6 @@
"default_title": "常用开发工具",
"default_popup": "index.html"
},
"options_page": "setting.html",
"icons": {
"16": "img/icon128.png",
"48": "img/icon128.png",
......
{
"pluginName": "Ctool",
"description": "Ctool 程序开发常用工具",
"author": "baiy",
"homepage": "https://github.com/baiy/Ctool",
"main": "utools.html",
"version": "##version##",
"logo": "img/icon128.png",
"pluginSetting": {
"single": true
},
"features": "##features##",
"development": {
"main": "http://localhost:8081/utools.html"
}
}
\ No newline at end of file
const category = [
{'name': 'common', 'title': '常用工具'},
{'name': 'encryption', 'title': '加密解密'},
{'name': 'conversion', 'title': '编码转换'},
{'name': 'serialize', 'title': '序列化'},
{'name': 'other', 'title': '其他工具'},
]
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']},
{'name': 'jsonToObject', 'title': 'JSON转实体类', 'cat': ['conversion', 'serialize']},
]
module.exports = {
category,
tool
}
\ No newline at end of file
import {stringify as queryStringify} from "query-string"
export const env = function (key) {
return process['ctool'][key] ? process['ctool'][key] : "";
};
export const isChrome = !!env('isChrome')
export const isWeb = !!env('isWeb')
export const isUtools = !!env('isUtools')
export const trim = function (str, char, type) {
if (char) {
if (type === 'left') {
......@@ -19,14 +27,13 @@ export const inArray = function (value, arr) {
};
export const openTab = function (url) {
if (!chrome.tabs) {
return window.open(url);
if (isChrome && chrome.tabs) {
return chrome.tabs.create({url: url, selected: true});
}
chrome.tabs.create({url: url, selected: true});
};
export const env = function (key) {
return process['ctool'][key] ? process['ctool'][key] : "";
if (isUtools && window.utools){
return window.utools.shellOpenExternal(url)
}
return window.open(url);
};
export const stat = function (action, data = {}) {
......
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');
......@@ -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),
......
......@@ -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()
......
let path = require('path');
// 运行平台适配
let platform = process.env.hasOwnProperty('npm_config_adapter') ? process.env.npm_config_adapter : "";
platform = ["chrome", 'utools'].includes(platform) ? platform : "web"
const IS_CHROME = "chrome" === platform
const IS_UTOOLS = "utools" === platform
const IS_WEB = "web" === platform
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);
});
});
}
}
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, () => {
});
})
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 features = [
{
"code": "ctool",
"explain": "程序开发常用工具",
"cmds": ['ctool', '程序开发常用工具']
},
...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.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);
});
}
}
module.exports = {
platform: platform,
isChrome: IS_CHROME,
isWeb: IS_WEB,
isUtools: IS_UTOOLS,
initialize: function () {
chromeConfigWrite();
utoolsConfigWrite();
}
}
\ No newline at end of file
......@@ -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)
},
......
<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
}
},
......
......@@ -8,7 +8,7 @@
</Card>
</template>
<script>
import common from "./views/setting/common"
import common from "./common"
export default {
components: {
"setting-common": common
......
let adapter = require('./src/tool/adapter');
const config = {
productionSourceMap: true,
publicPath:"./",
pages: {
tool: {
entry: 'src/tool.js',
template: 'public/tool.html',
},
setting: {
entry: 'src/setting.js',
template: 'public/setting.html',
}
},
chainWebpack: config => {
config.plugin('define').tap(args => {
args[0]['process.ctool'] = JSON.stringify({
version: process.env.npm_package_version,
updateTime: Date.parse((new Date()).toString())/1000,
updateTime: Date.parse((new Date()).toString()) / 1000,
platform: adapter.platform,
isChrome: adapter.isChrome,
isWeb: adapter.isWeb,
isUtools: adapter.isUtools,
});
return args
})
},
};
let fs = require('fs');
fs.readFile('./src/manifest.json', 'utf8', function (err, files) {
let result = files.replace(/##version##/g, process.env.npm_package_version);
fs.writeFile('./public/manifest.json', result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
adapter.initialize()
module.exports = config;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册