Last active
March 9, 2017 10:36
-
-
Save naniwaKun/e371e25c2c2ec7274e028146050e0528 to your computer and use it in GitHub Desktop.
GoogleChromeを使って1分でツイキャスのコメントを読み上げるTips。 ref: http://qiita.com/naniwaKun/items/0b5f7028964acf618f96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user_id = "自分のユーザーID"; | |
function yomiyomi(text){ | |
var synthes = new SpeechSynthesisUtterance(); | |
synthes.voiceURI = 'native'; | |
synthes.volume = 0.3; | |
synthes.rate = 1.3; | |
synthes.pitch = 1; | |
synthes.text = text; | |
synthes.lang = 'ja-JP'; | |
synthes.onend = function(e) { | |
}; | |
speechSynthesis.speak(synthes); | |
} | |
function json_str_decode(str){ | |
arrs=str.match(/\\u.{4}/g); | |
var t=""; | |
for(i=0;i<arrs.length;i++){ | |
t+=String.fromCharCode(arrs[i].replace("\\u","0x")); | |
} | |
return(t); | |
} | |
function update_comment(data, fade){ | |
var shown = 0; | |
for (var i in data){ | |
var val = data[i]; | |
var commentid = val["id"]; | |
var commentidstr = "" + commentid; | |
var show = val["show"]; | |
// find comment id; | |
if (commentid && commentidstr.indexOf(".") < 0 && $("tr[commentid=" + commentid + "]").length > 0){ | |
continue; | |
} | |
// skip if no show | |
var elm = $("<tr></tr>"); | |
if (!show){ | |
elm.css("display", "none"); | |
} | |
if (show){ | |
shown++; | |
// add date | |
var d = new Date(Date.parse(val["date"])); | |
var datestr = ""; | |
if (val["dur"]){ | |
datestr = val["dur"] + " | "; | |
} | |
try { | |
datestr += d.toLocaleDateString() + " " + d.toLocaleTimeString(); | |
} catch (e) { | |
datestr += d.toString(); | |
} | |
var elmblock = $("<div></div>"); | |
var elmdatespan = $("<span></span>"); | |
elmdatespan.text(datestr + " "); | |
elmdatespan.addClass("smalldate"); | |
elmblock.append(elmdatespan); | |
if (commentid && commentidstr.indexOf(".") < 0){ | |
if (val["uid"] == user_id || true){ | |
var elmclickspan = $("<span></span>"); | |
var elmclicka = $("<a></a>"); | |
elmclicka.addClass("smalldate block"); | |
elmclicka.attr("href", "#"); | |
elmclicka.attr("commentid", commentid); | |
elmclicka.click(function(){ | |
remove_comment($(this).attr('commentid')); | |
return false; | |
}); | |
elmclicka.text('削除'); | |
elmblock.append(elmclicka); | |
} | |
} | |
if (val["uid"] != user_id && true){ | |
var elmclickspan = $("<span></span>"); | |
var elmclicka = $("<a></a>"); | |
elmclicka.addClass("smalldate block"); | |
elmclicka.attr("href", "#"); | |
elmclicka.attr("uid", val["uid"]); | |
elmclicka.click(function(){ | |
toggle_reply($(this).attr('uid')); | |
return false; | |
}); | |
elmclicka.text('@リプライ'); | |
elmblock.append(elmclicka); | |
} | |
var str = val["html"].replace( /<td\ class\=\"img\".*name\">/g , "" ); | |
var str = str.replace( /<span\ class\=\"smallsubtitle.*$/g , "" ); | |
var str = str.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,''); | |
var utf8str = unescape(encodeURIComponent(str)); | |
var utf16str = decodeURIComponent(escape(utf8str)); | |
yomiyomi(utf16str); | |
if (false && val["uid"] != user_id && val["uid"].indexOf(":") == -1 && | |
val["statusid"] && true && true){ | |
var elmclickspan = $("<span></span>"); | |
var elmclicka = $("<a></a>"); | |
elmclicka.addClass("smalldate block"); | |
elmclicka.attr("href", "#"); | |
elmclicka.attr("statusid", val["statusid"]); | |
elmclicka.click(function(){ | |
retweet_comment($(this).attr('statusid')); | |
return false; | |
}); | |
elmclicka.text('リツイート'); | |
elmblock.append(elmclicka); | |
} | |
if (commentid && commentidstr.indexOf(".") < 0 && val["uid"] != user_id && true){ | |
var elmclickspan = $("<span></span>"); | |
var elmclicka = $("<a></a>"); | |
elmclicka.addClass("smalldate block"); | |
elmclicka.attr("href", "#"); | |
elmclicka.attr("commentid", val["id"]); | |
elmclicka.click(function(){ | |
report_comment($(this).attr('commentid')); | |
return false; | |
}); | |
elmclicka.text('スパム報告'); | |
elmblock.append(elmclicka); | |
} | |
if (val["uid"] != user_id && true){ | |
var elmclickspan = $("<span></span>"); | |
var elmclicka = $("<a></a>"); | |
elmclicka.addClass("smalldate block"); | |
elmclicka.attr("href", "/" + user_id + "/accountblock/?user=" + val["uid"]); | |
elmclicka.text('ブロック'); | |
// block in another page | |
elmclicka.attr("target", "_blank"); | |
elmblock.append(elmclicka); | |
} | |
elm.addClass(val["class"]); | |
elm.html(val["html"]); | |
// update typing status | |
if (val["uid"].toLowerCase() == typing_current_user){ | |
clear_typing_user(); | |
}else if (val["screen"] && val["screen"].toLowerCase() == typing_current_user){ | |
clear_typing_user(); | |
} | |
// | |
if (val["yomi"] && typeof clipboardData != "undefined" && typeof clipboardData.setData == "function"){ | |
clipboardData.setData("text", val["yomi"]); | |
} | |
} | |
if (commentid){ | |
elm.attr("commentid", commentid); | |
} | |
if (fade && show){ | |
elm.css("display", "none"); | |
elm.fadeIn(700); | |
} | |
// find insert point | |
var currenttr = $("#comment tr:first"); | |
while(currenttr.length){ | |
if (!commentid || currenttr.attr("commentid") < commentid){ | |
// insert before this element | |
currenttr.before(elm); | |
break; | |
} | |
currenttr = currenttr.next(); | |
} | |
if (currenttr.length == 0){ | |
$("#comment").append(elm); | |
} | |
// add date | |
elm.find("td.comment").append(elmblock); | |
if (commentid > lastcommentid) lastcommentid = commentid; | |
if (fade && fade != 2){ | |
update_comment_num(1); | |
} | |
} | |
update_charleft(); | |
// trim | |
trim_shown_comments(); | |
return shown; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment