单击扩展程序图标或“ 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标签页网址匹配,则需要执行此扩展程序
http://club.pchome.net/thread_1_15_6865723__.html
它将打开一个新标签页,该标签页未激活(在后台),并带有如下所示的新网址。数字6865723在不同页面中有所不同。其他是固定的。
http://wap.kdslife.com/t/1/15/6865723/?u=0&sc=235&rnd=0359251496
原始脚本来自(https://github.com/guiwuu/guiwuu/tree/master/chrome/linkmv)
最佳答案
尝试window.open,
代替:
document.location.href=document.location.href.replace(club.pchome.net/thread_1_15_,"wap.kdslife.com/t/1/15/");
尝试这个:
var url =document.location.href.replace(club.pchome.net/thread_1_15_,"wap.kdslife.com/t/1/15/";
window.open(url);
window.focus(); //send back the focus to the current window
注意:这可能会被浏览器首选项设置覆盖。