So basically, a fortnight ago, I read and watched Andy Weir’s Project Hail Mary.
Due to a rock shaped alien called Rocky’s special characteristics, me and my friend @KaladinsSenseOfHumourSpren were always conversing in Grace’s highly questionable Eridian to English translator. We would use phrases like Amaze! And What are you doing right now, question? For some joy in our day to day conversation. Me (being very lazy) decided my fingers were getting more sore after typing the added PHM english, so I set out to make a js script that’d do it for me.
Day 1.
Why am I doing this, question?
I had little to none knowledge of javascript and I DID NOT want to vibe code !! I knew the basics so i laid out my starting code
(function() {
What to do now….
Day 2.
I spend most of day one researching and found stuff that would help me greatly. I just now have finished my draft code.
(function() {
'use strict';
(function() {
'use strict';
document.addEventListener('keyup', function(e) {
const target = e.target;
if (target.getAttribute('contenteditable') === 'true' && target.innerText.includes('?')) {
const selection = window.getSelection();
const cursorPos = selection.anchorOffset;
if (target.innerText.endsWith('?')) {
const newValue = target.innerText.replace(/\?$/, ', question?');
target.innerText = newValue;
const range = document.createRange();
const sel = window.getSelection();
range.setStart(target.childNodes[0], newValue.length);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
});
})();
})();
I was using Tampermonkey and I tested it.
Nothing.
Why?
Day 3.
After the roadblock, I tinkered with it (Did nothing) and sighed. WHYY, QUESTION? WHYYY.
Then, my deepfried brain had an idea and i got my js, and pasted it onto the console
(Do not paste any code that you don’t know about on the console or you may get hacked)
AMAZE! AMAZE! AMAZE!
It worked.
Day 4.
It worked on the console.. YES.
Buttttt….
The questions always came twice..
Why?
At this point, I needed some help.
@KaladinsSenseOfHumourSpren was/is really good at javascript, so I gave him the code and the problem.
@KaladinsSenseOfHumourSpren, being @KaladinsSenseOfHumourSpren, figured it out immediately.
Well.. After taunting me first
There it was. The magic fix!
And I’m going to fix this n-
I slept.
Day 5.
I added the check and everything the code looks fine.
(function() {
'use strict';
(function() {
'use strict';
document.addEventListener('input', function(e) {
const target = e.target;
if (target.getAttribute('contenteditable') === 'true' && target.innerText.includes('?') && target.innerText.endsWith('?') && !target.innerText.includes(', question?')) {
const newValue = target.innerText.replace(/\?$/, ', question?');
target.innerText = newValue;
const rangWhat’s here, question???);
const sel = window.getSelection();
range.setStart(target.childNodes[0], newValue.length);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
});
})();
})();
(OOH cOlOur)
It was time for the BIG TEST!!!
I added it to my console
AND AMAZE, AMAZE, AMAZE!!!
I’m finally done. Yippee.
I’m content
Day 6.
I'm not content.
I wish it was automatic
So I scoured the Chrome Web Store.
Orangemonkey
Yes.
It was calling to me.
I installed it, added my code…
My work… Was done.
(also bdw how to remove the autobold, as i type my blogs in docs and then paste here:)