📄 gvuserreg.js
字号:
ratingMsgs = new Array(6);
ratingMsgColors = new Array(6);
barColors = new Array(6);
ratingMsgs[0] = "太短0";
ratingMsgs[1] = "弱1";
ratingMsgs[2] = "一般2";
ratingMsgs[3] = "很好3";
ratingMsgs[4] = "极佳4";
ratingMsgs[5] = "未评级5"; //If the password server is down
ratingMsgColors[0] = "#676767";
ratingMsgColors[1] = "#aa0033";
ratingMsgColors[2] = "#f5ac00";
ratingMsgColors[3] = "#6699cc";
ratingMsgColors[4] = "#008000";
ratingMsgColors[5] = "#676767";
barColors[0] = "#dddddd";
barColors[1] = "#aa0033";
barColors[2] = "#ffcc33";
barColors[3] = "#6699cc";
barColors[4] = "#008000";
barColors[5] = "#676767";
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all && !is_op;
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
if (is_ie) {
// Guaranteed to be ie5 or ie6
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
try {
xmlhttp = new ActiveXObject(control);
xmlhttp.onreadystatechange = handler;
} catch (ex) {
// TODO: better help message
alert("You need to enable active scripting and activeX controls");
}
} else {
// Mozilla
xmlhttp = new XMLHttpRequest();
xmlhttp.onload = handler;
xmlhttp.onerror = handler;
}
return xmlhttp;
}
// XMLHttp send POST request
function XmlHttpPOST(xmlhttp, url, data) {
try {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(data);
} catch (ex) {
// do nothing
}
}
// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
try {
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
} catch (ex) {
// do nothing
}
}
function CreateRatePasswdReq(formKey) {
if (!isBrowserCompatible) {
return;
}
var passwd = document.forms[formKey]["UserPassword"].value;
if (document.forms[formKey]["Email"]) {
var email = getUserName(document.forms[formKey]["Email"].value);
}
if (document.forms[formKey]["LastName"]) {
// If Last name exists, It has to be Caribou Sign up. We'll have
// all the functions defined in CaribouSignUpBox.gxp
var lastname = escape(document.forms[formKey]["LastName"].value);
}
if (document.forms[formKey]["FirstName"]) {
var firstname = escape(document.forms[formKey]["FirstName"].value);
}
var min_passwd_len = 8;
var passwdKey = "Passwd";
var emailKey = "Email";
var FirstNameKey = "FirstName";
var LastNameKey = "LastName";
if (passwd.length < min_passwd_len) {
if (passwd.length > 0) {
DrawBar(0);
} else {
ResetBar();
}
} else {
//We need to escape the password now so it won't mess up with length test
passwd = escape(passwd);
var params = passwdKey + "=" + passwd + "&" +
emailKey + "=" + email + "&" +
FirstNameKey + "=" + firstname + "&" +
LastNameKey + "=" + lastname;
myxmlhttp = CreateXmlHttpReq(RatePasswdXmlHttpHandler);
XmlHttpPOST(myxmlhttp, "https://www.google.com/accounts/RatePassword", params);
}
}
function getElement(name) {
if (document.all) {
return document.all(name);
}
return document.getElementById(name);
}
function getUserName(s) {
var parts = s.split("@");
return parts[0];
}
function RatePasswdXmlHttpHandler() {
// Can't check status since safari doesn't support it
if (myxmlhttp.readyState != 4) {
return;
}
rating = parseInt(myxmlhttp.responseText);
DrawBar(rating);
}
function DrawBar(rating) {
var posbar = getElement('posBar');
var negbar = getElement('negBar');
var passwdRating = getElement('passwdRating');
var barLength = getElement('passwdBar').width;
if (rating >= 0 && rating <= 4) { //We successfully got a rating
posbar.style.width = barLength / 4 * rating + "px";
negbar.style.width = barLength / 4 * (4 - rating) + "px";
} else {
posbar.style.width = "0px";
negbar.style.width = barLength + "px";
rating = 5; // Not rated Rating
}
posbar.style.background = barColors[rating];
passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] +
"'>" + ratingMsgs[rating] + "</font>";
}
//Resets the password strength bar back to its initial state without any message showing.
function ResetBar() {
var posbar = getElement('posBar');
var negbar = getElement('negBar');
var passwdRating = getElement('passwdRating');
var barLength = getElement('passwdBar').width;
posbar.style.width = "0px";
negbar.style.width = barLength + "px";
passwdRating.innerHTML = "";
}
/* Checks Browser Compatibility */
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_mac = (agt.indexOf("mac") != -1);
var is_gk = (agt.indexOf("gecko") != -1);
var is_sf = (agt.indexOf("safari") != -1);
function gff(str, pfx) {
var i = str.indexOf(pfx);
if (i != -1) {
var v = parseFloat(str.substring(i + pfx.length));
if (!isNaN(v)) {
return v;
}
}
return null;
}
function Compatible() {
if (is_ie && !is_op && !is_mac) {
var v = gff(agt, "msie ");
if (v != null) {
return (v >= 6.0);
}
}
if (is_gk && !is_sf) {
var v = gff(agt, "rv:");
if (v != null) {
return (v >= 1.4);
} else {
v = gff(agt, "galeon/");
if (v != null) {
return (v >= 1.3);
}
}
}
if (is_sf) {
var v = gff(agt, "applewebkit/");
if (v != null) {
return (v >= 124);
}
}
return false;
}
/* We also try to create an xmlhttp object to see if the browser supports it */
var myxmlhttp = CreateXmlHttpReq(RatePasswdXmlHttpHandler);
var isBrowserCompatible = Compatible() && myxmlhttp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -