We've Moved! Visit our NEW FORUM to join the latest discussions. This is an archive of our previous conversations...

You can find the login page for the old forum here.
CHATPRIVACYDONATELOGINREGISTER
DMT-Nexus
FAQWIKIHEALTH & SAFETYARTATTITUDEACTIVE TOPICS
Improving the Nexus experience with userscripts (#2: the chat!) Options
 
safrol
#1 Posted : 12/3/2015 6:48:51 PM

DMT-Nexus member


Posts: 19
Joined: 03-Oct-2015
Last visit: 08-Aug-2021
Dear fellow travelers,

have you ever entered something in the forum search, hit enter, and realized you have to painstakingly click the "Search" button? Your suffering ends today!
I've written a small so-called userscript - a javascript file that is to be installed via the Firefox addon Greasemonkey (in case you're using Chrome there's Tampermonkey, which claims to be compatible) to change the behaviour/looks of specific websites - to add this functionality to the forum search.

This is the code:
Code:
// ==UserScript==
// @name          Nexus Search Tweak
// @description   Nexus Search will react to keypress of Return
// @include       https://www.dmt-nexus.me/forum/default.aspx?g=search
// @version       0.15
// ==/UserScript==

//use jquery that is already included
var $ = unsafeWindow.jQuery;

//main functionality
$("#forum_ctl01_txtSearchStringFromWho, #forum_ctl01_txtHeaderSearchStringWhat, #forum_ctl01_txtSearchStringWhat")
    .keyup(function(event){
     if(event.keyCode == 13){
        $("#forum_ctl01_btnSearch").click();
    }
});



Please have a short look at the source and verify that there's nothing else going on (e.g. messing with your security).

Installation:
  • install Greasemonkey/Tampermonkey/etc.
  • copy the source or get it here
  • Save File (needs to end with .user.js)
  • Open File with your favorite compatible browser
  • Greasemonkey will prompt an installation dialog

Congratulations, you may now start your forum search by pressing Enter/Return when focus is in one of the textfields!

By the way, if you're into programming, it's really easy to get started. I recommend the Greasemonkey Wiki and Firebug for development. You can change your favourite websites or see what others have created and use their scripts!

Finally, I'd love to hear your requests for other scripts!
What features have you always missed on the Nexus forum/chat?


Thank you, Nexus. <3 Love
 

Good quality Syrian rue (Peganum harmala) for an incredible price!
 
safrol
#2 Posted : 4/3/2017 7:54:40 PM

DMT-Nexus member


Posts: 19
Joined: 03-Oct-2015
Last visit: 08-Aug-2021
This script will enable tab completion for the chat, inspired by IRC.


It works like this: you type the first letter(s) of the username you want, press <TAB> and see the matching name(s) appear. If there are more than one matching names, you may cycle through them by pressing <TAB> repeatedly. You may also cycle through all the names if your current input is empty.

I tested it with Firefox/Greasemonkey and Chromium/Tampermonkey on Linux, if you have any problems feel free to ask Smile Also feedback on the code is greatly appreciated!

There's one issue: if you have two spaces in a row and then press <TAB>, it will delete your previous input. I'm not sure how to fix this, but that situation doesn't occur very often, so I probably won't.

Code:

// ==UserScript==
// @name         Tab completion for Nexus Chat
// @namespace    nexus
// @version      1
// @description  enable tab completion for usernames in chat
// @include      https://chat.dmt-nexus.me
// @include      https://chat.dmt-nexus.me/chat.aspx
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var nickNames = [];
    var currentInput="";
    var tabIndex=0;
    var possibleCompletions=[]; //indices
    var lastKey=-1;
    var lastWord="";
    var tabKey=9;

    $("#InputBox").keydown(function(e) {
        if(e.which == tabKey) {
            var inputBox = document.getElementById("InputBox");
            e.preventDefault();
            if(lastKey != tabKey) { //first time user presses tab
                nickNames=$("#RoomUsers"+CurrentChatRoomId+ " .UserInfoName").map(function(){ return this.innerText; });
                currentInput = inputBox.value;
                lastWord = currentInput.split(" ").pop();
                possibleCompletions=[];
                for (var i=0; i < nickNames.length; i++) { //add the indices of usernames that start with the search string
                    if (nickNames[i].toLowerCase().search(lastWord.toLowerCase()) === 0) {
                        possibleCompletions.push(i);
                    }
                }
            }
            if (possibleCompletions.length !== 0) { //cycle through possibleCompletions
                inputBox.value = (lastWord.length>0 ? currentInput.slice(0,-lastWord.length) : currentInput) + nickNames[possibleCompletions[tabIndex]]+" ";
            }
            tabIndex++;
            if(tabIndex >= possibleCompletions.length) {
                tabIndex = 0;
            }
        } else {
            tabIndex=0;
        }
        lastKey=e.keyCode;
    });
})();

Love
 
slewb
#3 Posted : 4/4/2017 5:53:31 AM

DMT-Nexus member


Posts: 384
Joined: 29-Jul-2011
Last visit: 10-Jan-2022
Cool, safrol! I didn't know this could be done.

I've never used javascript so I can't be sure, but the problem with typing two spaces and then hitting tab may be because you are splitting your strings by a single space. So if you type
Code:
"Hi I'm slewb  "
(note two spaces after slewb), when you split by " " you will end up with the array ["Hi", "I'm", "slewb", ""]. So when you hit tab in this case, lastWord is "", whose length is zero. in the line
Code:
inputBox.value = currentInput.slice(0,-lastWord.length) + nickNames[possibleCompletions[tabIndex]]+" ";

you will be calling currentInput.slice(0, -0) which according to this (I think) returns an empty string, which is why the previously typed text is deleted.

So instead of splitting by a single space, maybe try using a regular expression to split by one or more spaces - see here. It looks like all you would need to do is replace the arguments when you call split to " +".

lol I hope I'm not 100 percent wrong on this, but try it out.

edit: actually I think that is still gonna mess things up since it will cut out some of the characters in currentInput. Maybe just keep it as it is and check if lastWord.length > 0 and act accordingly?
 
safrol
#4 Posted : 4/4/2017 9:13:10 PM

DMT-Nexus member


Posts: 19
Joined: 03-Oct-2015
Last visit: 08-Aug-2021
slewb wrote:
Maybe just keep it as it is and check if lastWord.length > 0 and act accordingly?

Perfect. Thanks a lot slewb, I didn't think of that! Sometimes it's the easiest solution that works best(at least it looks like it right now, heh). Also thanks for explaining the problem. The code is now updated.
 
 
Users browsing this forum
Guest

DMT-Nexus theme created by The Traveler
This page was generated in 0.016 seconds.