Back to feed
ForumSpark Support Themes & Extensions Join

Mood Icon Profile Field

Cory · 7 months ago · 15 replies · 98

Preview #1 - Preview #2

Use the version below for v1 boards; use this version for v2 and above.

Create a new custom profile field:

Admin CP → Users & Groups → Profile Fields → Add field

Handle: mood
Label: Mood
Show in mini profile: Enable

Admin CP → Themes → Board Templates → Below the board

<script>

const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const moodI = ['https://files.jcink.net/uploads/cory//p478599.png', 'https://files.jcink.net/uploads/cory//p478511.gif', 'https://files.jcink.net/uploads/cory//p478512.gif', 'https://files.jcink.net/uploads/cory//p478513.gif', 'https://files.jcink.net/uploads/cory//p478514.gif', 'https://files.jcink.net/uploads/cory//p478515.gif', 'https://files.jcink.net/uploads/cory//p478516.gif', 'https://files.jcink.net/uploads/cory//p478517.gif', 'https://files.jcink.net/uploads/cory//p478518.gif', 'https://files.jcink.net/uploads/cory//p478520.gif', 'https://files.jcink.net/uploads/cory//p478521.gif', 'https://files.jcink.net/uploads/cory//p478522.gif', 'https://files.jcink.net/uploads/cory//p478523.gif', 'https://files.jcink.net/uploads/cory//p478524.gif', 'https://files.jcink.net/uploads/cory//p478525.gif', 'https://files.jcink.net/uploads/cory//p478526.gif', 'https://files.jcink.net/uploads/cory//p478527.gif', 'https://files.jcink.net/uploads/cory//p478528.gif', 'https://files.jcink.net/uploads/cory//p478529.gif', 'https://files.jcink.net/uploads/cory//p478530.gif', 'https://files.jcink.net/uploads/cory//p478531.gif', 'https://files.jcink.net/uploads/cory//p478532.gif', 'https://files.jcink.net/uploads/cory//p478533.gif', 'https://files.jcink.net/uploads/cory//p478534.gif', 'https://files.jcink.net/uploads/cory//p478535.gif', 'https://files.jcink.net/uploads/cory//p478536.gif', 'https://files.jcink.net/uploads/cory//p478537.gif', 'https://files.jcink.net/uploads/cory//p478538.gif', 'https://files.jcink.net/uploads/cory//p478539.gif', 'https://files.jcink.net/uploads/cory//p478540.gif', 'https://files.jcink.net/uploads/cory//p478541.gif', 'https://files.jcink.net/uploads/cory//p478542.gif', 'https://files.jcink.net/uploads/cory//p478543.gif', 'https://files.jcink.net/uploads/cory//p478544.gif', 'https://files.jcink.net/uploads/cory//p478545.gif', 'https://files.jcink.net/uploads/cory//p478546.gif', 'https://files.jcink.net/uploads/cory//p478547.gif', 'https://files.jcink.net/uploads/cory//p478548.gif', 'https://files.jcink.net/uploads/cory//p478549.gif', 'https://files.jcink.net/uploads/cory//p478550.gif', 'https://files.jcink.net/uploads/cory//p478553.gif', 'https://files.jcink.net/uploads/cory//p478554.gif', 'https://files.jcink.net/uploads/cory//p478555.gif', 'https://files.jcink.net/uploads/cory//p478556.gif', 'https://files.jcink.net/uploads/cory//p478557.gif', 'https://files.jcink.net/uploads/cory//p478558.gif', 'https://files.jcink.net/uploads/cory//p478559.gif', 'https://files.jcink.net/uploads/cory//p478560.gif', 'https://files.jcink.net/uploads/cory//p478561.gif', 'https://files.jcink.net/uploads/cory//p478562.gif', 'https://files.jcink.net/uploads/cory//p478564.gif', 'https://files.jcink.net/uploads/cory//p478565.gif', 'https://files.jcink.net/uploads/cory//p478566.gif', 'https://files.jcink.net/uploads/cory//p478567.gif', 'https://files.jcink.net/uploads/cory//p478568.gif', 'https://files.jcink.net/uploads/cory//p478569.gif', 'https://files.jcink.net/uploads/cory//p478570.gif', 'https://files.jcink.net/uploads/cory//p478571.gif', 'https://files.jcink.net/uploads/cory//p478572.gif', 'https://files.jcink.net/uploads/cory//p478573.gif', 'https://files.jcink.net/uploads/cory//p478574.gif', 'https://files.jcink.net/uploads/cory//p478575.gif', 'https://files.jcink.net/uploads/cory//p478576.gif', 'https://files.jcink.net/uploads/cory//p478577.gif', 'https://files.jcink.net/uploads/cory//p478578.gif', 'https://files.jcink.net/uploads/cory//p478579.gif', 'https://files.jcink.net/uploads/cory//p478580.gif', 'https://files.jcink.net/uploads/cory//p478581.gif', 'https://files.jcink.net/uploads/cory//p478582.gif', 'https://files.jcink.net/uploads/cory//p478583.gif', 'https://files.jcink.net/uploads/cory//p478584.gif', 'https://files.jcink.net/uploads/cory//p478585.gif', 'https://files.jcink.net/uploads/cory//p478586.gif', 'https://files.jcink.net/uploads/cory//p478587.gif', 'https://files.jcink.net/uploads/cory//p478588.gif', 'https://files.jcink.net/uploads/cory//p478589.gif'];
const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
if (element && element.innerText.includes('Mood')) {
element.parentElement.nextElementSibling.querySelector('input').style.display = 'none';
const div = document.createElement('div');
div.style.display = 'flex';
div.style.flexWrap = 'wrap';
div.style.gap = '10px';

for (let i = 0; i < moodN.length; i++) {
const img = document.createElement('img');
img.src = moodI[i];
img.alt = moodN[i];
img.title = moodN[i];
img.className = 'mood-img';
img.width = '93';
img.height = '30';
img.style.cursor = 'pointer';
img.style.opacity = '0.5';
element.parentElement.nextElementSibling.appendChild(div);
div.appendChild(img);
}

value = element.parentElement.nextElementSibling.querySelector('input').value;
}
});

const flag = document.querySelectorAll('img.mood-img');

flag.forEach(element => {
if (element.title === value) {
element.style.opacity = '1';
}

element.addEventListener('click', function() {
flag.forEach(allElements => {
allElements.style.opacity = '0.5';
});

const title = element.title;
element.parentElement.parentElement.querySelector('input').value = title;
element.style.opacity = '1';
});
});

const about = document.querySelectorAll('div.profile-about__item');

about.forEach(element => {
if (element.querySelector('dt').innerText === 'Mood') {
const myMood = element.querySelector('dd').innerText;

for (let i = 0; i < moodN.length; i++) {
if (myMood === moodN[i]) {
element.querySelector('dd').innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
}
}
}
});

const mini = document.querySelectorAll('div.mini-profile--custom dt');

mini.forEach(element => {
if (element.innerText === 'Mood') {
const myMood = element.nextElementSibling.innerText;

for (let i = 0; i < moodN.length; i++) {
if (myMood === '-') {
element.nextElementSibling.innerHTML = `<img src="${moodI[0]}" title="${moodN[0]}" alt="${moodN[0]}">`;
} else if (myMood === moodN[i]) {
element.nextElementSibling.innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
}
}
}
});
</script>
15 replies
Smokey · 7 months ago
Cory OP · 7 months ago

Updated the code in the OP. Try it now.

Smokey · 7 months ago

That works :)

Could it be possible if a user doesn't have a mood set to have the "None" or "No Mood" graphic show by default?

Cory OP · 7 months ago

This should do the trick:

<script>
const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const moodI = ['https://files.jcink.net/uploads/cory//p478599.png', 'https://files.jcink.net/uploads/cory//p478511.gif', 'https://files.jcink.net/uploads/cory//p478512.gif', 'https://files.jcink.net/uploads/cory//p478513.gif', 'https://files.jcink.net/uploads/cory//p478514.gif', 'https://files.jcink.net/uploads/cory//p478515.gif', 'https://files.jcink.net/uploads/cory//p478516.gif', 'https://files.jcink.net/uploads/cory//p478517.gif', 'https://files.jcink.net/uploads/cory//p478518.gif', 'https://files.jcink.net/uploads/cory//p478520.gif', 'https://files.jcink.net/uploads/cory//p478521.gif', 'https://files.jcink.net/uploads/cory//p478522.gif', 'https://files.jcink.net/uploads/cory//p478523.gif', 'https://files.jcink.net/uploads/cory//p478524.gif', 'https://files.jcink.net/uploads/cory//p478525.gif', 'https://files.jcink.net/uploads/cory//p478526.gif', 'https://files.jcink.net/uploads/cory//p478527.gif', 'https://files.jcink.net/uploads/cory//p478528.gif', 'https://files.jcink.net/uploads/cory//p478529.gif', 'https://files.jcink.net/uploads/cory//p478530.gif', 'https://files.jcink.net/uploads/cory//p478531.gif', 'https://files.jcink.net/uploads/cory//p478532.gif', 'https://files.jcink.net/uploads/cory//p478533.gif', 'https://files.jcink.net/uploads/cory//p478534.gif', 'https://files.jcink.net/uploads/cory//p478535.gif', 'https://files.jcink.net/uploads/cory//p478536.gif', 'https://files.jcink.net/uploads/cory//p478537.gif', 'https://files.jcink.net/uploads/cory//p478538.gif', 'https://files.jcink.net/uploads/cory//p478539.gif', 'https://files.jcink.net/uploads/cory//p478540.gif', 'https://files.jcink.net/uploads/cory//p478541.gif', 'https://files.jcink.net/uploads/cory//p478542.gif', 'https://files.jcink.net/uploads/cory//p478543.gif', 'https://files.jcink.net/uploads/cory//p478544.gif', 'https://files.jcink.net/uploads/cory//p478545.gif', 'https://files.jcink.net/uploads/cory//p478546.gif', 'https://files.jcink.net/uploads/cory//p478547.gif', 'https://files.jcink.net/uploads/cory//p478548.gif', 'https://files.jcink.net/uploads/cory//p478549.gif', 'https://files.jcink.net/uploads/cory//p478550.gif', 'https://files.jcink.net/uploads/cory//p478553.gif', 'https://files.jcink.net/uploads/cory//p478554.gif', 'https://files.jcink.net/uploads/cory//p478555.gif', 'https://files.jcink.net/uploads/cory//p478556.gif', 'https://files.jcink.net/uploads/cory//p478557.gif', 'https://files.jcink.net/uploads/cory//p478558.gif', 'https://files.jcink.net/uploads/cory//p478559.gif', 'https://files.jcink.net/uploads/cory//p478560.gif', 'https://files.jcink.net/uploads/cory//p478561.gif', 'https://files.jcink.net/uploads/cory//p478562.gif', 'https://files.jcink.net/uploads/cory//p478564.gif', 'https://files.jcink.net/uploads/cory//p478565.gif', 'https://files.jcink.net/uploads/cory//p478566.gif', 'https://files.jcink.net/uploads/cory//p478567.gif', 'https://files.jcink.net/uploads/cory//p478568.gif', 'https://files.jcink.net/uploads/cory//p478569.gif', 'https://files.jcink.net/uploads/cory//p478570.gif', 'https://files.jcink.net/uploads/cory//p478571.gif', 'https://files.jcink.net/uploads/cory//p478572.gif', 'https://files.jcink.net/uploads/cory//p478573.gif', 'https://files.jcink.net/uploads/cory//p478574.gif', 'https://files.jcink.net/uploads/cory//p478575.gif', 'https://files.jcink.net/uploads/cory//p478576.gif', 'https://files.jcink.net/uploads/cory//p478577.gif', 'https://files.jcink.net/uploads/cory//p478578.gif', 'https://files.jcink.net/uploads/cory//p478579.gif', 'https://files.jcink.net/uploads/cory//p478580.gif', 'https://files.jcink.net/uploads/cory//p478581.gif', 'https://files.jcink.net/uploads/cory//p478582.gif', 'https://files.jcink.net/uploads/cory//p478583.gif', 'https://files.jcink.net/uploads/cory//p478584.gif', 'https://files.jcink.net/uploads/cory//p478585.gif', 'https://files.jcink.net/uploads/cory//p478586.gif', 'https://files.jcink.net/uploads/cory//p478587.gif', 'https://files.jcink.net/uploads/cory//p478588.gif', 'https://files.jcink.net/uploads/cory//p478589.gif'];
const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
    if (element && element.innerText.includes('Mood')) {
        element.parentElement.nextElementSibling.querySelector('input').style.display = 'none';
        const div = document.createElement('div');
        div.style.display = 'flex';
        div.style.flexWrap = 'wrap';
        div.style.gap = '10px';

for (let i = 0; i < moodN.length; i++) {
    const img = document.createElement('img');
    img.src = moodI[i];
    img.alt = moodN[i];
    img.title = moodN[i];
    img.className = 'mood-img';
    img.width = '93';
    img.height = '30';
    img.style.cursor = 'pointer';
    img.style.opacity = '0.5';
    element.parentElement.nextElementSibling.appendChild(div);
    div.appendChild(img);
}

value = element.parentElement.nextElementSibling.querySelector('input').value;
}
});

const flag = document.querySelectorAll('img.mood-img');

flag.forEach(element => {
    if (element.title === value) {
        element.style.opacity = '1';
    }

element.addEventListener('click', function() {
    flag.forEach(allElements => {
        allElements.style.opacity = '0.5';
    });

const title = element.title;
element.parentElement.parentElement.querySelector('input').value = title;
element.style.opacity = '1';
});
});

const about = document.querySelectorAll('div.profile-about__item');

about.forEach(element => {
    if (element.querySelector('dt').innerText === 'Mood') {
        const myMood = element.querySelector('dd').innerText;

for (let i = 0; i < moodN.length; i++) {
    if (myMood === moodN[i]) {
        element.querySelector('dd').innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
    }
}
}
});

const mini = document.querySelectorAll('div.mini-profile--custom dt');

mini.forEach(element => {
    if (element.innerText === 'Mood') {
        const myMood = element.nextElementSibling.innerText;

for (let i = 0; i < moodN.length; i++) {
    if (myMood === moodN[i]) {
        element.nextElementSibling.innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
    } else {
        element.nextElementSibling.innerHTML = `<img src="${moodI[0]}" title="${moodN[0]}" alt="${moodN[0]}">`;
    }
}
}
});
</script>
Smokey · 7 months ago

Nope, that broke it. Now it sets everyone's mood to "None" despite having a mood set already.

Cory OP · 7 months ago

This worked for me:

<script>
const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const moodI = ['https://files.jcink.net/uploads/cory//p478599.png', 'https://files.jcink.net/uploads/cory//p478511.gif', 'https://files.jcink.net/uploads/cory//p478512.gif', 'https://files.jcink.net/uploads/cory//p478513.gif', 'https://files.jcink.net/uploads/cory//p478514.gif', 'https://files.jcink.net/uploads/cory//p478515.gif', 'https://files.jcink.net/uploads/cory//p478516.gif', 'https://files.jcink.net/uploads/cory//p478517.gif', 'https://files.jcink.net/uploads/cory//p478518.gif', 'https://files.jcink.net/uploads/cory//p478520.gif', 'https://files.jcink.net/uploads/cory//p478521.gif', 'https://files.jcink.net/uploads/cory//p478522.gif', 'https://files.jcink.net/uploads/cory//p478523.gif', 'https://files.jcink.net/uploads/cory//p478524.gif', 'https://files.jcink.net/uploads/cory//p478525.gif', 'https://files.jcink.net/uploads/cory//p478526.gif', 'https://files.jcink.net/uploads/cory//p478527.gif', 'https://files.jcink.net/uploads/cory//p478528.gif', 'https://files.jcink.net/uploads/cory//p478529.gif', 'https://files.jcink.net/uploads/cory//p478530.gif', 'https://files.jcink.net/uploads/cory//p478531.gif', 'https://files.jcink.net/uploads/cory//p478532.gif', 'https://files.jcink.net/uploads/cory//p478533.gif', 'https://files.jcink.net/uploads/cory//p478534.gif', 'https://files.jcink.net/uploads/cory//p478535.gif', 'https://files.jcink.net/uploads/cory//p478536.gif', 'https://files.jcink.net/uploads/cory//p478537.gif', 'https://files.jcink.net/uploads/cory//p478538.gif', 'https://files.jcink.net/uploads/cory//p478539.gif', 'https://files.jcink.net/uploads/cory//p478540.gif', 'https://files.jcink.net/uploads/cory//p478541.gif', 'https://files.jcink.net/uploads/cory//p478542.gif', 'https://files.jcink.net/uploads/cory//p478543.gif', 'https://files.jcink.net/uploads/cory//p478544.gif', 'https://files.jcink.net/uploads/cory//p478545.gif', 'https://files.jcink.net/uploads/cory//p478546.gif', 'https://files.jcink.net/uploads/cory//p478547.gif', 'https://files.jcink.net/uploads/cory//p478548.gif', 'https://files.jcink.net/uploads/cory//p478549.gif', 'https://files.jcink.net/uploads/cory//p478550.gif', 'https://files.jcink.net/uploads/cory//p478553.gif', 'https://files.jcink.net/uploads/cory//p478554.gif', 'https://files.jcink.net/uploads/cory//p478555.gif', 'https://files.jcink.net/uploads/cory//p478556.gif', 'https://files.jcink.net/uploads/cory//p478557.gif', 'https://files.jcink.net/uploads/cory//p478558.gif', 'https://files.jcink.net/uploads/cory//p478559.gif', 'https://files.jcink.net/uploads/cory//p478560.gif', 'https://files.jcink.net/uploads/cory//p478561.gif', 'https://files.jcink.net/uploads/cory//p478562.gif', 'https://files.jcink.net/uploads/cory//p478564.gif', 'https://files.jcink.net/uploads/cory//p478565.gif', 'https://files.jcink.net/uploads/cory//p478566.gif', 'https://files.jcink.net/uploads/cory//p478567.gif', 'https://files.jcink.net/uploads/cory//p478568.gif', 'https://files.jcink.net/uploads/cory//p478569.gif', 'https://files.jcink.net/uploads/cory//p478570.gif', 'https://files.jcink.net/uploads/cory//p478571.gif', 'https://files.jcink.net/uploads/cory//p478572.gif', 'https://files.jcink.net/uploads/cory//p478573.gif', 'https://files.jcink.net/uploads/cory//p478574.gif', 'https://files.jcink.net/uploads/cory//p478575.gif', 'https://files.jcink.net/uploads/cory//p478576.gif', 'https://files.jcink.net/uploads/cory//p478577.gif', 'https://files.jcink.net/uploads/cory//p478578.gif', 'https://files.jcink.net/uploads/cory//p478579.gif', 'https://files.jcink.net/uploads/cory//p478580.gif', 'https://files.jcink.net/uploads/cory//p478581.gif', 'https://files.jcink.net/uploads/cory//p478582.gif', 'https://files.jcink.net/uploads/cory//p478583.gif', 'https://files.jcink.net/uploads/cory//p478584.gif', 'https://files.jcink.net/uploads/cory//p478585.gif', 'https://files.jcink.net/uploads/cory//p478586.gif', 'https://files.jcink.net/uploads/cory//p478587.gif', 'https://files.jcink.net/uploads/cory//p478588.gif', 'https://files.jcink.net/uploads/cory//p478589.gif'];
const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
    if (element && element.innerText.includes('Mood')) {
        element.parentElement.nextElementSibling.querySelector('input').style.display = 'none';
        const div = document.createElement('div');
        div.style.display = 'flex';
        div.style.flexWrap = 'wrap';
        div.style.gap = '10px';

for (let i = 0; i < moodN.length; i++) {
    const img = document.createElement('img');
    img.src = moodI[i];
    img.alt = moodN[i];
    img.title = moodN[i];
    img.className = 'mood-img';
    img.width = '93';
    img.height = '30';
    img.style.cursor = 'pointer';
    img.style.opacity = '0.5';
    element.parentElement.nextElementSibling.appendChild(div);
    div.appendChild(img);
}

value = element.parentElement.nextElementSibling.querySelector('input').value;
}
});

const flag = document.querySelectorAll('img.mood-img');

flag.forEach(element => {
    if (element.title === value) {
        element.style.opacity = '1';
    }

element.addEventListener('click', function() {
    flag.forEach(allElements => {
        allElements.style.opacity = '0.5';
    });

const title = element.title;
element.parentElement.parentElement.querySelector('input').value = title;
element.style.opacity = '1';
});
});

const about = document.querySelectorAll('div.profile-about__item');

about.forEach(element => {
    if (element.querySelector('dt').innerText === 'Mood') {
        const myMood = element.querySelector('dd').innerText;

for (let i = 0; i < moodN.length; i++) {
    if (myMood === moodN[i]) {
        element.querySelector('dd').innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
    }
}
}
});

const mini = document.querySelectorAll('div.mini-profile--custom dt');

mini.forEach(element => {
    if (element.innerText === 'Mood') {
        const myMood = element.nextElementSibling.innerText;

for (let i = 0; i < moodN.length; i++) {
    if (myMood === '-') {
       element.nextElementSibling.innerHTML = `<img src="${moodI[0]}" title="${moodN[0]}" alt="${moodN[0]}">`; 
    } else if (myMood === moodN[i]) {
        element.nextElementSibling.innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
    }
}
}
});
</script>
Smokey · 7 months ago

That worked. I'd edit the main post and include that as the code :)

Cory OP · 7 months ago

It has been done.

?
Deleted user · 7 months ago

Would there be a way to have it as text only and when editing the profile to have the options as a drop-down?

Cory OP · 7 months ago
Gizmo said:

Would there be a way to have it as text only and when editing the profile to have the options as a drop-down?

Try this:

<script>
const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
    if (element && element.innerText.includes('Mood')) {
        element.parentElement.nextElementSibling.querySelector('input').style.display = 'none';
        const select = document.createElement('select');
        select.id = 'moods';

    for (let i = 0; i < moodN.length; i++) {
        const option = document.createElement('option');
        option.innerText = moodN[i];
        option.value = moodN[i];
        element.parentElement.nextElementSibling.appendChild(select);
        select.appendChild(option);
    }

    value = element.parentElement.nextElementSibling.querySelector('input').value;
}
});

const mood = document.querySelector('#moods');

if (mood) {
    mood.value = value;

mood.addEventListener('change', function() {
    mood.parentElement.querySelector('input').value = mood.value;
});
}
</script>
?
Deleted user · 7 months ago

Is there a way for the dropdown to show "select mood" or something when it's not open?

Cory OP · 7 months ago
Gizmo said:

Is there a way for the dropdown to show "select mood" or something when it's not open?

Try this instead:

<script>
const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
    if (element && element.innerText.includes('Mood')) {
        element.parentElement.nextElementSibling.querySelector('input').style.display = 'none';
        const select = document.createElement('select');
        select.id = 'moods';
        const selectMood = document.createElement('option');
        selectMood.innerText = 'Select Mood';
        selectMood.value = '-1';
        select.appendChild(selectMood);
        select.value = '-1';

    for (let i = 0; i < moodN.length; i++) {
        const option = document.createElement('option');
        option.innerText = moodN[i];
        option.value = moodN[i];
        element.parentElement.nextElementSibling.appendChild(select);
        select.appendChild(option);
    }

    value = element.parentElement.nextElementSibling.querySelector('input').value;
}
});

const mood = document.querySelector('#moods');

if (mood) {
    if (value !== '') {
        mood.value = value;
    }

mood.addEventListener('change', function() {
    if (mood.value !== '-1') {
        mood.parentElement.querySelector('input').value = mood.value;
    }
});
}
</script>
Empire · 7 months ago

If you want to keep the images to show on the mini profile and also use the dropdown option in the profile, then here:

<script>
const moodN = ['None', 'Aggressive', 'Amazed', 'Amused', 'Angelic', 'Angry', 'Artistic', 'Asleep', 'Bashful', 'Blah', 'Bored', 'Breezy', 'Brooding', 'Busy', 'Buzzed', 'Chatty', 'Cheeky', 'Cheerful', 'Cloud_9', 'Cold', 'Coldturkey', 'Confused', 'Cool', 'Crappy', 'Curious', 'Cynical', 'Daring', 'Dead', 'Depressed', 'Devilish', 'Doh', 'Doubtful', 'Drunk', 'Energetic', 'Fiendish', 'Fine', 'Flirty', 'Gloomy', 'Goofy', 'Grumpy', 'Hot', 'Hungover', 'In-Love', 'Innocent', 'Inpain', 'Inspired', 'Lonely', 'Lurking', 'Mellow', 'Mischievious', 'Nerdly', 'Nerdy', 'Notworthy', 'Paranoid', 'Pensive', 'Psychedelic', 'Question', 'Relaxed', 'Roflmao', 'Sad', 'Scared', 'Shocked', 'Sick', 'Sleepy', 'Sneaky', 'Snobbish', 'Spaced', 'Stressed', 'Sunshine', 'Sweettooth', 'Thinking', 'Tired', 'Twisted', 'Veggedout', 'Worried', 'Yeehaw'];
const moodI = ['https://files.jcink.net/uploads/cory//p478599.png', 'https://files.jcink.net/uploads/cory//p478511.gif', 'https://files.jcink.net/uploads/cory//p478512.gif', 'https://files.jcink.net/uploads/cory//p478513.gif', 'https://files.jcink.net/uploads/cory//p478514.gif', 'https://files.jcink.net/uploads/cory//p478515.gif', 'https://files.jcink.net/uploads/cory//p478516.gif', 'https://files.jcink.net/uploads/cory//p478517.gif', 'https://files.jcink.net/uploads/cory//p478518.gif', 'https://files.jcink.net/uploads/cory//p478520.gif', 'https://files.jcink.net/uploads/cory//p478521.gif', 'https://files.jcink.net/uploads/cory//p478522.gif', 'https://files.jcink.net/uploads/cory//p478523.gif', 'https://files.jcink.net/uploads/cory//p478524.gif', 'https://files.jcink.net/uploads/cory//p478525.gif', 'https://files.jcink.net/uploads/cory//p478526.gif', 'https://files.jcink.net/uploads/cory//p478527.gif', 'https://files.jcink.net/uploads/cory//p478528.gif', 'https://files.jcink.net/uploads/cory//p478529.gif', 'https://files.jcink.net/uploads/cory//p478530.gif', 'https://files.jcink.net/uploads/cory//p478531.gif', 'https://files.jcink.net/uploads/cory//p478532.gif', 'https://files.jcink.net/uploads/cory//p478533.gif', 'https://files.jcink.net/uploads/cory//p478534.gif', 'https://files.jcink.net/uploads/cory//p478535.gif', 'https://files.jcink.net/uploads/cory//p478536.gif', 'https://files.jcink.net/uploads/cory//p478537.gif', 'https://files.jcink.net/uploads/cory//p478538.gif', 'https://files.jcink.net/uploads/cory//p478539.gif', 'https://files.jcink.net/uploads/cory//p478540.gif', 'https://files.jcink.net/uploads/cory//p478541.gif', 'https://files.jcink.net/uploads/cory//p478542.gif', 'https://files.jcink.net/uploads/cory//p478543.gif', 'https://files.jcink.net/uploads/cory//p478544.gif', 'https://files.jcink.net/uploads/cory//p478545.gif', 'https://files.jcink.net/uploads/cory//p478546.gif', 'https://files.jcink.net/uploads/cory//p478547.gif', 'https://files.jcink.net/uploads/cory//p478548.gif', 'https://files.jcink.net/uploads/cory//p478549.gif', 'https://files.jcink.net/uploads/cory//p478550.gif', 'https://files.jcink.net/uploads/cory//p478553.gif', 'https://files.jcink.net/uploads/cory//p478554.gif', 'https://files.jcink.net/uploads/cory//p478555.gif', 'https://files.jcink.net/uploads/cory//p478556.gif', 'https://files.jcink.net/uploads/cory//p478557.gif', 'https://files.jcink.net/uploads/cory//p478558.gif', 'https://files.jcink.net/uploads/cory//p478559.gif', 'https://files.jcink.net/uploads/cory//p478560.gif', 'https://files.jcink.net/uploads/cory//p478561.gif', 'https://files.jcink.net/uploads/cory//p478562.gif', 'https://files.jcink.net/uploads/cory//p478564.gif', 'https://files.jcink.net/uploads/cory//p478565.gif', 'https://files.jcink.net/uploads/cory//p478566.gif', 'https://files.jcink.net/uploads/cory//p478567.gif', 'https://files.jcink.net/uploads/cory//p478568.gif', 'https://files.jcink.net/uploads/cory//p478569.gif', 'https://files.jcink.net/uploads/cory//p478570.gif', 'https://files.jcink.net/uploads/cory//p478571.gif', 'https://files.jcink.net/uploads/cory//p478572.gif', 'https://files.jcink.net/uploads/cory//p478573.gif', 'https://files.jcink.net/uploads/cory//p478574.gif', 'https://files.jcink.net/uploads/cory//p478575.gif', 'https://files.jcink.net/uploads/cory//p478576.gif', 'https://files.jcink.net/uploads/cory//p478577.gif', 'https://files.jcink.net/uploads/cory//p478578.gif', 'https://files.jcink.net/uploads/cory//p478579.gif', 'https://files.jcink.net/uploads/cory//p478580.gif', 'https://files.jcink.net/uploads/cory//p478581.gif', 'https://files.jcink.net/uploads/cory//p478582.gif', 'https://files.jcink.net/uploads/cory//p478583.gif', 'https://files.jcink.net/uploads/cory//p478584.gif', 'https://files.jcink.net/uploads/cory//p478585.gif', 'https://files.jcink.net/uploads/cory//p478586.gif', 'https://files.jcink.net/uploads/cory//p478587.gif', 'https://files.jcink.net/uploads/cory//p478588.gif', 'https://files.jcink.net/uploads/cory//p478589.gif'];

const label = document.querySelectorAll('label.input-label');
let value;

label.forEach(element => {
    if (element && element.innerText.includes('Mood')) {
        const input = element.parentElement.nextElementSibling.querySelector('input');
        input.style.display = 'none';

    const select = document.createElement('select');
    select.className = 'mood-select';
    select.style.width = '100%';
    select.style.maxWidth = '300px';
    select.style.padding = '6px';
    select.style.marginTop = '4px';

    for (let i = 0; i < moodN.length; i++) {
        const option = document.createElement('option');
        option.value = moodN[i];
        option.textContent = moodN[i];
        select.appendChild(option);
    }

    value = input.value || 'None';
    select.value = value;

    select.addEventListener('change', function() {
        input.value = this.value;
    });

    element.parentElement.nextElementSibling.appendChild(select);
}
});

const about = document.querySelectorAll('div.profile-about__item');

about.forEach(element => {
    if (element.querySelector('dt').innerText === 'Mood') {
        const myMood = element.querySelector('dd').innerText;

    for (let i = 0; i < moodN.length; i++) {
        if (myMood === moodN[i]) {
            element.querySelector('dd').innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
        }
    }
}
});

const mini = document.querySelectorAll('div.mini-profile--custom dt');

mini.forEach(element => {
    if (element.innerText === 'Mood') {
        const myMood = element.nextElementSibling.innerText;

    for (let i = 0; i < moodN.length; i++) {
        if (myMood === '-') {
            element.nextElementSibling.innerHTML = `<img src="${moodI[0]}" title="${moodN[0]}" alt="${moodN[0]}">`;
        } else if (myMood === moodN[i]) {
            element.nextElementSibling.innerHTML = `<img src="${moodI[i]}" title="${moodN[i]}" alt="${moodN[i]}">`;
        }
    }
}
});
</script>
Empire · 1 month ago

I’ve updated the MOOD profile field and it now works with Spark 2.0 😉 The selected mood will show on your profile and in the About Me section, with a selection of 23 moods to choose from.

Go to: Admin CP → Users & Groups → Profile Fields → Add Field

Use:
Handle: mood
Label: Mood
Show in mini profile: Enabled

One important thing. You’ll need to change the field number in the code to match the Mood field you create.

Look for:

[name="custom_field[REPLACE]"]

Replace REPLACE with your actual field number.

For example, if Spark gives your Mood field ID 9, change it to:

[name="custom_field[9]"]

The number will be different depending on your forum, so make sure you check the field you created. You may also need to make a few CSS adjustments depending on your theme especially the size, spacing and number of moods shown across the page.

That's it, once the field number is correct, the Mood picker should work. 😉

CODE:

<script>
(function () {

    'use strict';

    const MOODS = [
        'None',
        'Aggressive',
        'Amazed',
        'Amused',
        'Angelic',
        'Angry',
        'Artistic',
        'Asleep',
        'Bashful',
        'Blah',
        'Bored',
        'Breezy',
        'Brooding',
        'Busy',
        'Buzzed',
        'Chatty',
        'Cheeky',
        'Cheerful',
        'Cloud_9',
        'Cold',
        'Coldturkey',
        'Confused',
        'Cool',
        'Crappy',
        'Curious',
        'Cynical',
        'Daring',
        'Dead',
        'Depressed',
        'Devilish',
        'Doh',
        'Doubtful',
        'Drunk',
        'Energetic',
        'Fiendish',
        'Fine',
        'Flirty',
        'Gloomy',
        'Goofy',
        'Grumpy',
        'Hot',
        'Hungover',
        'In-Love',
        'Innocent',
        'Inpain',
        'Inspired',
        'Lonely',
        'Lurking',
        'Mellow',
        'Mischievious',
        'Nerdly',
        'Nerdy',
        'Notworthy',
        'Paranoid',
        'Pensive',
        'Psychedelic',
        'Question',
        'Relaxed',
        'Roflmao',
        'Sad',
        'Scared',
        'Shocked',
        'Sick',
        'Sleepy',
        'Sneaky',
        'Snobbish',
        'Spaced',
        'Stressed',
        'Sunshine',
        'Sweettooth',
        'Thinking',
        'Tired',
        'Twisted',
        'Veggedout',
        'Worried',
        'Yeehaw'
    ];

    const MOOD_IMAGES = [
        'https://files.jcink.net/uploads/cory//p478599.png',
        'https://files.jcink.net/uploads/cory//p478511.gif',
        'https://files.jcink.net/uploads/cory//p478512.gif',
        'https://files.jcink.net/uploads/cory//p478513.gif',
        'https://files.jcink.net/uploads/cory//p478514.gif',
        'https://files.jcink.net/uploads/cory//p478515.gif',
        'https://files.jcink.net/uploads/cory//p478516.gif',
        'https://files.jcink.net/uploads/cory//p478517.gif',
        'https://files.jcink.net/uploads/cory//p478518.gif',
        'https://files.jcink.net/uploads/cory//p478520.gif',
        'https://files.jcink.net/uploads/cory//p478521.gif',
        'https://files.jcink.net/uploads/cory//p478522.gif',
        'https://files.jcink.net/uploads/cory//p478523.gif',
        'https://files.jcink.net/uploads/cory//p478524.gif',
        'https://files.jcink.net/uploads/cory//p478525.gif',
        'https://files.jcink.net/uploads/cory//p478526.gif',
        'https://files.jcink.net/uploads/cory//p478527.gif',
        'https://files.jcink.net/uploads/cory//p478528.gif',
        'https://files.jcink.net/uploads/cory//p478529.gif',
        'https://files.jcink.net/uploads/cory//p478530.gif',
        'https://files.jcink.net/uploads/cory//p478531.gif',
        'https://files.jcink.net/uploads/cory//p478532.gif',
        'https://files.jcink.net/uploads/cory//p478533.gif',
        'https://files.jcink.net/uploads/cory//p478534.gif',
        'https://files.jcink.net/uploads/cory//p478535.gif',
        'https://files.jcink.net/uploads/cory//p478536.gif',
        'https://files.jcink.net/uploads/cory//p478537.gif',
        'https://files.jcink.net/uploads/cory//p478538.gif',
        'https://files.jcink.net/uploads/cory//p478539.gif',
        'https://files.jcink.net/uploads/cory//p478540.gif',
        'https://files.jcink.net/uploads/cory//p478541.gif',
        'https://files.jcink.net/uploads/cory//p478542.gif',
        'https://files.jcink.net/uploads/cory//p478543.gif',
        'https://files.jcink.net/uploads/cory//p478544.gif',
        'https://files.jcink.net/uploads/cory//p478545.gif',
        'https://files.jcink.net/uploads/cory//p478546.gif',
        'https://files.jcink.net/uploads/cory//p478547.gif',
        'https://files.jcink.net/uploads/cory//p478548.gif',
        'https://files.jcink.net/uploads/cory//p478549.gif',
        'https://files.jcink.net/uploads/cory//p478550.gif',
        'https://files.jcink.net/uploads/cory//p478553.gif',
        'https://files.jcink.net/uploads/cory//p478554.gif',
        'https://files.jcink.net/uploads/cory//p478555.gif',
        'https://files.jcink.net/uploads/cory//p478556.gif',
        'https://files.jcink.net/uploads/cory//p478557.gif',
        'https://files.jcink.net/uploads/cory//p478558.gif',
        'https://files.jcink.net/uploads/cory//p478559.gif',
        'https://files.jcink.net/uploads/cory//p478560.gif',
        'https://files.jcink.net/uploads/cory//p478561.gif',
        'https://files.jcink.net/uploads/cory//p478562.gif',
        'https://files.jcink.net/uploads/cory//p478564.gif',
        'https://files.jcink.net/uploads/cory//p478565.gif',
        'https://files.jcink.net/uploads/cory//p478566.gif',
        'https://files.jcink.net/uploads/cory//p478567.gif',
        'https://files.jcink.net/uploads/cory//p478568.gif',
        'https://files.jcink.net/uploads/cory//p478569.gif',
        'https://files.jcink.net/uploads/cory//p478570.gif',
        'https://files.jcink.net/uploads/cory//p478571.gif',
        'https://files.jcink.net/uploads/cory//p478572.gif',
        'https://files.jcink.net/uploads/cory//p478573.gif',
        'https://files.jcink.net/uploads/cory//p478574.gif',
        'https://files.jcink.net/uploads/cory//p478575.gif',
        'https://files.jcink.net/uploads/cory//p478576.gif',
        'https://files.jcink.net/uploads/cory//p478577.gif',
        'https://files.jcink.net/uploads/cory//p478578.gif',
        'https://files.jcink.net/uploads/cory//p478579.gif',
        'https://files.jcink.net/uploads/cory//p478580.gif',
        'https://files.jcink.net/uploads/cory//p478581.gif',
        'https://files.jcink.net/uploads/cory//p478582.gif',
        'https://files.jcink.net/uploads/cory//p478583.gif',
        'https://files.jcink.net/uploads/cory//p478584.gif',
        'https://files.jcink.net/uploads/cory//p478585.gif',
        'https://files.jcink.net/uploads/cory//p478586.gif',
        'https://files.jcink.net/uploads/cory//p478587.gif',
        'https://files.jcink.net/uploads/cory//p478588.gif',
        'https://files.jcink.net/uploads/cory//p478589.gif'
    ];

    function addStyles() {

        if (document.getElementById('ek-mood-style')) {
            return;
        }

        const style = document.createElement('style');

        style.id = 'ek-mood-style';

        style.textContent = `

            .ek-mood-picker {
                display: grid;
                grid-template-columns: repeat(10, 82px);
                gap: 5px;
                width: fit-content;
                max-width: 100%;
                margin-top: 8px;
                padding: 6px;
                box-sizing: border-box;
                border-radius: 6px;
                background: rgba(0,0,0,.12);
            }

            .ek-mood-picker button {
                appearance: none;
                display: flex;
                align-items: center;
                justify-content: center;
                width: 82px;
                height: 30px;
                padding: 2px;
                margin: 0;
                border: 1px solid rgba(255,255,255,.10);
                border-radius: 4px;
                background: rgba(255,255,255,.035);
                cursor: pointer;
                box-sizing: border-box;
                transition:
                    background .15s ease,
                    border-color .15s ease,
                    transform .15s ease,
                    box-shadow .15s ease;
            }

            .ek-mood-picker button:hover {
                background: rgba(255,255,255,.10);
                border-color: rgba(255,255,255,.28);
                transform: translateY(-1px);
                box-shadow: 0 2px 6px rgba(0,0,0,.20);
            }

            .ek-mood-picker button.ek-mood-selected {
                background: rgba(255,255,255,.12);
                border-color: rgba(255,255,255,.60);
                box-shadow:
                    0 0 0 1px rgba(255,255,255,.06),
                    0 2px 7px rgba(0,0,0,.25);
            }

            .ek-mood-picker img {
                display: block;
                width: auto;
                height: 23px;
                max-width: 76px;
                object-fit: contain;
                pointer-events: none;
            }

            .ek-profile-mood {
                display: inline-block;
                width: auto;
                height: 30px;
                max-width: 93px;
                object-fit: contain;
                vertical-align: middle;
            }

            .ek-mini-mood {
                display: inline-block;
                width: auto;
                height: 26px;
                max-width: 82px;
                object-fit: contain;
                vertical-align: middle;
            }

            @media (max-width: 950px) {

                .ek-mood-picker {
                    grid-template-columns: repeat(8, 82px);
                }

                .ek-mood-picker button {
                    width: 82px;
                }

            }

            @media (max-width: 750px) {

                .ek-mood-picker {
                    grid-template-columns: repeat(6, 78px);
                }

                .ek-mood-picker button {
                    width: 78px;
                }

                .ek-mood-picker img {
                    max-width: 72px;
                }

            }

            @media (max-width: 550px) {

                .ek-mood-picker {
                    grid-template-columns: repeat(5, 70px);
                }

                .ek-mood-picker button {
                    width: 70px;
                }

                .ek-mood-picker img {
                    max-width: 65px;
                }

            }

            @media (max-width: 400px) {

                .ek-mood-picker {
                    grid-template-columns: repeat(3, 70px);
                }

                .ek-mood-picker button {
                    width: 70px;
                }

            }

        `;

        document.head.appendChild(style);
    }

    function addMoodPicker() {

        const input = document.querySelector(
            'input[name="custom_field[9]"]'
        );

        if (!input) {
            return;
        }

        if (document.querySelector('.ek-mood-picker')) {
            return;
        }

        input.style.display = 'none';

        const picker = document.createElement('div');

        picker.className = 'ek-mood-picker';

        const currentMood =
            input.value.trim();

        MOODS.forEach(function (mood, index) {

            const button =
                document.createElement('button');

            button.type = 'button';
            button.title = mood;

            button.setAttribute(
                'aria-label',
                mood
            );

            const image =
                document.createElement('img');

            image.src =
                MOOD_IMAGES[index];

            image.alt =
                mood;

            image.loading =
                'lazy';

            button.appendChild(image);

            if (
                currentMood.toLowerCase() ===
                mood.toLowerCase()
            ) {

                button.classList.add(
                    'ek-mood-selected'
                );

            }

            button.addEventListener(
                'click',
                function () {

                    input.value = mood;

                    input.dispatchEvent(
                        new Event(
                            'input',
                            { bubbles: true }
                        )
                    );

                    input.dispatchEvent(
                        new Event(
                            'change',
                            { bubbles: true }
                        )
                    );

                    picker
                        .querySelectorAll('button')
                        .forEach(function (item) {

                            item.classList.remove(
                                'ek-mood-selected'
                            );

                        });

                    button.classList.add(
                        'ek-mood-selected'
                    );

                }
            );

            picker.appendChild(button);

        });

        input.parentElement.appendChild(picker);
    }

    function findMood(mood) {

        if (!mood) {
            return -1;
        }

        const cleanMood =
            mood.trim().toLowerCase();

        return MOODS.findIndex(function (item) {

            return item.toLowerCase() ===
                cleanMood;

        });
    }

    function makeMoodImage(index, className) {

        if (index < 0 || index >= MOOD_IMAGES.length) {
            return null;
        }

        const image =
            document.createElement('img');

        image.className =
            className;

        image.src =
            MOOD_IMAGES[index];

        image.alt =
            MOODS[index];

        image.title =
            MOODS[index];

        image.loading =
            'lazy';

        image.decoding =
            'async';

        return image;
    }

    function displayPublicProfileMood() {

        document
            .querySelectorAll('p')
            .forEach(function (row) {

                const spans =
                    row.querySelectorAll(':scope > span');

                const bolds =
                    row.querySelectorAll(':scope > b');

                if (
                    spans.length === 0 ||
                    bolds.length === 0
                ) {
                    return;
                }

                const label =
                    spans[0].textContent
                        .trim()
                        .toLowerCase();

                if (label !== 'mood') {
                    return;
                }

                const value =
                    bolds[0];

                if (
                    value.querySelector(
                        '.ek-profile-mood'
                    )
                ) {
                    return;
                }

                const mood =
                    value.textContent.trim();

                let index =
                    findMood(mood);

                if (
                    mood === '' ||
                    mood === '-'
                ) {
                    index = 0;
                }

                if (index === -1) {
                    return;
                }

                const image =
                    makeMoodImage(
                        index,
                        'ek-profile-mood'
                    );

                if (!image) {
                    return;
                }

                value.replaceChildren(image);

            });
    }

    function displayOldProfileMood() {

        document
            .querySelectorAll(
                'div.profile-about__item'
            )
            .forEach(function (item) {

                const label =
                    item.querySelector('dt');

                const value =
                    item.querySelector('dd');

                if (!label || !value) {
                    return;
                }

                if (
                    label.textContent
                        .trim()
                        .toLowerCase() !== 'mood'
                ) {
                    return;
                }

                if (
                    value.querySelector(
                        '.ek-profile-mood'
                    )
                ) {
                    return;
                }

                const mood =
                    value.textContent.trim();

                let index =
                    findMood(mood);

                if (
                    mood === '' ||
                    mood === '-'
                ) {
                    index = 0;
                }

                if (index === -1) {
                    return;
                }

                const image =
                    makeMoodImage(
                        index,
                        'ek-profile-mood'
                    );

                if (!image) {
                    return;
                }

                value.replaceChildren(image);

            });
    }

    function displayMiniMood() {

        document
            .querySelectorAll(
                'div.mini-profile--custom dt'
            )
            .forEach(function (label) {

                if (
                    label.textContent
                        .trim()
                        .toLowerCase() !== 'mood'
                ) {
                    return;
                }

                const value =
                    label.nextElementSibling;

                if (!value) {
                    return;
                }

                if (
                    value.querySelector(
                        '.ek-mini-mood'
                    )
                ) {
                    return;
                }

                const mood =
                    value.textContent.trim();

                let index =
                    findMood(mood);

                if (
                    mood === '' ||
                    mood === '-'
                ) {
                    index = 0;
                }

                if (index === -1) {
                    return;
                }

                const image =
                    makeMoodImage(
                        index,
                        'ek-mini-mood'
                    );

                if (!image) {
                    return;
                }

                value.replaceChildren(image);

            });
    }

    function updateProfiles() {

        displayPublicProfileMood();
        displayOldProfileMood();
        displayMiniMood();

    }

    function run() {

        addStyles();
        addMoodPicker();
        updateProfiles();

        const observer =
            new MutationObserver(function () {

                updateProfiles();

            });

        observer.observe(
            document.body,
            {
                childList: true,
                subtree: true
            }
        );

    }

    if (
        document.readyState === 'loading'
    ) {

        document.addEventListener(
            'DOMContentLoaded',
            run
        );

    } else {

        run();

    }

})();
</script>

Cory OP · 1 month ago

Added the link to your version in both OPs, @empire.

Create a free account to join the conversation.
Sign up free
ForumSpark © 2023 - 2026 · ForumSpark.net · Terms