nekrochan/static/js/autofill.js

53 řádky
1.5 KiB
JavaScript
Surový Normální zobrazení Historie

2024-03-16 11:20:50 +00:00
$(function () {
let name = get_cookie("name");
let password = get_cookie("password");
let email = get_cookie("email");
if (password === "") {
password = generate_password();
set_cookie("password", password);
}
$('input[name="post_name"]').attr("value", name);
$('input[name="post_password"]').attr("value", password);
$('input[name="email"]').attr("value", email);
function generate_password() {
let chars =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let password_length = 8;
let password = "";
for (let i = 0; i <= password_length; i++) {
let random_number = Math.floor(Math.random() * chars.length);
password += chars.substring(random_number, random_number + 1);
}
return password;
}
function get_cookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function set_cookie(cname, cvalue) {
document.cookie = `${cname}=${cvalue};path=/`;
}
});