9
votes
Tildes User Script: Drag and drop usernames in order to mention them in your comments
It is was a tedious task to mention users: copy, type, paste. This script makes it a single step: drag and drop any username on to the comment you're composing, and tada! It's there.
Here is the script:
// ==UserScript==
// @name tildesDragNDropUsernameForMention
// @version 1
// @grant none
// @namespace tildes.net
// ==/UserScript==
var userLinks = document.querySelectorAll('a.link-user');
var dragstartHandler = function (event) {
var text = event.target.innerText;
if(!text.startsWith('@')){
text = "@" + text;
}
event.dataTransfer.setData("text", text);
event.dataTransfer.dropEffect = 'copy';
}
userLinks.forEach(function (each) {
each.setAttribute('draggable', true);
each.ondragstart = dragstartHandler;
});
Patches welcome!
Edit: remove useless code
Version 2 without useless definitions:
Thanks for sharing! I don't reference usernames often enough to use it personally, but I'm sure it'll be useful for some.
As an alternative approach: maybe some sort of suggestive-feature could pull names from the current thread, and volunteer them if you type
@
or/u/
? Though I don't know of any simple way to offer something like that.You're welcome! @Deimos uses really good class names, and again in this time, all instances of usernames are assigned
link-user
. So, apart from the UI, the implementation of such a feature would be as easy asdocument.querySelectorAll('a.link-user')
and display the results at where the cursor is in a filtering list. The UI would be straightforward but involved if you don't use a library (tho there is this that suggests it can be easier).I'm curious (and feeling a bit cheeky). You user-mentioned someone in your comment. Did you use your script to do that?
Nope :) The name needs to exist on the webpage somewhere so that you can drag and drop it on the comment text box. If the feature @Wes talked about was implemented, you could use it to auto complete Deimos or Algernon_Asimov. I was tempted to give it a try, but I already procrastinated enough, and that one is a bit too involved (and I'm no expert at browser stuff). Maybe someone with a better know-how can try their hand at writing it.
BTW when mentioning Wes here, I did use the script.
That's what I thought. :)
Cool.