Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
akoya-tomo committed Jul 2, 2019
2 parents e584d71 + 5aaf440 commit 1e550e4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 63 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ himuro\_majika氏作のユーザースタイルシートも使ってみてくだ
[futaba\_catalog\_mod(クラシックバージョン)](https://userstyles.org/styles/114130/futaba-catalog-mod-classic)

## 更新履歴
* v1.6.6rev24 2019-07-02
- リロードの監視を修正
- 既読スレのマークの監視を修正
* v1.6.6rev23 2019-05-20
- KOSHIAN リロード拡張 改のページ更新せずに「多順」「勢順」などに切り替えする機能に対応
* v1.6.6rev22 2019-05-15
Expand Down
174 changes: 111 additions & 63 deletions futaba_thread_highlighter.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @description スレ本文を検索してカタログでスレッド監視しちゃう
// @include http://*.2chan.net/*/futaba.php?mode=cat*
// @include https://*.2chan.net/*/futaba.php?mode=cat*
// @version 1.6.6rev23
// @version 1.6.6rev24
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @grant GM_registerMenuCommand
// @grant GM_getValue
Expand Down Expand Up @@ -143,7 +143,7 @@ this.$ = this.jQuery = jQuery.noConflict(true);
if ($("#GM_fcn_ng_menubar").length) {
$pickup_thread_area = $("#GM_fcn_ng_menubar");
} else {
$("body > table[border]").before($pickup_thread_area);
$("#cattable").before($pickup_thread_area);
}

var $container_header = $("<span>", {
Expand Down Expand Up @@ -182,7 +182,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
"background-color": "",
}
});
if ($("body").attr("__fcn_catalog_visibility") == "hidden") $pickup_thread_container.css("visibility", "hidden");
if ($("body").attr("__fcn_catalog_visibility") == "hidden") {
$pickup_thread_container.css("visibility", "hidden");
}
$pickup_thread_area.after($pickup_thread_container);
}

Expand Down Expand Up @@ -345,7 +347,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
* ふたば@アプリ としあき(仮) 出張版のキーワード検索バーの表示制御
*/
function futakuroSearchBarDispCtrl() {
if (!$("#inputSearch").length) return;
if (!$("#inputSearch").length) {
return;
}
$("#inputSearch,#inputSearch+div").wrapAll("<div class='fth_futakuro_searchbar'>");
var $futakuro_searchbar_button_header = $("<span>", {
id: "GM_fth_futakuro_searchbar_button_header",
Expand Down Expand Up @@ -397,47 +401,54 @@ this.$ = this.jQuery = jQuery.noConflict(true);
if ($("#cat_search").length) {
// ふたクロ
highlight();
target = $("html > body > table[border]").get(0);
target = $("#cattable").get(0);
config = { attributes: true , attributeFilter: ["style"] };
}
var observer = new MutationObserver(function(mutations) {
var isFutakuro = $("#cat_search").length > 0;
var isAkahuku = $("#akahuku_catalog_reload_status").length > 0;
mutations.forEach(function(mutation) {
var nodes = $(mutation.addedNodes);
if ($("#cat_search").length) {
if (isFutakuro) {
// ふたクロ
if (mutation.target.attributes.style.nodeValue == "opacity: 0;") {
opacityZero = true;
} else if (opacityZero) {
} else if (opacityZero && mutation.target.attributes.style.nodeValue != "opacity: 0;") {
opacityZero = false;
highlight();
pickup_opened_threads();
check_opened_threads_mark();
notifyPickup();
setTitle();
}
}
else if (nodes.attr("border") == "1" && $("#akahuku_catalog_reload_status").length) {
} else if (isAkahuku) {
// 赤福
if ($("body").attr("__fcn_catalog_visibility") == "hidden") $("#GM_fth_highlighted_threads").css("visibility", "hidden");
var timer = setInterval(function() {
var status = $("#akahuku_catalog_reload_status").text();
if(status === "" || status == "完了しました") {
clearInterval(timer);
highlight();
mark_akahuku_visited();
pickup_opened_threads();
check_opened_threads_mark();
notifyPickup();
var nodes = $(mutation.addedNodes);
if (nodes.attr("border") == "1") {
if ($("body").attr("__fcn_catalog_visibility") == "hidden") {
$("#GM_fth_highlighted_threads").css("visibility", "hidden");
}
}, 10);
var timer = setInterval(function() {
var status = $("#akahuku_catalog_reload_status").text();
if(status === "" || status == "完了しました") {
clearInterval(timer);
highlight();
mark_akahuku_visited();
pickup_opened_threads();
check_opened_threads_mark();
notifyPickup();
}
}, 10);
}
}
});
});
observer.observe(target, config);

// KOSHIAN
document.addEventListener("KOSHIAN_cat_reload", () => {
if ($("body").attr("__fcn_catalog_visibility") == "hidden") $("#GM_fth_highlighted_threads").css("visibility", "hidden");
$(document).on("KOSHIAN_cat_reload", () => {
if ($("body").attr("__fcn_catalog_visibility") == "hidden") {
$("#GM_fth_highlighted_threads").css("visibility", "hidden");
}
highlight();
pickup_opened_threads();
check_opened_threads_mark();
Expand All @@ -450,37 +461,40 @@ this.$ = this.jQuery = jQuery.noConflict(true);
* 既読スレのマークの状態を取得
*/
function check_opened_threads_mark() {
if (!USE_PICKUP_OPENED_THREAD) return;
if (!USE_PICKUP_OPENED_THREAD) {
return;
}

var target = $("html > body table[border] td");
var target = $("#cattable td");
var config = { attributes: true , attributeFilter: ["style"] };
// オブザーバインスタンスが既にあれば事前に解除
if (openedThreadObserver) openedThreadObserver.disconnect();

openedThreadObserver = new MutationObserver(function(mutations) {
mutations.forEach(function() {
//console.log("futaba_thread_highlighter : target mutated");
if (timerMutated) {
clearTimeout(timerMutated);
timerMutated = null;
}
timerMutated = setTimeout(function() {
highlight();
mark_akahuku_visited();
pickup_opened_threads();
notifyPickup();
}, 200);
});
if (openedThreadObserver) {
openedThreadObserver.disconnect();
}

openedThreadObserver = new MutationObserver(function() {
//console.log("futaba_thread_highlighter : target mutated");
if (timerMutated) {
clearTimeout(timerMutated);
timerMutated = null;
}
timerMutated = setTimeout(function() {
timerMutated = null;
highlight();
mark_akahuku_visited();
pickup_opened_threads();
notifyPickup();
}, 200);
});
for (var i = 0; i < target.length; i++) {
for (var i = 0; i < target.length; ++i) {
openedThreadObserver.observe(target[i], config);
}

if ($(".akahuku_markup_catalog_table").length) {
// 赤福の既読マーク
target = $("html > body table[border] td a[style]");
config = { attributes: true , attributeFilter: ["class"] };
for (var j = 0; j < target.length; j++) {
target = $("#cattable td a[style]");
config = { attributes: true, attributeFilter: ["class"] };
for (var j = 0; j < target.length; ++j) {
openedThreadObserver.observe(target[j], config);
}
}
Expand Down Expand Up @@ -514,11 +528,11 @@ this.$ = this.jQuery = jQuery.noConflict(true);
}
if( words !== "" ) {
removeOldHighlighted();
$("body > table[border] td small").each(function(){
$("#cattable td small").each(function() {
if( $(this).text().match(re) &&
( ($(this).parent("td").attr("class") + "").indexOf("GM_fcn_ng_") == -1 ) && // 「futaba catalog NG」NGスレ
( ($(this).parent("td").attr("style") + "").indexOf("display: none") == -1 ) && // NGスレ
( ($(this).attr("style") + "").indexOf("display: none") == -1 )) { // 「合間合間に」NGスレ
($(this).parent("td").attr("class") + "").indexOf("GM_fcn_ng_") == -1 && // 「futaba catalog NG」NGスレ
($(this).parent("td").attr("style") + "").indexOf("display: none") == -1 && // NGスレ
($(this).attr("style") + "").indexOf("display: none") == -1 ) { // 「合間合間に」NGスレ
if ( !$(this).children(".GM_fth_matchedword").length ) {
$(this).html($(this).html().replace(re,
"<span class='GM_fth_matchedword'>" +
Expand Down Expand Up @@ -556,7 +570,7 @@ this.$ = this.jQuery = jQuery.noConflict(true);
if ( $("#GM_fth_highlighted_threads .GM_fth_pickuped").length ) {
$("#GM_fth_highlighted_threads .GM_fth_pickuped").remove();
}
var highlighted = $("body > table .GM_fth_highlighted:not([class *= 'GM_fcn_ng_'])");
var highlighted = $("#cattable .GM_fth_highlighted:not([class *= 'GM_fcn_ng_'])");
// 要素の中身を整形
highlighted.each(function(){
var $clone = $(this).clone();
Expand All @@ -573,6 +587,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
// 「合間合間に」のボタンを削除
$clone.children("small.aima_aimani_generated").replaceWith();

// 「KOSHIAN 画像をポップアップで表示 改」のポップアップを削除
$clone.children(".KOSHIAN_image_popup_container").replaceWith();

// aタグがクリックされたらカタログのaタグをクリックする
$clone.children("a").click((e) => {
var origin_anchor = $(this).children("a:first").get(0);
Expand All @@ -584,13 +601,24 @@ this.$ = this.jQuery = jQuery.noConflict(true);

var attr = "";
// KOSHIANカタログマーカー改v2のマークを反映
if ($clone.attr("opened") == "true") attr = " opened='true'";
if ($clone.attr("old") == "true") attr += " old='true'";
if ($clone.attr("opened") == "true") {
attr = " opened='true'";
}
if ($clone.attr("old") == "true") {
attr += " old='true'";
}
if ($clone.attr("new") == "true") {
attr += " new='true'";
}
// 赤福Extendedのマークを反映
var age = $clone.attr("__age");
if (typeof age !== "undefined" && age !== false ) attr += ` __age=${age}`;
if (typeof age !== "undefined" && age !== false ) {
attr += ` __age=${age}`;
}
var preserved = $clone.attr("__preserved");
if (typeof preserved !== "undefined" && preserved !== false ) attr += ` __preserved=${preserved}`;
if (typeof preserved !== "undefined" && preserved !== false ) {
attr += ` __preserved=${preserved}`;
}

$clone.wrap("<div class='GM_fth_pickuped'" + attr + ">");
$clone.children().unwrap();
Expand All @@ -610,7 +638,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
* 赤福既読スレをマーク
*/
function mark_akahuku_visited() {
if (!MARK_AKAHUKU_VISITED) return;
if (!MARK_AKAHUKU_VISITED) {
return;
}
$("td:has('a.akahuku_visited')").css("background-color", AKAHUKU_VISITED_COLOR);
$("td:has('a:visited')").css("background-color", AKAHUKU_VISITED_COLOR);
}
Expand All @@ -619,7 +649,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
* 既読スレを先頭にピックアップ
*/
function pickup_opened_threads() {
if (!USE_PICKUP_OPENED_THREAD) return;
if (!USE_PICKUP_OPENED_THREAD) {
return;
}

var Start = new Date().getTime(); // count parsing time
// ピックアップに既読スレがあればクリア
Expand All @@ -635,10 +667,10 @@ this.$ = this.jQuery = jQuery.noConflict(true);
"[class *= 'GM_fcn_ng_']"; // futaba catalog NG
if ($(".akahuku_markup_catalog_table").length) {
// 赤福の既読スレ
opened = $("body > table td:has('a.akahuku_visited'):not(" + filter + ")");
opened = $("#cattable td:has('a.akahuku_visited'):not(" + filter + ")");
} else {
// 既読スレ
opened = $("body > table td[style]:not(" + filter +")");
opened = $("#cattable td[style]:not(" + filter +")");
}
// OPENED_THREAD_MARKER_STYLEが未設定でKOSHIANカタログマーカー改v2以外のマークならスタイルをコピー
if (opened.length && !openedThreadCssText && !opened.first().attr("opened")) {
Expand Down Expand Up @@ -669,6 +701,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
// 「合間合間に」のボタンを削除
$clone.children("small.aima_aimani_generated").replaceWith();

// 「KOSHIAN 画像をポップアップで表示 改」のポップアップを削除
$clone.children(".KOSHIAN_image_popup_container").replaceWith();

// aタグがクリックされたらカタログのaタグをクリックする
$clone.children("a").click((e) => {
var origin_anchor = $(this).children("a:first").get(0);
Expand All @@ -680,13 +715,24 @@ this.$ = this.jQuery = jQuery.noConflict(true);

var attr = "";
// KOSHIANカタログマーカー改v2のマークを反映
if ($clone.attr("opened") == "true") attr = " opened='true'";
if ($clone.attr("old") == "true") attr += " old='true'";
if ($clone.attr("opened") == "true") {
attr = " opened='true'";
}
if ($clone.attr("old") == "true") {
attr += " old='true'";
}
if ($clone.attr("new") == "true") {
attr += " new='true'";
}
// 赤福Extendedのマークを反映
var age = $clone.attr("__age");
if (typeof age !== "undefined" && age !== false ) attr += ` __age=${age}`;
if (typeof age !== "undefined" && age !== false ) {
attr += ` __age=${age}`;
}
var preserved = $clone.attr("__preserved");
if (typeof preserved !== "undefined" && preserved !== false ) attr += ` __preserved=${preserved}`;
if (typeof preserved !== "undefined" && preserved !== false ) {
attr += ` __preserved=${preserved}`;
}

$clone.wrap("<div class='GM_fth_opened'" + attr + ">");
$clone.children().unwrap();
Expand All @@ -708,7 +754,9 @@ this.$ = this.jQuery = jQuery.noConflict(true);
*/
function notifyPickup() {
document.dispatchEvent(new CustomEvent("FutabaTH_pickup"));
if ($("body").attr("__fcn_catalog_visibility") == "visible") $("#GM_fth_highlighted_threads").css("visibility", "visible");
if ($("body").attr("__fcn_catalog_visibility") == "visible") {
$("#GM_fth_highlighted_threads").css("visibility", "visible");
}
//console.log('futaba_thread_highlighter: Notyfy pickup completed');
}

Expand Down

0 comments on commit 1e550e4

Please sign in to comment.