changeset 590:f480fa97fba6

Redirection also inserted by #XXX anchors
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 16 Aug 2019 18:33:29 +0900
parents 9994bfb637e5
children 3bfd1ac6fbf3
files s4-main.js
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/s4-main.js	Fri Aug 16 17:33:38 2019 +0900
+++ b/s4-main.js	Fri Aug 16 18:33:29 2019 +0900
@@ -26,6 +26,9 @@
 	    else
 		lines = [""];
 	    var re = new RegExp("[, ]*#"+articleId+"(?![0-9])");
+	    checked = (p.nodeName.match(/^input$/)
+		       ? p.checked		// checkbox obeys its status
+		       : !lines[0].match(re))	// a-elment toggles redirection
 	    if (checked) {
 		if (!lines[0].match(re)) {
 		    var re2 = new RegExp(/>#[#0-9, ]+[0-9]/);
@@ -51,12 +54,16 @@
 	    textarea.value = lines.join("\n");
 	}
     }
-    function init(){
+    function init() {
 	var el, check = collectElementsByNameAttr("input", "notifyto");
 	if (check)
-	    for (var i of check) {
+	    for (let i of check) {
 		i.addEventListener("click", insertRedirect, null);
 	    }
+	for (let i of document.getElementsByTagName("a"))
+	    if (i.getAttribute("href").match(/^#[0-9]+$/))
+		if (RegExp.lastMatch == i.innerHTML)
+		    i.addEventListener("click", insertRedirect, null)
     }
     document.addEventListener('DOMContentLoaded', init, null);
 })();

yatex.org