Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update content.js #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ document.onkeyup = (e) => {
}
}

function escapeChars(str) {
// 替换<, >, {, }, (, ), ;字符为实体字符
return str.replace(/[<>{}();]/g, function(match) {
switch (match) {
case '<':
return '&lt;';
case '>':
return '&gt;';
case '{':
return '&#123;';
case '}':
return '&#125;';
case '(':
return '&#40;';
case ')':
return '&#41;';
case ';':
return '&#59;';
default:
return match;
}
});
}

$(document).ready(() => {
var actions = [];
var isFiltered = false;
Expand Down Expand Up @@ -98,9 +122,9 @@ $(document).ready(() => {
img = "<span class='omni-emoji-action'>"+action.emojiChar+"</span>"
}
if (index != 0) {
return $("<div class='omni-item' data-index='"+index+"' data-type='"+action.type+"' data-url='"+action.url+"'>"+img+"<div class='omni-item-details'><div class='omni-item-name'>"+action.title+"</div><div class='omni-item-desc'>"+action.url+"</div></div>"+keys+"<div class='omni-select'>Select <span class='omni-shortcut'>⏎</span></div></div>")[0]
return $("<div class='omni-item' data-index='"+index+"' data-type='"+action.type+"' data-url='"+escapeChars(action.url)+"'>"+img+"<div class='omni-item-details'><div class='omni-item-name'>"+action.title+"</div><div class='omni-item-desc'>"+action.url+"</div></div>"+keys+"<div class='omni-select'>Select <span class='omni-shortcut'>⏎</span></div></div>")[0]
} else {
return $("<div class='omni-item omni-item-active' data-index='"+index+"' data-type='"+action.type+"' data-url='"+action.url+"'>"+img+"<div class='omni-item-details'><div class='omni-item-name'>"+action.title+"</div><div class='omni-item-desc'>"+action.url+"</div></div>"+keys+"<div class='omni-select'>Select <span class='omni-shortcut'>⏎</span></div></div>")[0]
return $("<div class='omni-item omni-item-active' data-index='"+index+"' data-type='"+action.type+"' data-url='"+escapeChars(action.url)+"'>"+img+"<div class='omni-item-details'><div class='omni-item-name'>"+action.title+"</div><div class='omni-item-desc'>"+action.url+"</div></div>"+keys+"<div class='omni-select'>Select <span class='omni-shortcut'>⏎</span></div></div>")[0]
}
}
actions.length && new VirtualizedList.default($("#omni-extension #omni-list")[0], {
Expand Down