1、屏幕取色设置快捷键alt+cmd+p
2、咖啡因设置快捷键alt+cmd+c
3、json 解析界面修改,触发快捷键同时复制选中的文本
This commit is contained in:
sugood
2022-01-09 13:14:59 +08:00
parent c8ba9c953f
commit ef592e4267
11 changed files with 69 additions and 1046 deletions
+25 -11
View File
@@ -4,7 +4,7 @@
--- DateTime: 2020/10/24 14:13
---
local console = require("hs.console")
version = "v0.1.2"
version = "v0.1.3"
configPath= "~/.hammerspoon/data/config.json"
initConfigPath= "~/.hammerspoon/data/initConfig.json"
config = {}
@@ -124,15 +124,7 @@ function initMenu()
end },
{ title = "-" },
{ title = "屏幕取色", fn = function()
hs.openConsole(true)
colorDialog.show()
colorDialog.mode("RGB")
colorDialog.callback(function(a,b)
if b then
hs.closeConsole()
end
end)
hs.closeConsole()
openColorDialog()
end },
{ title = "-" },
{ title = "咖啡因:" .. config[1].caffeine, fn = function()
@@ -259,4 +251,26 @@ function isCopySuccess()
local numAfter = hs.pasteboard.changeCount()
print("复制后数量:"..numAfter)
return numAfter > num
end
end
function openColorDialog()
hs.openConsole(true)
colorDialog.show()
colorDialog.mode("RGB")
colorDialog.callback(function(a,b)
if b then
hs.closeConsole()
end
end)
hs.closeConsole()
end
--设置颜色拾取快键键
hs.hotkey.bind(hyperCmd, "P", function ()
openColorDialog()
end)
--设置颜色拾取快键键
hs.hotkey.bind(hyperCmd, "C", function ()
switchCaffeine()
end)
+9 -150
View File
@@ -6,154 +6,6 @@
--
--
local function generateHtml()
local html = [[
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Json格式化高亮展示工具</title>
<style>
body { height: 100%; margin:0; font-family:"微软雅黑"; font-size:12px; }
.pdiv { height: 85%; position: absolute; }
.title { height: auto; font-size:20px; text-align:center; margin-top: 5px; margin-bottom: 20px;}
.author { height: auto; width: 100%; font-size:12px; text-align:center; margin-top: 30px; margin-bottom: 20px;}
table { height: 100%; width:100%; border-collapse:collapse; }
table .tdLeft { width:85%; text-align:left; padding-left: 10px;padding-right: 10px;}
table .tdmid { width:150px; text-align:center; margin: 0px; padding: 0px;}
table .tdRight { width:85%; padding-right: 30px;text-align:left; }
table textarea { width:100%; height:100%; font-size:14px; padding-top: 10px; padding-left: 10px; outline: none; border-radius: 15px; border: 2px solid #8AC007; }
#container { width:100%; height:100%; font-size:14px; padding-top: 10px; padding-left: 10px; border-radius: 15px; border: 2px solid #8AC007;}
pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; margin: 0px; padding: 5px;}
pre .string { color: green; }
pre .number { color: darkorange; }
pre .boolean { color: blue; }
pre .null { color: magenta; }
.key { color: red; }
</style>
</head>
<body>
<div class="pdiv">
<div class="title" >Json格式化高亮展示工具</div>
<table style="table-layout:fixed">
<tr>
<!-- <td class="tdLeft" nowrap>请输入要展示的Json:</td> -->
<td class="tdLeft">
<input style="width:auto; margin: 10px;" type="button" value="复制" onClick="copySource()">
<textarea name = "jsonContent" id="jsonContent" ></textarea>
</td>
<td class="tdmid"><input style="width:80%;" type="button" value="格式化JSON >>" onClick="showJson()"></td>
<td class="tdRight">
<input style="width:auto; margin: 10px;" type="button" value="复制" onClick="copyResult()">
<pre id="container"></pre>
</td>
</tr>
</table>
<div class="author">
<a href="https://github.com/sugood" target="_blank">By: github.com/sugood</a>
</div>
<div class="tips" id="tips">
</div>
</div>
</body>
<script type="text/javascript">
function copySource(){
var obj = document.getElementById('jsonContent');
//选择当前对象
obj.select();
try{
if(document.execCommand("Copy","false",null)){
alert("复制成功!");
}
}catch(err){
alert("复制错误!");
}
}
function copyResult(){
var text = document.getElementById('container').innerText;
const input = document.createElement('textarea');
input.value = text;
input.setAttribute('readonly', 'readonly');
document.body.appendChild(input);
input.select();
try{
if(document.execCommand('Copy')){
alert('复制成功');
}
}catch(err){
alert("复制错误!");
}
document.body.removeChild(input);
}
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 4);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
function showJson(){
var text = document.getElementById('jsonContent').value
if (text!="" && text!=null){
try {
var result = JSON.stringify(JSON.parse(text), null, 4);//将字符串转换成json对象
highLineResult = syntaxHighlight(result);
document.getElementById('container').innerHTML= highLineResult;
localStorage.setItem("jsonFormatSource",text);
localStorage.setItem("jsonFormatResult",highLineResult);
} catch(e) {
document.getElementById('container').innerText= '异常信息:'+e ;
}
}else{
document.getElementById("jsonContent").value = "请输入json文本";
document.getElementById('container').innerHTML= "显示Json格式化后的效果";
localStorage.setItem("jsonFormatSource","请输入json文本");
localStorage.setItem("jsonFormatResult","显示Json格式化后的效果");
}
  };
var jsonFormatSource = localStorage.getItem("jsonFormatSource");
if (jsonFormatSource!="" && jsonFormatSource!=null){
document.getElementById("jsonContent").value=localStorage.getItem("jsonFormatSource");
}else{
document.getElementById("jsonContent").value = "请输入json文本"
}
var jsonFormatResult = localStorage.getItem("jsonFormatResult");
if (jsonFormatResult!="" && jsonFormatResult!=null){
document.getElementById("container").innerHTML=localStorage.getItem("jsonFormatResult");
}else{
document.getElementById("jsonContent").value = "显示Json格式化后的效果"
}
</script>
</html>
]]
return html
end
--- KSheet:hide()
--- Method
--- Hide the cheatsheet view.
@@ -187,8 +39,11 @@ end
--- Method
--- Show current application's keybindings in a view.
function show(time)
local webcontent = generateHtml()
sheetView:html(webcontent, "http://localhost")
bindCopyKey()
local str = hs.pasteboard.getContents()
-- local webcontent = generateHtml()
-- sheetView:html(webcontent, "http://localhost")
sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
sheetView:show(time)
end
@@ -202,6 +57,10 @@ end
init()
-- 按下添加快捷键时映射到复制快捷键
function bindCopyKey()
hs.eventtap.keyStroke({ "cmd" }, "C")
end
-- 添加片段(按下快捷键时做一个复制操作,并记录复制的内容到片段列表中)
hs.hotkey.bind(hyperCmd, "G", function ()
toggle()