// ==UserScript== // @name Twintail Quote Key // @version v4 // @description Select Text, Ctrl + Q for clipboard or Ctrl + V for quick reply // @author PekoPeko, modified by kaitou // @match https://twintail.cafe/showthread.php?tid=* // @icon https://twintail.cafe/favicon-dark.ico // @grant none // ==/UserScript== (function() { 'use strict'; document.addEventListener('keydown', function(event) { // Ctrl + q -> clipboard if (event.ctrlKey && event.key === 'q') { let sel = window.getSelection().anchorNode; let pid = ""; if (sel.tagName != undefined) { pid = window.getSelection().anchorNode.closest("div.post_body").id.substring(4); // pid_xxxx -> xxxx } else { pid = window.getSelection().anchorNode.parentElement.closest("div.post_body").id.substring(4); // pid_xxxx -> xxxx } let user = document.getElementById(`post_${pid}`).querySelector("span > a > span").innerHTML; let text = `[quote="${user}" pid="${pid}"]${window.getSelection().toString()}[/quote]\n`; navigator.clipboard.writeText(text); } // Ctrl + v -> into quick reply if (window.getSelection().anchorOffset != window.getSelection().focusOffset && event.ctrlKey && event.key === 'v') { let sel = window.getSelection().anchorNode; let pid = ""; if (sel.tagName != undefined) { pid = window.getSelection().anchorNode.closest("div.post_body").id.substring(4); // pid_xxxx -> xxxx } else { pid = window.getSelection().anchorNode.parentElement.closest("div.post_body").id.substring(4); // pid_xxxx -> xxxx } let user = document.getElementById(`post_${pid}`).querySelector("span > a > span").innerHTML; let text = `[quote="${user}" pid="${pid}"]${window.getSelection().toString()}[/quote]\n`; let reply_box = document.getElementById("quick_reply_form").querySelector("div > textarea"); let curr_value = reply_box.value; let start = reply_box.selectionStart; let end = reply_box.selectionEnd; reply_box.value = curr_value.slice(0, start) + text + curr_value.slice(end); //reply_box.selectionStart = reply_box.selectionEnd = start + text.length; //reply_box.focus(); // ^pastes in clipboard content for some fucking reason as well ;-; reply_box.scrollIntoView(); } }); })();