294 lines
9.4 KiB
JavaScript
294 lines
9.4 KiB
JavaScript
const nameElement = document.getElementById("spec-name");
|
|
|
|
const sliders = [
|
|
[
|
|
"spec-gen-idt",
|
|
"spec-gen-idt-amt",
|
|
["gen-idt", (x) => x.value],
|
|
(x) => x.value >= 1,
|
|
], // Gender identity
|
|
[
|
|
"spec-gen-exp",
|
|
"spec-gen-exp-ovr",
|
|
["gen-exp", (x) => (x.checked ? 1 : 0)],
|
|
(x) => x.checked,
|
|
], // Gender expression
|
|
[
|
|
"spec-sex-ori",
|
|
"spec-sex-ori-amt",
|
|
["sex-ori", (x) => x.value],
|
|
(x) => x.value >= 1,
|
|
], // Sexual orientation
|
|
[
|
|
"spec-rom-ori",
|
|
"spec-rom-ori-amt",
|
|
["rom-ori", (x) => x.value],
|
|
(x) => x.value >= 1,
|
|
], // Romantic orientation
|
|
[
|
|
"spec-rel-att",
|
|
"spec-rel-att-amt",
|
|
["rel-att", (x) => x.value],
|
|
(x) => x.value >= 1,
|
|
], // Relationship attitude
|
|
];
|
|
|
|
const descs = {
|
|
"gen-idt": {
|
|
descElement: document.getElementById("spec-gen-idt-dsc"),
|
|
components: {
|
|
amount: [
|
|
(val, sub) =>
|
|
`${sub} does not feel any connection with identifying as any gender.`,
|
|
(val, sub) =>
|
|
`${sub} closely identifies ${val}, but they are somewhat disconnected from it.`,
|
|
(val, sub) =>
|
|
`${sub} closely identifies ${val}, but they don't really care.`,
|
|
(val, sub) =>
|
|
`${sub} identifies ${val}, and they are somewhat connected to it.`,
|
|
(val, sub) =>
|
|
`${sub} identifies ${val}, and they are very connected to it.`,
|
|
],
|
|
value: [
|
|
`as male`,
|
|
`as mostly male`,
|
|
`as somewhat male`,
|
|
`more androgynously than male`,
|
|
`androgynously`,
|
|
`more androgynously than female`,
|
|
`as somewhat female`,
|
|
`as mostly female`,
|
|
`as female`,
|
|
],
|
|
},
|
|
},
|
|
"gen-exp": {
|
|
descElement: document.getElementById("spec-gen-exp-dsc"),
|
|
components: {
|
|
amount: [
|
|
(val, sub) => `${sub} isn't too occupied with expressing themselves.`,
|
|
(val, sub) => `${sub} expresses themselves ${val}.`,
|
|
],
|
|
value: [
|
|
`as super masculine`,
|
|
`as very masculine`,
|
|
`as masculine`,
|
|
`as somewhat masculine`,
|
|
`more androgynously than masculine`,
|
|
`androgynously`,
|
|
`more androgynously than feminine`,
|
|
`as somewhat feminine`,
|
|
`as feminine`,
|
|
`as very feminine`,
|
|
`as super feminine`,
|
|
],
|
|
},
|
|
},
|
|
"sex-ori": {
|
|
descElement: document.getElementById("spec-sex-ori-dsc"),
|
|
components: {
|
|
amount: [
|
|
(val, sub) => `${sub} does not feel any sexual attraction.`,
|
|
(val, sub) => `${sub} feels some sexual attraction, ${val}.`,
|
|
(val, sub) => `${sub} feels sexual attraction, ${val}.`,
|
|
(val, sub) => `${sub} feels more sexual attraction than usual, ${val}.`,
|
|
(val, sub) => `${sub} feels extreme sexual attraction, ${val}.`,
|
|
],
|
|
value: [
|
|
`to another gender`,
|
|
`more to another gender than their own`,
|
|
`to any gender`,
|
|
`more towards their own gender than another`,
|
|
`towards their own gender`,
|
|
],
|
|
},
|
|
},
|
|
"rom-ori": {
|
|
descElement: document.getElementById("spec-rom-ori-dsc"),
|
|
components: {
|
|
amount: [
|
|
(val, sub) => `${sub} does not feel any romantic attraction.`,
|
|
(val, sub) => `${sub} feels some romantic attraction, ${val}.`,
|
|
(val, sub) => `${sub} feels romantic attraction, ${val}.`,
|
|
(val, sub) =>
|
|
`${sub} feels more romantic attraction than usual, ${val}.`,
|
|
(val, sub) => `${sub} feels extreme romantic attraction, ${val}.`,
|
|
],
|
|
value: [
|
|
`to another gender`,
|
|
`more to another gender than their own`,
|
|
`to any gender`,
|
|
`more towards their own gender than another`,
|
|
`towards their own gender`,
|
|
],
|
|
},
|
|
},
|
|
"rel-att": {
|
|
descElement: document.getElementById("spec-rel-att-dsc"),
|
|
components: {
|
|
amount: [
|
|
(val, sub) => `${sub} would be uncomfortable in any relationship.`,
|
|
(val, sub) =>
|
|
`${sub} is somewhat uncomfortable with relationships, but they would ${val}.`,
|
|
(val, sub) => `${sub} would ${val}.`,
|
|
(val, sub) =>
|
|
`${sub} would ${val}. They would also be more active in it than usual.`,
|
|
(val, sub) =>
|
|
`${sub} would ${val}. They would also be dedicated to it.`,
|
|
],
|
|
value: [
|
|
`prefer a monogamous relationship`,
|
|
`prefer a monogamous relationship. However, they can be polyamorous if desired`,
|
|
`be open to any kind of relationship`,
|
|
`prefer a polyamorous relationship. However, they can be monogamous if desired`,
|
|
`prefer a polyamorous relationship`,
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
function triggerSliders(generate) {
|
|
sliders.forEach(([slider, override, description, func]) => {
|
|
console.log(slider, override);
|
|
var overrideElement = document.getElementById(override);
|
|
var sliderElement = document.getElementById(slider);
|
|
|
|
if (generate) {
|
|
// Disable on override condition
|
|
overrideElement.addEventListener("input", (e) => {
|
|
sliderElement.disabled = !func(e.target);
|
|
});
|
|
|
|
// Update description on attribute change
|
|
overrideElement.addEventListener("input", (e) => {
|
|
updateDescription(
|
|
description[0],
|
|
sliderElement.value,
|
|
description[1](overrideElement)
|
|
);
|
|
createShareableURL();
|
|
});
|
|
sliderElement.addEventListener("input", (e) => {
|
|
updateDescription(
|
|
description[0],
|
|
sliderElement.value,
|
|
description[1](overrideElement)
|
|
);
|
|
createShareableURL();
|
|
});
|
|
|
|
// Update description on name change
|
|
nameElement.addEventListener("input", () => {
|
|
updateDescription(
|
|
description[0],
|
|
sliderElement.value,
|
|
description[1](overrideElement)
|
|
);
|
|
createShareableURL();
|
|
});
|
|
}
|
|
|
|
sliderElement.disabled = !func(overrideElement);
|
|
if (!func(overrideElement)) sliderElement.classList.add("off");
|
|
|
|
updateDescription(
|
|
description[0],
|
|
sliderElement.value,
|
|
description[1](overrideElement)
|
|
);
|
|
createShareableURL();
|
|
});
|
|
}
|
|
|
|
function updateDescription(id, val, amt) {
|
|
var descObject = descs[id];
|
|
descObject.descElement.innerHTML = descObject.components.amount[amt](
|
|
descObject.components.value[val],
|
|
nameElement.value || "[Subject Name Here]"
|
|
);
|
|
}
|
|
|
|
var enc_s_gia = document.getElementById("spec-gen-idt-amt");
|
|
var enc_s_gi = document.getElementById("spec-gen-idt");
|
|
var enc_s_geo = document.getElementById("spec-gen-exp-ovr");
|
|
var enc_s_ge = document.getElementById("spec-gen-exp");
|
|
var enc_s_soa = document.getElementById("spec-sex-ori-amt");
|
|
var enc_s_so = document.getElementById("spec-sex-ori");
|
|
var enc_s_roa = document.getElementById("spec-rom-ori-amt");
|
|
var enc_s_ro = document.getElementById("spec-rom-ori");
|
|
var enc_s_raa = document.getElementById("spec-rel-att-amt");
|
|
var enc_s_ra = document.getElementById("spec-rel-att");
|
|
function encode() {
|
|
// out string len is 3 + 4 + 1 + 4 + 3 + 3 + 3 + 3 + 3 + 3 = 30
|
|
// 000 0000 0 0000 000 000 000 000 000 000
|
|
const parse = (s, n) => Math.abs(s).toString(2).padStart(n, "0");
|
|
var string =
|
|
parse(enc_s_gia.value, 3) +
|
|
parse(enc_s_gi.value, 4) +
|
|
parse(enc_s_geo.checked, 1) +
|
|
parse(enc_s_ge.value, 4) +
|
|
parse(enc_s_soa.value, 3) +
|
|
parse(enc_s_so.value, 3) +
|
|
parse(enc_s_roa.value, 3) +
|
|
parse(enc_s_ro.value, 3) +
|
|
parse(enc_s_raa.value, 3) +
|
|
parse(enc_s_ra.value, 3);
|
|
var parsed_string = parseInt(string, 2).toString(16);
|
|
console.log(string, parsed_string);
|
|
return parsed_string;
|
|
}
|
|
|
|
// test pattern (on): 100100011010100100100100100100 246a4924
|
|
// test pattern (off): 001000010000001000001000001000 8408208
|
|
|
|
function decode(string) {
|
|
var parsed_string = parseInt(string, 16).toString(2).padStart(30, "0");
|
|
|
|
enc_s_gia.value = parseInt(parsed_string.substring(0, 3), 2);
|
|
enc_s_gi.value = parseInt(parsed_string.substring(3, 7), 2);
|
|
enc_s_geo.checked = parseInt(parsed_string.substring(7, 8), 2);
|
|
enc_s_ge.value = parseInt(parsed_string.substring(8, 12), 2);
|
|
enc_s_soa.value = parseInt(parsed_string.substring(12, 15), 2);
|
|
enc_s_so.value = parseInt(parsed_string.substring(15, 18), 2);
|
|
enc_s_roa.value = parseInt(parsed_string.substring(18, 21), 2);
|
|
enc_s_ro.value = parseInt(parsed_string.substring(21, 24), 2);
|
|
enc_s_raa.value = parseInt(parsed_string.substring(24, 27), 2);
|
|
enc_s_ra.value = parseInt(parsed_string.substring(27, 30), 2);
|
|
|
|
triggerSliders(false);
|
|
}
|
|
|
|
const s_share_link = document.getElementById("spec-share-link");
|
|
|
|
function createShareableURL() {
|
|
const url = new URL(window.location.href);
|
|
const code = encode();
|
|
|
|
url.search = new URLSearchParams({
|
|
s: code,
|
|
n: nameElement.value || "[Subject Name Here]",
|
|
}).toString();
|
|
|
|
s_share_link.innerHTML = url.toString();
|
|
s_share_link.href = url.toString();
|
|
}
|
|
|
|
function parseURL() {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
if (urlParams.get("s") == null) {
|
|
document.addEventListener("DOMContentLoaded", () => triggerSliders(true));
|
|
return;
|
|
}
|
|
triggerSliders(false);
|
|
nameElement.value = urlParams.get("n") || "";
|
|
decode(urlParams.get("s"));
|
|
sliders.forEach(([slider, override]) => {
|
|
document.body.classList.add("readOnly");
|
|
nameElement.classList.add("ro");
|
|
nameElement.disabled = true;
|
|
document.getElementById(slider).classList.add("ro");
|
|
document.getElementById(slider).disabled = true;
|
|
document.getElementById(override).classList.add("ro");
|
|
document.getElementById(override).disabled = true;
|
|
});
|
|
}
|