// ==UserScript== // @name QuoteCommentator // @namespace http://zymopinion.xyz/ // @version 0.1 // @description Wordpress Comments Quoting // @match https://www.kiwiblog.co.nz/* // @author Fentex // @grant none // ==/UserScript== (function() { 'use strict'; let quotedText = ''; let quotedElement = null; var css = document.createTextNode(` .quote { position: fixed; z-index: 10000; background:#fff; top:36px; right:4px; width:3em; height:3em; border: 4px solid #090; border-radius:50%; line-height: 1; text-align:center; cursor: pointer; } .quote span { display: block; position: relative; top:3px; color:#090; font-weight:bold; font-size:200%; } `); var style = document.createElement("style"); style.appendChild(css); var head = document.querySelector("head"); head.appendChild(style); var div = document.createElement("div"); div.classList.add("quote"); var span = document.createElement("span"); span.appendChild(document.createTextNode(`Q`)); div.appendChild(span); document.querySelector("body").appendChild(div); div.addEventListener("click", function() { if (quotedText !== "") { let insert = ''; if (quotedElement) { let a = quotedElement.querySelector("header.comment-author > h3") || quotedElement.querySelector("header.comment-author > h3 > a"); if (a) { insert = insert + `${a.textContent}; ${quotedText.trim()}`; } } else { insert = insert + quotedText.trim(); } inputElement.value += "
" + insert + "\n\n"; inputElement.focus(); } }); var inputElement = document.querySelector("textarea#comment"); if (inputElement != null) { document.querySelectorAll("p").forEach ( (e)=> { e.onpointerup = () => { let selection = document.getSelection(); quotedText = selection.toString(); let e = selection.anchorNode; while (!e.closest) e = e.parentNode; quotedElement = e.closest("article.jumplink"); } } ); } })();