Chrome의 확장 프로그램을 사용하여 웹 페이지에서 이름의 모든 변경 사항을 변경하려고합니다. 예를 들어 페이지에 단어 "그"가 있으면 다른 이름으로 바뀝니다.사용자가 브라우저 버튼을 클릭 할 때 DOM을 변경하는 Chrome 확장자
아이디어는 사용자가 브라우저 버튼을 클릭 할 때 변경되도록하는 것입니다.
내 문제는 변경하지 않는다는 것입니다. 나는 내가 무엇을 잘못하고 있는지 전혀 모른다.
여기 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;
}
}
크롬 버전 : 윈도우 7 에 23.0.1271.95 m 감사합니다!
감사합니다. 그래, 나는 그 점을 놓쳤다. 그러나 조금 당황 스럽지만 여전히 작동하게 만들 수는 없습니다.() 함수 (탭 { chrome.tabs.executeScript (널 (null), {파일 : "content.js"}); \t \t \t }) chrome.browserAction.onClicked.addListener : 나는 이런 짓을; 파일의 코드가 실행되지 않는 것 같습니다. 그러나 어쨌든, 나는 당신에게 피드백을주기 위해 여기에 게시합니다. 다시 한 번 감사드립니다! : D – dehq
좋아요, 당신은 배경 페이지를 등록하는 것을 잊어 버렸습니다. "배경"처럼 나타납니다 : { "scripts": [ "background.js "] },' – Sudarshan