// ==UserScript== // @name V2EX快捷查看回复 // @namespace http://tampermonkey.net/ // @version 0.1 // @description V2EX快捷查看回复对象 // @author You // @match https://v2ex.com/t/* // @match https://www.v2ex.com/t/* // @icon https://www.google.com/s2/favicons?domain=v2ex.com // @license GPL3.0 // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let style = document.querySelector('style').sheet, replyWidth = 542, svgIcon = `` style.insertRule(`.fixed-reply { transition: all 300ms; transform: translateY(-10px); pointer-events: none; opacity: 0; padding: 12px 20px; width: ${replyWidth}px; box-sizing: border-box; position: absolute; bottom: 30px; left: -14px; background: #ffffff; border-radius: 8px; box-shadow: 0 0 18px rgb(0 0 0 / 10%); border: solid 1px #d5d8da; user-select: auto; }`, 1) style.insertRule(`.show-reply { position: relative; display: inline-flex; align-items: center; justify-content: flex-start; }`, 1) style.insertRule(` .show-reply:hover>.fixed-reply{ transform: translateY(0); pointer-events: auto; opacity: 1; }`, 1) style.insertRule(`.show-reply:hover:before { content: ""; position: absolute; width: 100%; height: 10px; left: 0; bottom: 100%; }`, 1) let replyList = document.querySelectorAll(".reply_content") replyList.forEach((el, index) => { el.parentNode.parentNode.querySelector(".no").addEventListener("click", function(event) { event.preventDefault() event.stopPropagation() gotoReply(this.innerText) }) el.querySelectorAll(".reply_content a").forEach((el) => { let replyEl = getContent(el.innerText, index) if (replyEl) { el.className = "show-reply" el.appendChild(replyEl) el.appendChild(document.createRange().createContextualFragment(svgIcon)) } }) }) function getContent(userId, maxIndex) { let lastContent = null for (var i = 0; i < maxIndex; i++) { if (replyList[i].parentNode.querySelector("strong a").innerText === userId) { lastContent = replyList[i].parentNode.parentNode } } if (lastContent) { var tempNode = document.createElement("div") tempNode.className = "fixed-reply" tempNode.addEventListener("click", function(event) { event.preventDefault() }) tempNode.appendChild(lastContent.cloneNode(true)).querySelector("td:last-child").width = replyWidth - 48 - 10 tempNode.querySelector(".no").addEventListener("click", function(event) { event.preventDefault() event.stopPropagation() gotoReply(this.innerText) }) return tempNode } else { return false } } function gotoReply(index) { replyList.forEach((el) => { if (el.parentNode.querySelector(".no").innerText == index) { var replaceTop = el.parentNode.parentNode.parentNode.parentNode.parentNode.getBoundingClientRect().top, repId = el.parentNode.parentNode.parentNode.parentNode.parentNode.id window.scrollTo({ top: window.scrollY + replaceTop, behavior: "smooth" }) history.pushState(null, null, `${window.location.origin}${window.location.pathname}#${repId}`) } }) } })();