「新しい日本語を作る会」コメントシステムの改良

「新しい日本語を作る会」の コメントシステムを 改良します。

当前为 2024-03-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         「新しい日本語を作る会」コメントシステムの改良
// @namespace    http://lit.link/toracatman
// @version      2024-03-05
// @description  「新しい日本語を作る会」の コメントシステムを 改良します。
// @author       トラネコマン
// @match        http://www.tackns.net/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    //ミュート
    //ミュートしたい 言葉が 名前に 含まれるなら,「var n = [〰︎];」に 入力します。
    //ミュートしたい 言葉が 本文に 含まれるなら,「var c = [〰︎];」に 入力します。
    //ミュートしたい 言葉を,ダブルクォーテーション「"」で 囲んで,複数 ある 場合は コンマ「,」で 区切ります。
    //ミュートしたい 言葉に 完全一致するなら,「^$」で 囲んでから「"」で 囲みます。例: 「あいうえお」に 完全一致 → "^あいうえお$"

    //名前
    var n = [];

    //本文
    var c = [];

    var a;

    a = document.getElementsByClassName("cs_name");
    for (var i = 0; i < a.length; i++) {
        //名前
        var f = false;
        for (var j = 0; j < n.length; j++) {
            var r = new RegExp(n[j], "u");
            if (r.test(a[i].textContent)) {
                mute(a[i], 0);
                f = true;
                break;
            }
        }
        if (f) continue;

        //本文
        for (var j = 0; j < c.length; j++) {
            var r = new RegExp(c[j], "u");
            if (r.test(a[i].parentNode.lastElementChild.innerHTML)) {
                mute(a[i], 1);
                break;
            }
        }
    }

    //バックスラッシュ、特殊文字、リンク
    a = document.getElementsByClassName("cs_contents");
    for (var i = 0; i < a.length; i++) {
        a[i].innerHTML = convertSpecial(a[i].innerHTML);
    }
    if (location.href == "http://www.tackns.net/bin/comment_post.cgi") {
        a = document.querySelector("tr:nth-child(5) td:nth-child(2)");
        a.innerHTML = convertSpecial(a.innerHTML);
    }
})();

//特殊処理
function convertSpecial(s) {
	return s.replace(/\\\\/g, "\\").replace(/&amp;/g, "&").replace(/(https?|ftp)(:\/\/[\w\/:%#\$&\?\(\)~\.=\+\-]+)/g, '<a href="$1$2">$1$2</a>');
}

//表示ボタン
function displayButton(a) {
	var b = a.parentNode.children;
	for (var i = 0; i < b.length; i++) {
		b[i].removeAttribute("style");
	}
	a.value = "隠す";
	a.setAttribute("onclick", "hideButton(this)");
}

//隠すボタン
function hideButton(a) {
	var b = a.previousElementSibling.previousElementSibling;
	while (b != null) {
		if (b.className != "cs_no") b.style.display = "none";
		b = b.previousElementSibling;
	}
	 b = a.nextElementSibling;
	while (b != null) {
		if (b.className != "cs_no") b.style.display = "none";
		b = b.nextElementSibling;
	}
	a.value = "表示";
	a.setAttribute("onclick", "displayButton(this)");
}

//ミュート処理
function mute(a, e) {
	a.style.display = "none";
	var b = a.nextElementSibling;
	while (b != null) {
		if (b.className != "cs_no") b.style.display = "none";
		b = b.nextElementSibling;
	}
	var s;
	switch (e) {
	case 0:
		s = "《ミュートしている投稿者によるコメントです》";
		break;
	case 1:
		s = "《ミュートしている内容が含まれるコメントです》";
		break;
	}
	b = document.createElement("span");
	b.className = "cs_text";
	b.textContent = s;
	a.nextElementSibling.after(b);
	var c = document.createElement("input");
	c.type = "button";
	c.value = "表示";
	c.className = "cs_button";
	c.setAttribute("onclick", "displayButton(this)");
	b.after(c);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址