nekrochan/static/js/autofill.js

51 řádky
1.2 KiB
JavaScript
Surový Normální zobrazení Historie

2024-02-20 21:09:52 +00:00
$(function () {
let name = get_cookie("name");
2024-02-20 21:09:52 +00:00
let password = get_cookie("password");
if (password === "") {
password = generate_password();
set_cookie("password", password);
}
2024-03-05 16:48:25 +00:00
$('input[name="post_name"]').attr("value", name);
$('input[name="post_password"]').attr("value", password);
2024-02-20 21:09:52 +00:00
});
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=/`;
}