s4

changeset 972:8781f341d93a

Add referring text to hover title of ">#xxxx" marks.
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 28 May 2022 22:34:21 +0900
parents 0ac251f04f21
children 072362c47306
files s4-main.js
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/s4-main.js	Sun May 22 12:19:15 2022 +0900
     1.2 +++ b/s4-main.js	Sat May 28 22:34:21 2022 +0900
     1.3 @@ -1,6 +1,7 @@
     1.4  // 愛
     1.5  (function (){
     1.6      var isOlderJS;	// Set in init();
     1.7 +    var hoverTextLines = 10;
     1.8      var hasTouchPad =
     1.9  	(navigator.maxTouchPoints && navigator.maxTouchPoints >0);
    1.10      var myurl = document.URL,
    1.11 @@ -1032,6 +1033,30 @@
    1.12  	});
    1.13  	ta.parentNode.appendChild(btn);
    1.14      }
    1.15 +    function initReplyHover() {
    1.16 +	function getTextId(id) {
    1.17 +	    console.log("Getting!::"+id);
    1.18 +	    let txt = document.getElementById(id).innerText;
    1.19 +	    return txt.split("\n").splice(0,hoverTextLines).join("\n");
    1.20 +	}
    1.21 +	for (let td of document.querySelectorAll("td.repl")) {
    1.22 +	    let text = td.innerHTML;
    1.23 +	    console.log(text);
    1.24 +	    if (text.startsWith("\&gt;#")) {
    1.25 +		let newline = text.indexOf("\n");
    1.26 +		let first   = text.substring(0, newline),
    1.27 +		    rest    = text.substring(newline);
    1.28 +		td.innerHTML = first.replace(
    1.29 +		    /#([0-9]+)/g,
    1.30 +		    (match, start, whole) => {
    1.31 +			let id = RegExp.$1
    1.32 +			return '<span title="' + getTextId(id) + '">'
    1.33 +			    + match + '</span>';
    1.34 +		    }
    1.35 +		) + rest;
    1.36 +	    }
    1.37 +	}
    1.38 +    }
    1.39      function init() {
    1.40  	isOlderJS = !("insertAdjacentElement" in document.body);
    1.41  	initGrpAction();
    1.42 @@ -1040,6 +1065,7 @@
    1.43  	initTextarea();
    1.44  	initGrphome();
    1.45  	initMath();
    1.46 +	initReplyHover();
    1.47      }
    1.48      document.addEventListener('DOMContentLoaded', init, null);
    1.49  })();