下载列表
简要说明
copyq的脚本本质上是javascript,但是copyq会把脚本经过特殊处理之后转换为专用的ini格式。因此本文既保留ini文件又保留js代码文件。其中,js文件第一行必须是copyq:
。
建议先在vscode中写好js脚本,然后在copyq中按F6
,点击“添加脚本”,然后在右下角勾选“显示高级”,把代码粘贴进去,并在代码框上面选择全局快捷键,最后导出用于分享。
脚本功能说明和原始代码
自动合并换行
用于把从pdf文件复制的多行文本按行尾的句号、问号和感叹号合并为段落。
copyq:
function isAlphaNumeric(s) {
return /^[a-zA-Z0-9]+$/.test(s);
}
function mergeLinesIntoParagraph(text) {
const paragraphEndFlags = ['.', '!', '?', '?', '!', '。'];
const lines = text.split('\n').map(str => str.trim()).filter(str => str !== '');
const paragraphs = [];
var currentParagraph = '';
for (var i = 0; i < lines.length; i++) {
const line = lines[i];
// 检查行尾字符是否为句号
const lastChar = line.charAt(line.length - 1);
const isEndOfSentence = paragraphEndFlags.indexOf(lastChar) > -1;
//将该行添加到当前段落,英文要加空格
currentParagraph += line + (isAlphaNumeric(lastChar) ? ' ' : '');
if (isEndOfSentence) {
// 如果是句号或逗号,则将当前段落添加到合并后的行数组,并重置当前段落
paragraphs.push(currentParagraph.trim());
currentParagraph = '';
}
}
// 添加最后一个段落到合并后的行数组F
paragraphs.push(currentParagraph.trim());
const mergedText = paragraphs.join('\n');
return mergedText;
}
var mytext = str(clipboard('text/plain'));
if (mytext) {
tab(selectedtab());
myindex = index() + 1;
write(myindex, 'text/plain', mergeLinesIntoParagraph(mytext));
select(myindex);
paste();
}