ウェブページでの名前の出現をすべて変更するChromeの拡張機能を作成しようとしています。(たとえば、ページに「that」という単語が含まれている場合は、別の名前に変更されます)。
アイデアは、ユーザーがブラウザのボタンをクリックしたときにこの変更を加えることです。
私の問題は、それが変更を加えないことです!何が間違っているのかわかりません。
これがmanifest.jsonです:
{
"name": "App Name",
"description": "App description",
"version": "1.0",
"background": {
"scripts": ["jquery.min.js", "jquery.ba-replacetext.min.js","background.js"]
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "App name",
"default_icon": "icon.png"
},
"manifest_version": 2
}
そして、これがbackground.jsです:
chrome.browserAction.onClicked.addListener(function(tab) {
var state = document.readyState;
var carregou = false;
var matches = document.body.innerText.match(regex);
if (state == "interactive"|| (!carregou)){
$("body *").replaceText( /That/gi, "" );
var regex = /That/gi;
matches = document.body.innerText.match(regex);
if(matches){
alert("Reload the page (f5)");
}else{
alert("All changes done! :D");
carregou = true;
}
}
});
ブラウザのボタンをクリックせずにページを変更するものを実行しましたが、機能します。コードは次のとおりです。
{
"name": "App Name",
"version": "1.0",
"manifest_version": 2,
"description": "App description.",
"content_scripts": [
{
"matches": ["http://www.facebook.com/*"],
"js": ["jquery.min.js","jquery.ba-replacetext.min.js", "script.js"],
"run_at": "document_end"
}
]
}
sript.js:
var state = document.readyState;
var carregou = false;
var matches = document.body.innerText.match(regex);
if (state == "interactive"|| (!carregou)){
$("body *").replaceText( /That/gi, "" );
var regex = /That/gi;
matches = document.body.innerText.match(regex);
if(matches){
alert("Reload the pahe (f5)");
}else{
alert("All changes done! :D");
carregou = true;
}
}
Chromeバージョン:Windows7で23.0.1271.95mありがとうございます!