skip to Main Content

I have try this way, but some of site like bingChat not allow me to do that.

javascript:(function() {
    var currentDateTime = new Date();
    document.activeElement.value += currentDateTime;
})();

Also tried this way, but still work not well. Because I need to write some logs in company website, thus I want to insert time by just click a button. Thus I can insert data anywhere.

javascript:(function() {
    var currentDateTime = new Date();
    var activeElement = document.activeElement;
    if (activeElement && activeElement.tagName.toLowerCase() === 'textarea') {
        var startPos = activeElement.selectionStart;
        var endPos = activeElement.selectionEnd;
        activeElement.value = activeElement.value.substring(0, startPos) + currentDateTime + activeElement.value.substring(endPos, activeElement.value.length);
        activeElement.selectionStart = startPos + currentDateTime.toString().length;
        activeElement.selectionEnd = startPos + currentDateTime.toString().length;
    } else {
        alert('Please place your cursor in a text area.');
    }
})();

If cannot do, just copy the time to cilpboard is OK.

For bingChat, the activeElement I got is: cib-text-input, but textarea is one of the offspring.

2

Answers


  1. Chosen as BEST ANSWER

    This is my walkaround, just put the current time in the clipboard, then paste it...

    javascript:(function() {
        var currentDateTime = new Date().toLocaleString();
        navigator.clipboard.writeText(currentDateTime).then(function() {
            console.log('Copying to clipboard was successful!');
        }, function(err) {
            console.error('Could not copy text: ', err);
        });
    })();
    

  2. I couldn’t get it to work with the address bar, but you could right click on the textarea, Inspect, and then paste in $0.value += new Date(); into the console tab.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search