2012-02-22 7 views
1

拡張機能アイコンまたは「Shift + Ctrl + K」キーをクリックしたときにこの機能を実行するにはどうすればよいですか?Chromeで既存のリンクを使用して新しいタブを自動作成するにはどうすればよいですか?

$(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を、それが(バックグラウンドで)アクティブでない新しいタブを開きます

http://club.pchome.net/thread_1_15_6865723__.html 

クロームタブのURLが一致した場合、次の操作を実行するために

{ 
    "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 
    }] 
} 

この拡張機能です次のような新しいURLで番号6865723はページによって異なります。その他は修正されています。

http://wap.kdslife.com/t/1/15/6865723/?u=0&sc=235&rnd=0359251496 

https://github.com/guiwuu/guiwuu/tree/master/chrome/linkmv

+0

このスクリプトの目的は何ですか?ブラウザのハイジャックのように聞こえる。 –

+0

最初のページはデスクトップ用のHTML形式で、2番目のページはフォーラム用のモバイル形式です。私は自動的に携帯電話で読み取ることができ、私の友人に送信することができるURLにデスクトップのHTMLバージョンを変換します。それはです:-) – user1225183

答えて

0

するTry 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 

注:これはブラウザの設定で上書きされる可能性があります。

+0

また、 'if(href!= undefined && href.indexOf(" club.pchome.net/thread_1_15 _^\ d {7} $ __。html ")== - 1)'を ' if(href!= undefined && href.indexOf( "club.pchome.net/thread_1_15 _")!= - 1) ' – PAEz

関連する問題