对于Google Chrome扩展程序,我需要捕获网页中的选定文本并发送到网络服务.我被卡住了!
首先我尝试了一个书签,但Mac上的Chrome似乎有一些书签错误,所以我决定写一个扩展名.
我在我的分机中使用此代码:
function getSelText(){
var txt = 'nothing';
if (window.getSelection){
txt = "1" + window.getSelection();
} else if (document.getSelection) {
txt = "2" + document.getSelection();
} else if (document.selection) {
txt = "3" + document.selection.createRange().text;
} else txt = "wtf";
return txt;
}
var selection = getSelText();
alert("selection = " + selection);
Run Code Online (Sandbox Code Playgroud)
当我点击我的扩展图标时,我得到一个"1".所以我认为在浏览器窗口之外选择的行为导致浏览器不再将文本视为"已选择".
只是一个理论....
想法?
我正在尝试为Chrome扩展程序添加一些键盘快捷键,特别是允许用户使用热键打开浏览器操作/弹出窗口.我已阅读文档,并将以下代码行添加到manifest.json文件中:
"commands": {
"_execute_browser_action": {
"suggested_key": {
"windows": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y",
"chromeos": "Ctrl+Shift+U",
"linux": "Ctrl+Shift+J"
}
}
}
Run Code Online (Sandbox Code Playgroud)
添加完这个后,我在chrome:// extensions中重新加载了我的扩展程序,然后在我的Mac上试用了Command+ Shift+ ,没有任何反应.大约2个小时,我尝试在manifest.json中设置不同的热键组合,但没有一个工作.我从开发版Chrome转换到稳定版但无济于事.当我进入chrome://扩展并点击右下角的"键盘快捷键"按钮时,我能够手动设置热键组合,然后就可以了.但我不希望用户必须做那个手工工作.Y
知道我如何在Mac上运行Chrome扩展键盘快捷键吗?我在manifest.json中有这个
"commands": {
"trigger_me": {
"suggested_key": {
"default": "Ctrl+E"
},
"description": "Trigger test"
}
}
Run Code Online (Sandbox Code Playgroud)
当我查看键盘快捷键下的Chrome扩展程序标签时,我可以看到"触发器测试"条目,但未设置实际的快捷方式.
如何通过manifest.json设置默认快捷方式?
我正在构建Google Chrome扩展程序,我正在尝试在弹出窗口中显示所选窗口.(我说的是当你点击扩展图标时显示的弹出窗口).
我试图使用文档,但我不太了解它.具体来说,我试图使用:
chrome.windows.getCurrent(function(w) {
chrome.windows.get(w.id,
function (response){
alert(response.location.href);
});
});
Run Code Online (Sandbox Code Playgroud)
但它没有用.有任何想法吗?
谢谢(抱歉,如果英语不好).