Bitcoin Forum

Other => Meta => Topic started by: PowerGlove on September 16, 2024, 06:08:01 AM



Title: Help me test something?
Post by: PowerGlove on September 16, 2024, 06:08:01 AM
Hey, everybody! :)

A while ago, I did a patch (https://bitcointalk.org/index.php?topic=5485720) to add a "Copy" button to [code] blocks. Thinking about it a little more, I think a "[Select]" link (like the one I've seen in later SMF versions) might actually make more sense...

After coming up with my own implementation of this, I took a peek at what the SMF devs did for 2.x and noticed that they're special-casing things for different browsers. I'd like to know if that special-casing is still necessary these days, so I'd appreciate some help with testing this on different browsers.

Basically, go to any forum page that contains [code] blocks (like the page you're currently on), and then open up the developer console in your browser and paste/run the following code:

Code:
function addSelectionLinksToCodeBlocks() {

    const allCodeDivs = document.querySelectorAll("div.codeheader + div.code");

    for (const codeDiv of allCodeDivs) {

        const codeHeaderDiv = codeDiv.previousElementSibling;

        if (!codeHeaderDiv.querySelector("a.selectionLink")) {

            const selectionLink = document.createElement("a");

            selectionLink.onclick = () => {

                const range = document.createRange();

                const selection = document.getSelection();

                range.selectNodeContents(codeDiv);

                selection.removeAllRanges();

                selection.addRange(range);

                return false;
            };

            selectionLink.className = "selectionLink";

            selectionLink.href = "javascript:void(0);";

            selectionLink.textContent = "[Select]";

            codeHeaderDiv.appendChild(document.createTextNode(" "));

            codeHeaderDiv.appendChild(selectionLink);
        }
    }
}

addSelectionLinksToCodeBlocks();

(Make sure to copy it in its entirety and to hit enter after pasting it.)

You should now see that each [code] block has a little "[Select]" link at the top. Click on that link and check if the code for that block gets correctly selected or not.

If it doesn't work for you, then please post your browser details (just the name and version will do).

If you have thoughts about preferring the "[Select]" link to the "Copy" button (or vice versa), feel free to leave those, too.

Thanks.

(I'm not really looking for code critiques. If you're a programmer and something looks odd to you, probably I'm either sticking to some established SMF 1.x idiom, or it's because I had to write this code in a particular way to get Cloudflare's WAF to stop blocking me from posting it.)


Title: Re: Help me test something?
Post by: Learn Bitcoin on September 16, 2024, 06:11:37 AM
It worked like a charm for me.
I guess you don't need my browser details since it worked. But I am using Microsoft Edge.
I have been seeing this feature on another forum. Since then, I was wondering if this forum can add this feature, to help users copy pasting the codes correctly. Mostly the signature participants can't copy paste the code in mobile device. Well done.

https://talkimg.com/images/2024/09/16/BeH3N.png


Title: Re: Help me test something?
Post by: garlonicon on September 16, 2024, 07:40:19 AM
It works for me:
Code:
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0
Edit: Also works here:
Code:
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0
Edit: More working browsers:
Code:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0


Title: Re: Help me test something?
Post by: Alpha Marine on September 16, 2024, 01:17:13 PM
It worked just fine on my Google Chrome browser.
I used Chrome Version 128.0.6613.138
https://talkimg.com/images/2024/09/16/Bqo5H.png (https://talkimg.com/image/Bqo5H)


Title: Re: Help me test something?
Post by: examplens on September 16, 2024, 01:51:42 PM
It works fine for all code tags on this page.
It's latest Chrome Version 128.0.6613.138

https://talkimg.com/images/2024/09/16/B02Q8.png


Title: Re: Help me test something?
Post by: UserU on September 17, 2024, 03:22:40 PM
So far so good, works on Brave browser (v1.69.168)

https://www.talkimg.com/images/2024/09/17/ga5UP.png


Title: Re: Help me test something?
Post by: un_rank on September 18, 2024, 02:59:09 PM
Works well on Firefox and Tor

https://www.talkimg.com/images/2024/09/18/gHnYo.png

Copying the code for this made me realize why this code will be useful.

If you have thoughts about preferring the "[Select]" link to the "Copy" button (or vice versa), feel free to leave those, too.
Both work very fine, but the tricky part is selecting the entire text a it is, hitting ctrl C is easy.

- Jay -