Jump to content
  • entry
    1
  • comments
    2
  • views
    214

Rocky.js --The whole story


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.

image.png.a1f1912772968264f32b1a5b89bd7ca4.png

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….

image.thumb.png.1e1f83eb8c8b6d979c4a5172a3372564.png

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.

image.png.0d032a4bf8558844b1b7f58f70b53a1b.png

Well.. After taunting me first 😡

image.thumb.png.9c6c0e4dfe56cb989c08a72dfad080be.png

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!!!

image.thumb.png.0d60490a42ac1e04089ff6783d69251d.png

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:)

 

2 Comments


Recommended Comments

KaladinsSenseOfHumourSpren

Posted

You know you can insert code 

(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 rangWhats here, question???);

            const sel = window.getSelection();

            range.setStart(target.childNodes[0], newValue.length);

            range.collapse(true);

            sel.removeAllRanges();

            sel.addRange(range);

        }

    });

})();

})();

 

TheUnInvestedCremling

Posted

2 hours ago, KaladinsSenseOfHumourSpren said:

You know you can insert code 

(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 rangWhats here, question???);

            const sel = window.getSelection();

            range.setStart(target.childNodes[0], newValue.length);

            range.collapse(true);

            sel.removeAllRanges();

            sel.addRange(range);

        }

    });

})();

})();

 

Oh, dayum, thanks

×
×
  • Create New...