Spectrum/scripts/index.js

349 lines
10 KiB
JavaScript
Raw Normal View History

2024-01-03 07:55:27 +00:00
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: [
2024-01-03 20:50:11 +00:00
(val) => `I do not feel any connection with identifying as any gender.`,
(val) =>
`I'm somewhat disconnected from the concept of gender, but I closely identify ${val}.`,
(val) =>
`I don't really care about gender, but I closely identify ${val}.`,
(val) =>
`I am somewhat connected to the concept of gender, and I identify ${val}.`,
(val) =>
`I am very connected to the concept of gender, and I identify ${val}.`,
2024-01-03 07:55:27 +00:00
],
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: [
2024-01-03 20:50:11 +00:00
(val) => `I don't occupy myself too much with gender expression.`,
(val) => `I express myself ${val}.`,
2024-01-03 07:55:27 +00:00
],
value: [
2024-01-03 19:21:24 +00:00
`super masculinely`,
2024-01-03 19:42:47 +00:00
`very masculinely`,
2024-01-03 19:21:24 +00:00
`masculinely`,
2024-01-03 07:55:27 +00:00
`as somewhat masculine`,
`more androgynously than masculine`,
`androgynously`,
`more androgynously than feminine`,
`as somewhat feminine`,
2024-01-03 19:21:24 +00:00
`femininely`,
`very femininely`,
`super femininely`,
2024-01-03 07:55:27 +00:00
],
},
},
"sex-ori": {
descElement: document.getElementById("spec-sex-ori-dsc"),
components: {
amount: [
2024-01-03 20:50:11 +00:00
(val) => `I do not experience any sexual attraction.`,
2024-01-04 01:05:02 +00:00
(val) => `I feel very little sexual attraction, ${val}.`,
2024-01-03 20:50:11 +00:00
(val) => `I feel some sexual attraction, ${val}.`,
(val) => `I feel an average amount of sexual attraction, ${val}.`,
(val) => `I feel more sexual attraction than usual, ${val}.`,
2024-01-04 01:05:02 +00:00
(val) => `I feel a lot of sexual attraction, ${val}.`,
2024-01-03 20:50:11 +00:00
(val) => `I feel extreme sexual attraction, ${val}.`,
2024-01-03 07:55:27 +00:00
],
value: [
`to another gender`,
2024-01-03 20:50:11 +00:00
`more to another gender than my own`,
2024-01-03 07:55:27 +00:00
`to any gender`,
2024-01-03 20:50:11 +00:00
`more towards my own gender than another`,
2024-01-03 07:55:27 +00:00
`towards their own gender`,
],
},
},
"rom-ori": {
descElement: document.getElementById("spec-rom-ori-dsc"),
components: {
amount: [
2024-01-03 20:50:11 +00:00
(val) => `I do not experience any romantic attraction.`,
2024-01-04 01:05:02 +00:00
(val) => `I feel very little romantic attraction, ${val}.`,
2024-01-03 20:50:11 +00:00
(val) => `I feel some romantic attraction, ${val}.`,
(val) => `I feel an average amount of romantic attraction, ${val}.`,
(val) => `I feel more romantic attraction than usual, ${val}.`,
2024-01-04 01:05:02 +00:00
(val) => `I feel a lot of romantic attraction, ${val}.`,
2024-01-03 20:50:11 +00:00
(val) => `I feel extreme romantic attraction, ${val}.`,
2024-01-03 07:55:27 +00:00
],
value: [
`to another gender`,
2024-01-03 20:50:11 +00:00
`more to another gender than my own`,
2024-01-03 07:55:27 +00:00
`to any gender`,
2024-01-03 20:50:11 +00:00
`more towards my own gender than another`,
2024-01-03 07:55:27 +00:00
`towards their own gender`,
],
},
},
"rel-att": {
descElement: document.getElementById("spec-rel-att-dsc"),
components: {
amount: [
2024-01-03 20:50:11 +00:00
(val) => `I would be uncomfortable in any relationship.`,
(val) =>
`I ${val} - though I am somewhat uncomfortable with relationships.`,
(val) => `I ${val}.`,
(val) => `I ${val} - and I would be active in it.`,
(val) => `I ${val} - and I would be dedicated to it.`,
2024-01-03 07:55:27 +00:00
],
value: [
2024-01-03 20:50:11 +00:00
`prefer monogamous relationships`,
`prefer monogamous relationships, but polygamy is OK`,
`would be open to any kind of relationship`,
`prefer polygamous relationships, but monogamy is OK`,
`prefer polygamous relationships`,
2024-01-03 07:55:27 +00:00
],
},
},
};
function triggerSliders(generate) {
sliders.forEach(([slider, override, description, func]) => {
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);
2024-01-03 08:38:16 +00:00
if (!func(overrideElement)) sliderElement.classList.add("off");
2024-01-03 08:39:11 +00:00
else sliderElement.classList.remove("off");
2024-01-03 07:55:27 +00:00
});
// 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();
});
}
sliderElement.disabled = !func(overrideElement);
if (!func(overrideElement)) sliderElement.classList.add("off");
2024-01-03 08:39:11 +00:00
else sliderElement.classList.remove("off");
2024-01-03 07:55:27 +00:00
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](
2024-01-03 20:50:11 +00:00
descObject.components.value[val]
// nameElement.value || "[Subject Name Here]"
2024-01-03 07:55:27 +00:00
);
}
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() {
2024-01-03 20:50:11 +00:00
var number =
(+enc_s_gia.value << (4 + 23)) +
(+enc_s_gi.value << (1 + 22)) +
(+enc_s_geo.checked << (4 + 18)) +
(+enc_s_ge.value << (3 + 15)) +
(+enc_s_soa.value << (3 + 12)) +
(+enc_s_so.value << (3 + 9)) +
(+enc_s_roa.value << (3 + 6)) +
(+enc_s_ro.value << (3 + 3)) +
(+enc_s_raa.value << 3) +
+enc_s_ra.value;
return number.toString(36);
2024-01-03 07:55:27 +00:00
}
2024-01-03 20:50:11 +00:00
function extract_ecfBIN(parsed_string) {
2024-01-04 01:05:02 +00:00
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_so.value = parseInt(parsed_string.substring(15, 18), 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);
const sex_att = parseInt(parsed_string.substring(12, 15), 2);
const rom_att = parseInt(parsed_string.substring(18, 21), 2);
switch (sex_att) {
case 0:
enc_s_soa.value = 0;
break;
case 1:
enc_s_soa.value = 2;
break;
case 2:
enc_s_soa.value = 3;
break;
case 3:
enc_s_soa.value = 4;
break;
case 4:
enc_s_soa.value = 6;
break;
}
switch (rom_att) {
case 0:
enc_s_roa.value = 0;
break;
case 1:
enc_s_roa.value = 2;
break;
case 2:
enc_s_roa.value = 3;
break;
case 3:
enc_s_roa.value = 4;
break;
case 4:
enc_s_roa.value = 6;
break;
}
}
function extract_ecfBINv2(parsed_string) {
2024-01-03 07:55:27 +00:00
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);
2024-01-03 20:50:11 +00:00
}
2024-01-03 07:55:27 +00:00
2024-01-03 20:50:11 +00:00
function decodev1(string) {
var parsed_string = parseInt(string, 16).toString(2).padStart(30, "0");
extract_ecfBIN(parsed_string);
}
function decodev2(string) {
var parsed_string = parseInt(string, 36).toString(2).padStart(30, "0");
extract_ecfBIN(parsed_string);
2024-01-03 07:55:27 +00:00
}
2024-01-04 01:05:02 +00:00
function decodev3(string) {
var parsed_string = parseInt(string, 36).toString(2).padStart(30, "0");
extract_ecfBINv2(parsed_string);
}
2024-01-03 07:55:27 +00:00
const s_share_link = document.getElementById("spec-share-link");
function createShareableURL() {
const url = new URL(window.location.href);
const code = encode();
2024-01-04 01:05:02 +00:00
url.hash = "3-" + code;
2024-01-03 07:55:27 +00:00
s_share_link.innerHTML = url.toString();
s_share_link.href = url.toString();
}
function parseURL() {
const urlParams = new URLSearchParams(window.location.search);
2024-01-03 20:50:11 +00:00
const hash = window.location.hash.replace("#", "");
if (hash != "") {
if (hash.startsWith("2-")) {
decodev2(hash.substring(2));
return lockSliders();
}
2024-01-04 01:05:02 +00:00
if (hash.startsWith("3-")) {
decodev3(hash.substring(2));
return lockSliders();
}
2024-01-03 20:50:11 +00:00
} else if (urlParams.get("s") != null) {
decodev1(urlParams.get("s"));
return lockSliders();
2024-01-03 07:55:27 +00:00
}
2024-01-03 20:50:11 +00:00
document.addEventListener("DOMContentLoaded", () => triggerSliders(true));
}
function lockSliders() {
2024-01-03 08:33:20 +00:00
triggerSliders(false);
2024-01-03 07:55:27 +00:00
sliders.forEach(([slider, override]) => {
document.body.classList.add("readOnly");
document.getElementById(slider).classList.add("ro");
document.getElementById(slider).disabled = true;
document.getElementById(override).classList.add("ro");
document.getElementById(override).disabled = true;
});
}