由于某种原因,我似乎无法将元素的值设置为引号中的文本以外的任何值。我一去:
hiddenField1.setAttribute("值", localStorage.curl);
或任何类似的东西,它只是无法加载页面并设置属性。
完整代码:
var curl = localStorage["curl"];
var username = localStorage["username"];
var password = localStorage["password"];
function fakePost() {
var form = document.createElement("form");
form.setAttribute("name", "form1");
form.setAttribute("id", "form1");
form.setAttribute("method", "post");
form.setAttribute("action", "http://SNIPURLlogin&action=login");
var hiddenField1 = document.createElement("input");
hiddenField1.setAttribute("type", "hidden");
hiddenField1.setAttribute("name", "short");
hiddenField1.setAttribute("id", "short");
hiddenField1.setAttribute("value", localStorage["curl"]);
form.appendChild(hiddenField1);
var hiddenField2 = document.createElement("input");
hiddenField2.setAttribute("type", "hidden");
hiddenField2.setAttribute("name", "txtUsername");
hiddenField2.setAttribute("id", "txtUsername");
hiddenField2.setAttribute("value", "shane");
form.appendChild(hiddenField2);
var hiddenField3 = document.createElement("input");
hiddenField3.setAttribute("type", "hidden");
hiddenField3.setAttribute("name", "txtPassword");
hiddenField3.setAttribute("id", "txtPassword");
hiddenField3.setAttribute("value", "shane");
form.appendChild(hiddenField3);
document.body.appendChild(form);
form.submit();
};
//minify function
fakePostCode = fakePost.toString().replace(/(\n|\t)/gm,'');
chrome.browserAction.onClicked.addListener(function (t) {
chrome.tabs.create({"url" : "javascript:"+fakePostCode+"; fakePost();"});
});