s4

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 diff
     1.1 --- a/s4-main.js	Fri Aug 16 17:33:38 2019 +0900
     1.2 +++ b/s4-main.js	Fri Aug 16 18:33:29 2019 +0900
     1.3 @@ -26,6 +26,9 @@
     1.4  	    else
     1.5  		lines = [""];
     1.6  	    var re = new RegExp("[, ]*#"+articleId+"(?![0-9])");
     1.7 +	    checked = (p.nodeName.match(/^input$/)
     1.8 +		       ? p.checked		// checkbox obeys its status
     1.9 +		       : !lines[0].match(re))	// a-elment toggles redirection
    1.10  	    if (checked) {
    1.11  		if (!lines[0].match(re)) {
    1.12  		    var re2 = new RegExp(/>#[#0-9, ]+[0-9]/);
    1.13 @@ -51,12 +54,16 @@
    1.14  	    textarea.value = lines.join("\n");
    1.15  	}
    1.16      }
    1.17 -    function init(){
    1.18 +    function init() {
    1.19  	var el, check = collectElementsByNameAttr("input", "notifyto");
    1.20  	if (check)
    1.21 -	    for (var i of check) {
    1.22 +	    for (let i of check) {
    1.23  		i.addEventListener("click", insertRedirect, null);
    1.24  	    }
    1.25 +	for (let i of document.getElementsByTagName("a"))
    1.26 +	    if (i.getAttribute("href").match(/^#[0-9]+$/))
    1.27 +		if (RegExp.lastMatch == i.innerHTML)
    1.28 +		    i.addEventListener("click", insertRedirect, null)
    1.29      }
    1.30      document.addEventListener('DOMContentLoaded', init, null);
    1.31  })();