처음으로 사용자에게 이메일과 비밀번호를 묻는 작업 자바 스크립트가 있습니다. 이후에 사용자가 해당 웹 페이지를 다시 방문 할 때마다 사용자 이름과 암호가 자동 완성됩니다. 내 HTML 코드에서는 JSFiddle.net에서 checkCookie() 함수를 호출해야한다.Chrome 확장 프로그램에서 자동 완성 자바 스크립트 실행
클릭하면 자동 완성 JS가 실행되는 Chrome 확장 프로그램을 만들고 싶습니다. 이 코드가 있지만 확장명을 클릭하면 출력이 없습니다. 아무도 내가 뭘 잘못하고 있는지 제안 해 줄 수 없어요.
// manifest.json
{
"manifest_version": 2,
"name": "Auto-fill Passwords",
"description": "This extension autofill password on click.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
}
}
// background.js
chrome.browserAction.onClicked.addListener(function (tab)
{ //Fired when User Clicks ICON
chrome.tabs.executeScript(tab.id, {
"file": "autofill.js"
}, function() {
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function checkCookie() {
var username = prompt("Please enter your name:", "");
var n= getCookie("username",username);
if(n)
{
alert("UserID Match! The user's password is " +n) ;
}
else
{
//alert("UserID password doesnot exist ");
var password = prompt("Please enter your password:", "");
username += "!";
username += password;
alert("Username = "+ username);
setCookie("username", username, 365);
}
}
console.log("Script Executed .. "); // Notification on Completion
});
}
});
//autofill.js
alert("Check cookie function is called");
checkCookie();
앞에서 콘텐츠 스크립트의 사용을 사용했지만 어디 선가 읽고 이 작업을 위해 background.js를 사용하는 것이 더 좋습니다. 좋은 제안을 찾고 있습니다. 읽어 주셔서 감사합니다 –