如何在 Chrome 中使用现有链接自动创建新选项卡?
当我点击扩展图标或按键“Shift+Ctrl+K”时,如何使该功能运行?
$(document).bind('keydown', 'shift+ctrl+k', function replaceWeiboLink()
{
这个 content.js 似乎不起作用。
$(document).bind('keydown', 'shift+ctrl+k', function replaceWeiboLink()
{
var url = document.location.href;
if (url != undefined && url.indexOf("club.pchome.net/thread_1_15_")!=-1)
{
url = url.replace("club.pchome.net/thread_1_15_","wap.kdslife.com/t/1/15/");
url = url.replace("__.html","/?u=0&sc=235&rnd=0359251496");
window.open(url);
window.focus(); //send back the focus to the current window
}
window.setTimeout(replaceWeiboLink, 100);
});
仅焦点位于新页面上,而不是打开选项卡作为背景。该字符串不起作用,有什么想法吗?
window.focus(); //send back the focus to the current window
我的manifest.json是
{
"name": "linkmv",
"version": "0.1",
"description": "linkmv",
"icons": {
"48": "icon.png"
},
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs",
"http://*/*"
],
"content_scripts": [ {
"matches": ["http://*.club.pchome.net/*"],
"js": ["content.js"],
"all_frames": true
}]
}
这个扩展程序,如果Chrome选项卡url匹配,
http://club.pchome.net/thread_1_15_6865723__.html
它将打开一个不活动的新选项卡(在后台),新的url如下所示。 6865723这个数字在不同的页面是不同的。其他的都是固定的。
http://wap.kdslife.com/t/1/15/6865723/?u=0&sc=235&rnd=0359251496
原始脚本来自 (https://github.com/guiwuu/guiwuu/tree/主/chrome/linkmv)
How can I make this function run when I click on the extension icon or key "Shift+Ctrl+K"?
$(document).bind('keydown', 'shift+ctrl+k', function replaceWeiboLink()
{
This content.js seems does not work.
$(document).bind('keydown', 'shift+ctrl+k', function replaceWeiboLink()
{
var url = document.location.href;
if (url != undefined && url.indexOf("club.pchome.net/thread_1_15_")!=-1)
{
url = url.replace("club.pchome.net/thread_1_15_","wap.kdslife.com/t/1/15/");
url = url.replace("__.html","/?u=0&sc=235&rnd=0359251496");
window.open(url);
window.focus(); //send back the focus to the current window
}
window.setTimeout(replaceWeiboLink, 100);
});
Only the focus was on the new page, not opening tab as background. This string is not working, any idea?
window.focus(); //send back the focus to the current window
my manifest.json is
{
"name": "linkmv",
"version": "0.1",
"description": "linkmv",
"icons": {
"48": "icon.png"
},
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs",
"http://*/*"
],
"content_scripts": [ {
"matches": ["http://*.club.pchome.net/*"],
"js": ["content.js"],
"all_frames": true
}]
}
This extension to do following, if the Chrome tab url match
http://club.pchome.net/thread_1_15_6865723__.html
it will open a new tab not active(in background) with the new url like following. The number 6865723 is different in different pages. Others are fixed.
http://wap.kdslife.com/t/1/15/6865723/?u=0&sc=235&rnd=0359251496
Original script come from (https://github.com/guiwuu/guiwuu/tree/master/chrome/linkmv)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 window.open,
而不是:
尝试这个:
注意:这可能会被浏览器首选项设置覆盖。
Try window.open,
instead of:
try this:
NOTE: this might be overridden by a browser preference settings.