Tildes User Script: Drag and drop usernames in order to mention them in your comments

unknown user
Wed, 31 Jul 2019 12:00:04 +0000

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

Comments URL: https://tildes.net/~tildes/g46/tildes_user_script_drag_and_drop_usernames_in_order_to_mention_them_in_your_comments

Votes: 9

Comments: 6