", {
id: "GM_FAR_notificationButton",
text: "[通知]",
title: "新着レスのポップアップ通知",
css: {
cursor: "pointer",
},
click: function() {
toggleNotification();
}
});
if (isNotificationEnable) {
$notificationButton.css("background-color", "#a9d8ff");
}
var $input = $("input[value$='信する']");
$input.after($notificationButton);
$input.after($liveButton);
if(SHOW_NORMAL_BUTTON){
$input.after($normalButton);
}
//実況モードトグルショートカットキー
window.addEventListener("keydown",function(e) {
if ( e.altKey && e.keyCode == LIVE_TOGGLE_KEY ) {
liveMode();
}
}, false);
/*
* 通常モード切り替え
*/
function normalMode() {
if(normal_flag) {
clearNormalReload();
$normalButton.css("background" , "none");
normal_flag = false;
} else {
setNormalReload();
$normalButton.css("background-color" , "#ea8");
normal_flag = true;
}
}
/*
* 実況モード
* 呼出ごとにON/OFFトグル
*/
function liveMode() {
if (!live_flag) {
//実況モード時リロード
timerLiveReload = setInterval(rel_scroll, RELOAD_INTERVAL_LIVE);
//自動スクロール
timerLiveScroll = setInterval(live_scroll, LIVE_SCROLL_INTERVAL);
$liveButton.css("backgroundColor", "#ffa5f0");
startspin();
console.log(script_name + ": Start live mode @" + url);
live_flag = true;
} else {
clearInterval(timerLiveReload);
clearInterval(timerLiveScroll);
$liveButton.css("background", "none");
stopspin();
console.log(script_name + ": Stop live mode @" + url);
live_flag = false;
}
//新着スクロール
function rel_scroll() {
$('html, body').animate(
{scrollTop:window.scrollMaxY},"fast"
);
if(isAkahukuNotFound()){
//404時
liveMode();
}
else {
clickrelbutton();
}
}
function live_scroll() {
window.scrollBy( 0, LIVE_SCROLL_SPEED );
}
function startspin() {
$("#akahuku_throp_menu_opener").css(
"animation", "spin 2s infinite steps(8)"
);
}
function stopspin() {
$("#akahuku_throp_menu_opener").css(
"animation", "none"
);
}
}
/*
* 通知切り替え
*/
function toggleNotification() {
if(isNotificationEnable) {
$notificationButton.css("background" , "none");
isNotificationEnable = false;
} else {
Notification.requestPermission(function(result) {
if (result == "denied") {
$notificationButton.attr("title",
"通知はFirefoxの設定でブロックされています\n" +
"ロケーションバー(URL)の左のアイコンをクリックして\n" +
"「サイトからの通知の表示」を「許可」に設定してください");
return;
} else if (result == "default") {
console.log("default");
return;
}
$notificationButton.attr("title", "新着レスのポップアップ通知");
$notificationButton.css("background-color" , "#a9d8ff");
isNotificationEnable = true;
});
}
}
}
/*
* 新着レスをリセット
*/
function reset_title() {
//ページ末尾でホイールダウンした時
window.addEventListener("DOMMouseScroll",function scroll(event) {
var window_y = window.scrollY;
var window_ymax = window.scrollMaxY;
if (event.detail > 0 && window_y >= window_ymax) {
reset_titlename();
}
return;
} ,false);
//F5キー押された時
window.addEventListener("keydown",function(e) {
if ( e.keyCode == "116" ) {
reset_titlename();
}
}, false);
function reset_titlename() {
res = 0;
var title_char = title_name();
document.title = title_char;
}
}
function rel() {
soudane();
setTimeout(changetitle, 1000);
if(isAkahukuNotFound()){
//404時
clearNormalReload();
if (USE_SAVE_MHT) {
saveMHT();
}
console.log(script_name + ": Page not found, Stop auto reloading @" + url);
}
else {
clickrelbutton();
}
}
/**
* 赤福の続きを読むボタンをクリック
*/
function clickrelbutton() {
var relbutton = $("#akahuku_reload_button").get(0);
if(relbutton){
var e = document.createEvent("MouseEvents");
e.initEvent("click", false, true);
relbutton.dispatchEvent(e);
}
setTimeout(function(){
if (!isWindowActive && isNotificationEnable) {
getNewResContent();
}
}, 1000);
}
/**
* MHTで保存
*/
function saveMHT() {
var saveMHTButton = $("#akahuku_throp_savemht_button").get(0);
if (saveMHTButton) {
var e = document.createEvent("MouseEvents");
e.initEvent("click", false, true);
saveMHTButton.dispatchEvent(e);
}
}
/*
* そうだねの数に応じてレスを着色
*/
function soudane() {
if ( USE_SOUDANE ) {
$("td > .sod").each(function(){
var sodnum = $(this).text().match(/\d+/);
if (sodnum){
var col = "rgb(180, 240," + (Math.round(10 * sodnum + 180)) + ")";
$(this).parent().css("background-color", col);
}
});
}
}
/*
* タブタイトルに新着レス数・スレ消滅状態を表示
*/
function changetitle() {
if ( USE_TITLE_NAME ) {
var title_char = title_name();
var newres = $("#akahuku_new_reply_header_number").text();
if (isAkahukuNotFound()) {
document.title = "#" + title_char;
} else {
if(newres) {
res += parseInt(newres);
}
if ( res !== 0) {
document.title = "(" + res + ")" + title_char;
}
}
}
}
// 新着レスの内容を取得
function getNewResContent() {
var $newrestable = $("#akahuku_new_reply_header ~ table:not([id])");
if ($newrestable.length) {
var restexts = [];
$newrestable.each(function() {
var texts = [];
$(this).find("blockquote").contents().each(function() {
if ($(this).text() !== "") {
texts.push($(this).text());
}
});
restexts.push(texts.join("\r\n"));
});
var popupText = restexts.join("\r\n===============\r\n");
showNotification(popupText);
}
}
/*
* 赤福のステータスからスレ消滅状態をチェック
*/
function isAkahukuNotFound() {
var statustext = $("#akahuku_reload_status").text();
if (statustext.match(/(No Future)|((M|N)ot Found)/)) {
return true;
}
else {
return false;
}
}
function title_name() {
var title = document.title;
var title_num = title.match(/^(#|\(\d+\))/);
var title_num_length;
if(!title_num){
title_num_length = 0;
}
else {
title_num_length = title_num[0].length;
}
var act_title_name = title.substr(title_num_length);
return act_title_name;
}
function makeFormClearButton() {
if ( USE_CLEAR_BUTTON ) {
var $formClearButton = $("", {
id: "formClearButton",
text: "[クリア]",
css: {
cursor: "pointer",
margin: "0 5px"
},
click: function() {
clearForm();
}
});
var $comeTd = $(".ftdc b:contains('コメント')");
$comeTd.after($formClearButton);
}
function clearForm() {
$("#ftxa").val("");
}
}
function addCss() {
GM_addStyle(
"@keyframes spin {" +
" 0% { transform: rotate(0deg); }" +
" 100% { transform: rotate(359deg); }" +
"}"
);
}
// タブのアクティブ状態を取得
function setWindowFocusEvent() {
$(window).focus();
$(window).bind("focus", function() {
// タブアクティブ時
isWindowActive = true;
}).bind("blur", function() {
// タブ非アクティブ時
isWindowActive = false;
});
}
// 新着レスをポップアップでデスクトップ通知する
function showNotification(body) {
Notification.requestPermission();
var icon = $("#akahuku_thumbnail").attr("src");
var instance = new Notification(
document.title, {
body: body,
icon: icon,
}
);
}
})(jQuery);