Bitcoin Forum
April 04, 2026, 09:57:06 AM *
News: Latest Bitcoin Core release: 30.2 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcointalk Keep Caret Visible  (Read 96 times)
Halifat (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile
April 03, 2026, 09:22:15 PM
Last edit: April 03, 2026, 10:35:36 PM by Halifat
 #1

I normally use mobile phone to navigate around the forum but anytime I come to make post or make a reply I find it difficult to figure out some things when making my post or reply.

The challenge i normally faced when typing in the reply box, I realized that anytime I'm typing the cursor normally get out of my view especially if the post is long, and as for me I normally zoom the reply box because if I decided to leave it like that i can't be able to see clearly, so I decided to make a tools for myself so that the cursor will be visible even though I zoom the reply box.


What it's does?

It eliminate stress of scrolling side(left /right) with your hand just to see what you're typing and also it makes you focus directly to what you are typing.


How it works?
Get a tempermonkey extension and insert the userscript below.


Code:
// ==UserScript==
// @name         Bitcointalk Keep Caret Visible v2
// @namespace    https://bitcointalk.org/
// @version      2.0
// @description  Keeps the caret visible inside Bitcointalk textareas and scrolls the page to keep the active editor in view.
// @match        https://bitcointalk.org/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const CONFIG = {
        textareaMarginLines: 2,
        pageMarginPx: 120,
        smoothPageScroll: true,
        smoothBehavior: 'smooth',
        debug: false
    };

    function log(...args) {
        if (CONFIG.debug) console.log('[BTT Caret]', ...args);
    }

    function isVisible(el) {
        if (!el || !el.isConnected) return false;
        const style = getComputedStyle(el);
        return style.display !== 'none' &&
               style.visibility !== 'hidden' &&
               el.offsetParent !== null;
    }

    function toPxNumber(value, fallback = 0) {
        const n = parseFloat(value);
        return Number.isFinite(n) ? n : fallback;
    }

    function getLineHeight(style) {
        let lh = toPxNumber(style.lineHeight, NaN);
        if (!Number.isFinite(lh)) {
            const fs = toPxNumber(style.fontSize, 16);
            lh = fs * 1.2;
        }
        return lh;
    }

    function copyTextareaStyles(src, dst) {
        const style = getComputedStyle(src);
        const props = [
            'boxSizing',
            'width',
            'height',
            'overflowX',
            'overflowY',

            'borderTopWidth',
            'borderRightWidth',
            'borderBottomWidth',
            'borderLeftWidth',
            'borderStyle',

            'paddingTop',
            'paddingRight',
            'paddingBottom',
            'paddingLeft',

            'fontStyle',
            'fontVariant',
            'fontWeight',
            'fontStretch',
            'fontSize',
            'lineHeight',
            'fontFamily',

            'textAlign',
            'textTransform',
            'textIndent',
            'textDecoration',
            'letterSpacing',
            'wordSpacing',

            'tabSize',
            'MozTabSize',
            'whiteSpace',
            'wordBreak',
            'overflowWrap'
        ];

        props.forEach((prop) => {
            dst.style[prop] = style[prop];
        });

        return style;
    }

    function getCaretCoordinates(textarea, position) {
        const mirror = document.createElement('div');
        const span = document.createElement('span');
        const style = copyTextareaStyles(textarea, mirror);

        mirror.style.position = 'absolute';
        mirror.style.visibility = 'hidden';
        mirror.style.left = '-999999px';
        mirror.style.top = '0';
        mirror.style.whiteSpace = 'pre-wrap';
        mirror.style.wordWrap = 'break-word';
        mirror.style.overflow = 'hidden';

        const value = textarea.value;
        const before = value.slice(0, position);
        const after = value.slice(position);

        mirror.textContent = before;
        span.textContent = after.length ? after[0] : '\u200b';
        mirror.appendChild(span);
        document.body.appendChild(mirror);

        const paddingTop = toPxNumber(style.paddingTop);
        const paddingLeft = toPxNumber(style.paddingLeft);

        const coords = {
            top: span.offsetTop + paddingTop,
            left: span.offsetLeft + paddingLeft
        };

        document.body.removeChild(mirror);
        return coords;
    }

    function keepCaretVisibleInTextarea(textarea) {
        if (!textarea || textarea.selectionStart == null || !isVisible(textarea)) return;

        const style = getComputedStyle(textarea);
        const lineHeight = getLineHeight(style);
        const margin = lineHeight * CONFIG.textareaMarginLines;

        const caret = getCaretCoordinates(textarea, textarea.selectionStart);
        const visibleTop = textarea.scrollTop;
        const visibleBottom = visibleTop + textarea.clientHeight;

        const caretTop = caret.top;
        const caretBottom = caretTop + lineHeight;

        let nextScrollTop = textarea.scrollTop;

        if (caretBottom + margin > visibleBottom) {
            nextScrollTop = Math.max(0, caretBottom - textarea.clientHeight + margin);
        } else if (caretTop - margin < visibleTop) {
            nextScrollTop = Math.max(0, caretTop - margin);
        }

        if (Math.abs(nextScrollTop - textarea.scrollTop) > 1) {
            textarea.scrollTop = nextScrollTop;
        }
    }

    function getViewportTop() {
        return window.pageYOffset || document.documentElement.scrollTop || 0;
    }

    function getViewportBottom() {
        return getViewportTop() + window.innerHeight;
    }

    function scrollPageToKeepTextareaVisible(textarea) {
        if (!textarea || !isVisible(textarea)) return;

        const rect = textarea.getBoundingClientRect();
        const
I stand to be corrected, and I'm open for any new knowledge.
Upgrade00
Legendary
*
Offline Offline

Activity: 2730
Merit: 2865


Community Manager - Brand Promotions ✅


View Profile WWW
April 03, 2026, 09:43:11 PM
 #2

You should show how the extension will be displayed if a user activates it. It's usually not easy for users to trust extensions even if they are posted by very reputable members. If it's not posted by such member and there's no way to see how it will be useful, you will get even less users. Give a detailed graphic of how it will look and help fix the problem you highlighted, even though it's not one that has bothered me much.

I stand to be corrected, and I'm open for any new knowledge.
There's nothing to be corrected for. If it works for you that's all that matters.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
Ambatman
Legendary
*
Offline Offline

Activity: 966
Merit: 1269


Don't tell anyone


View Profile WWW
April 03, 2026, 09:47:02 PM
 #3

I haven't really noticed it in PC
Since I'm majorly online here with my mobile
I don't know it feels a little refreshing that there's a problem only unique to PCs.
But like was stated upstairs
Many are skeptical towards extensions (well I am many) and have never used any.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
PX-Z
Legendary
*
Offline Offline

Activity: 2142
Merit: 1294


Wallet Transaction Notifier - @txnNotifierBot


View Profile
April 03, 2026, 09:57:05 PM
 #4

You should show how the extension will be displayed if a user activates it. It's usually not easy for users to trust extensions even if they are posted by very reputable members. If it's not posted by such member and there's no way to see how it will be useful, you will get even less users. Give a detailed graphic of how it will look and help fix the problem you highlighted, even though it's not one that has bothered me much.
Yes, at least a screenshot to see how it looks in the browser for people to try because, its easy to describe additional function/feature using a set of images or even just a single image. So OP, it's better to update the OP with image/s.

 
 b1exch.to 
  ETH      DAI   
  BTC      LTC   
  USDT     XMR    
.███████████▄▀▄▀
█████████▄█▄▀
███████████
███████▄█▀
█▀█
▄▄▀░░██▄▄
▄▀██▄▀█████▄
██▄▀░▄██████
███████░█████
█░████░█████████
█░█░█░████░█████
█░█░█░██░█████
▀▀▀▄█▄████▀▀▀
Halifat (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile
April 03, 2026, 10:37:40 PM
 #5

You should show how the extension will be displayed if a user activates it. It's usually not easy for users to trust extensions even if they are posted by very reputable members. If it's not posted by such member and there's no way to see how it will be useful, you will get even less users. Give a detailed graphic of how it will look and help fix the problem you highlighted, even though it's not one that has bothered me much.
Yes, at least a screenshot to see how it looks in the browser for people to try because, its easy to describe additional function/feature using a set of images or even just a single image. So OP, it's better to update the OP with image/s.
I have put the sample of how it works, if you look at it closely you can see it is automatically moving sideways which was my aim, so I will be happy if you try it and tell me how you feel when using it.
mikel_012
Hero Member
*****
Offline Offline

Activity: 728
Merit: 524


Spinly.io - Next-gen Crypto iGaming Platform


View Profile
April 03, 2026, 11:46:43 PM
 #6

Is it not better if you make a script to make the post writing text box the size of the screen so when you are typing it breaks the line? This way you see everything you are writing instead of having the text area go out of the screen to the right?

Maybe it will help more than just moving the screen to show the cursor. Smiley


░▄████████████▀▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▄██
████████████░█▀
████░▄▄▄███████
████▄▄▄▄▄▄▄▄░▄██
▀▀▀▀▀▀▀▀████░███
████████████░███
████████████░█▀

░▄████████████▀▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▄██
████████████░███
████████████░███
████████████░███
████▄▄▄▄████░██▀
████▀▀▀▀▀▀▀▀░▀
████░█▀

░▄████████████▀▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▄██
████████████░█▀
█████████░▄▄▄
█████████░███
░▄░██████░██▀██
▀▀░██████░▀██▄██
████████████░█▀

░▄███████▀░▄██▀▄
▀▀▀▀▀▀▀▀██▀▀▀▄██
████████████░███
████████████░███
██░▄░███████░███
██░█░███████░███
████████████░███
████████████░█▀

░▄██████▀▄
▀▀▀▀▀▀▀▄██
██████░███
██████░███
██████░███
██████░███████▀▄
██████░▀▀▀▀▀▀▄██
████████████░█▀

░▄████▀██▄█████▀▄
▀▀▀▀▀███▀▀▀▀▀▀▄██
█████████████░███
█████░█░█████░███
█████░▀░█████░███
█████████████░█▀
██████████░▄▄▄
██████████░█▀
 
.....  Next−Gen Crypto iGaming  .....
| 
     Play now      
SeriouslyGiveaway
Full Member
***
Offline Offline

Activity: 686
Merit: 232


Bitz.io Best Bitcoin and Crypto Casino


View Profile
Today at 12:38:49 AM
 #7

I normally use mobile phone to navigate around the forum but anytime I come to make post or make a reply I find it difficult to figure out some things when making my post or reply.

The challenge i normally faced when typing in the reply box, I realized that anytime I'm typing the cursor normally get out of my view especially if the post is long, and as for me I normally zoom the reply box because if I decided to leave it like that i can't be able to see clearly, so I decided to make a tools for myself so that the cursor will be visible even though I zoom the reply box.
I don't really see this inconvenience but I agree that using mobile for typing is always inconvenient and annoying. It's harder than typing with keyboard on computer or on laptop but it's basic issue of mobile devices without keyboards but with small screens.

From your short video to illustrates how the extension works, I don't really see it is helpful (I am not offending you as I know you spent time for it, and I appreciate that) and somewhat I see it is annoying too. When you're typing, the long line shifts to the right while the left side is missing / trimming, it's really hard to know what I was typing in earliest words of the post.

Halifat (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile
Today at 05:33:38 AM
 #8

Is it not better if you make a script to make the post writing text box the size of the screen so when you are typing it breaks the line? This way you see everything you are writing instead of having the text area go out of the screen to the right?

Maybe it will help more than just moving the screen to show the cursor. Smiley

I definitely understand all what you have saying, it is called Auto-fit or Reflow zoom, thank you so much for calling my attention to this notice. This features is found in UC Browser and honestly it was amazing, I will put this in my top list.

I don't really see this inconvenience but I agree that using mobile for typing is always inconvenient and annoying. It's harder than typing with keyboard on computer or on laptop but it's basic issue of mobile devices without keyboards but with small screens.

From your short video to illustrates how the extension works, I don't really see it is helpful (I am not offending you as I know you spent time for it, and I appreciate that) and somewhat I see it is annoying too. When you're typing, the long line shifts to the right while the left side is missing / trimming, it's really hard to know what I was typing in earliest words of the post.

I like your comment because this will motivate me to think deep whenever I'm doing something new for public to access, but i like to disagree with what you said about not seeing what you have written previously, we always speak out from our mind not copying from somewhere else and I expected that if something is coming out from your mind definitely you can be able to reverse it with any difficulties.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!