Greasy Fork

dm5动漫屋 & dmzj动漫之家 键盘导览

[a / ←]前一页,[d / →]下一页,[w / ↑]新一章,[s / ↓]旧一章,[q]新一页留言,[e]旧一页留言,[r]载入全部留言_新到旧,[t]载入全部留言_旧到新,[esc]中断载入更多留言

目前为 2021-01-12 提交的版本。查看 最新版本

// ==UserScript==
// @name				dm5.com & dmzj.com - navigate with keyboard
// @name:zh-TW			dm5動漫屋 & dmzj動漫之家 鍵盤導覽
// @name:zh-CN			dm5动漫屋 & dmzj动漫之家 键盘导览
// @description			[a / ←]prev page,[d / →]next page,[w / ↑]next chapter,[s / ↓]prev chapter,[q]newer comments,[e]older comments
// @description:zh-TW	[a / ←]前一頁,[d / →]下一頁,[w / ↑]新一章,[s / ↓]舊一章,[q]新一頁留言,[e]舊一頁留言,[r]載入全部留言_新到舊,[t]載入全部留言_舊到新,[esc]中斷載入更多留言
// @description:zh-CN	[a / ←]前一页,[d / →]下一页,[w / ↑]新一章,[s / ↓]旧一章,[q]新一页留言,[e]旧一页留言,[r]载入全部留言_新到旧,[t]载入全部留言_旧到新,[esc]中断载入更多留言
// @author				Evan Tseng
// @version				1.0.3
// @namespace			https://greasyfork.org/zh-TW/users/393133-evan-tseng
// @match				*.dm5.com/*
// @match				*.dmzj.com/*
// @match				*.dmzj1.com/*
// @run-at				document-start
// @grant				none
// ==/UserScript==

(function() {
	'use strict';
	var host = window.location.hostname;
	if(host.indexOf("dm5.com") > -1) host="dm5";
	else if(host.indexOf("dmzj.com") > -1 || host.indexOf("dmzj1.com") > -1 ) host="dmzj";
	switch(host) {
		case "dm5":
			document.addEventListener("DOMContentLoaded", function(){
				setTimeout(function(){
					let adutBtn = document.querySelector("#checkAdult");
					if(adutBtn)	adutBtn.click();
				},150);
			});

			document.addEventListener("keydown", function(e) {
				if(document.querySelector("input:focus, textarea:focus") || (e.shiftKey | e.ctrlKey | e.altKey | e.metaKey | e.isComposing)) return;
				var PrevC, NextC, PrevP, NextP,
					ppa = document.querySelectorAll(".view-paging>.container>a");
				PrevC = NextC = PrevP = NextP = null;
				for(let i in ppa) {
					switch(ppa[i].innerText) {
						case "上一章":
							PrevC=ppa[i]; break;
						case "下一章":
							NextC=ppa[i]; break;
						case "上一页":
							PrevP=ppa[i]; break;
						case "下一页":
							NextP=ppa[i]; break;
					}
				}

				var actP=document.querySelector(".page-pagination ul li a.active");
				if(actP) actP=parseInt(actP.innerText);

				e = e || window.event;
				try{
					switch(e.key.toLowerCase()) {
						case 'arrowup':
						case 'w':
							if(NextC) NextC.click(); break;
						case 'arrowdown':
						case 's':
							if(PrevC) PrevC.click(); break;
						case 'arrowleft':
						case 'a':
							$('#last-mask, #last-win').hide();
							if(PrevP) ShowPre();
							else if(actP>1) YingdmList.self.changepager(actP-1);
							break;
						case 'arrowright':
						case 'd':
							$('#last-mask, #last-win').hide();
							if(NextP) ShowNext();
							else if(actP) YingdmList.self.changepager(actP+1);
							break;
						case 'escape':
							if(allComments) clearTimeout(allComments)
							$('#last-mask, #last-win').hide();
							break;
						case 'e':
							if(allComments) clearTimeout(allComments)
							$('#last-mask, #last-win').hide();
							var NextE=document.querySelector(".view-comment-main .top .page span.current").nextElementSibling;
							if(NextE) NextE.click();
							$(".view-comment-main .top .page, .view-comment-main .bottom-page").show();
							break;
						case 'q':
							if(allComments) clearTimeout(allComments)
							$('#last-mask, #last-win').hide();
							var PrevE=document.querySelector(".view-comment-main .top .page span.current").previousElementSibling;
							if(PrevE) PrevE.click();
							$(".view-comment-main .top .page, .view-comment-main .bottom-page").show();
							break;
						case 'r': // 載入全部留言
							if(allComments) clearTimeout(allComments)
							$('#last-mask, #last-win').hide();
							$(".postlist").html("");
							if (typeof (DM5_PAGETYPE) != "undefined") {
								if (DM5_PAGETYPE == 9) {
									getPost2(1, DM5_PAGEPCOUNT, DM5_TIEBATOPICID, DM5_PAGETYPE);
								}
								else if (DM5_PAGETYPE == 4) {
									getMangaPost2(1, DM5_PAGEPCOUNT, DM5_COMIC_MID, DM5_PAGETYPE);
								}
							}
							$(".view-comment-main .top .page, .view-comment-main .bottom-page").hide();
							break;
						case 't':
							if(allComments) clearTimeout(allComments)
							$('#last-mask, #last-win').hide();
							$(".postlist").html("");
							if (typeof (DM5_PAGETYPE) != "undefined") {
								if (DM5_PAGETYPE == 9) {
									getPost2(DM5_PAGEPCOUNT, DM5_PAGEPCOUNT, DM5_TIEBATOPICID, DM5_PAGETYPE, true);
								}
								else if (DM5_PAGETYPE == 4) {
									getMangaPost2(DM5_PAGEPCOUNT, DM5_PAGEPCOUNT, DM5_COMIC_MID, DM5_PAGETYPE, true);
								}
							}
							$(".view-comment-main .top .page, .view-comment-main .bottom-page").hide();
							break;
						case '/':
							alert("Pages of comments: " + DM5_PAGEPCOUNT);
					}
				} catch(err) { console.log(err); }
			});
			break;

		case "dmzj":
			document.addEventListener("keydown", function(e) {
				if(document.querySelector("input:focus, textarea:focus") || (e.shiftKey | e.ctrlKey | e.altKey | e.metaKey | e.isComposing)) return;
				var elm=null;
				e = e || window.event;
				try {
					switch(e.key.toLowerCase()) {
						case 'arrowup':
						case 'w':
							elm=document.querySelector("#next_chapter, a.btm_chapter_btn.fr"); break;
						case 'arrowdown':
						case 's':
							elm=document.querySelector("#prev_chapter, a.btm_chapter_btn.fl"); break;
						case 'arrowleft':
							elm=document.querySelector(".pages a.pselected, .page a.cu");
							if(elm)	do elm=elm.previousElementSibling; while(elm.nodeName == "#text");
							break;
						case 'arrowright':
							elm=document.querySelector(".pages a.pselected, .page a.cu");
							if(elm)	do elm=elm.nextElementSibling; while(elm.nodeName == "#text");
							break;
						case 'a':
							if(elm=document.querySelector("#center_box>a.img_land_prev, .comic_wraCon>a.img_land_prev")) break;
							else {
								elm=document.querySelector("#search_list_div .pages a.pselected, .page a.cu");
								if(elm)	do elm=elm.previousElementSibling; while(elm.nodeName == "#text");
							}
							break;
						case 'd':
							if(elm=document.querySelector("#center_box>a.img_land_next, .comic_wraCon>a.img_land_next")) break;
							else {
								elm=document.querySelector("#search_list_div .pages a.pselected, .page a.cu");
								if(elm)	do elm=elm.nextElementSibling; while(elm.nodeName == "#text");
							}
							break;
						case 'escape':
							elm=document.querySelector("#close_btn");
					}
					if(elm) elm.click();
				} catch(err) { console.log(err); }
			});
			break;
	}

	//	=============================================================================
	//	dm5 讀取留言・改
	var allComments=null;
	function getPost2(pageindex, pagesize, tid, type, rev=false) {
		var cid = 0;
		if (typeof (DM5_CID) != "undefined") {
			cid = DM5_CID;
		}
		$.ajax({
			url: 'pagerdata.ashx?d=' + new Date().getTime(),
			data: { pageindex: pageindex, pagesize: pagesize, tid: tid, cid: cid, t: type },
			error: function (msg) {
				//ShowDialog("服务器出现异常请重试");
			},
			success: function (json) {
				var objs = eval(json);
				var html = "";
				for (var i = 0; i < objs.length; i++) {
					var obj = rev ? objs[objs.length-1-i] : objs[i];
					html += "<li class=\"dashed\">";
					html += "<div class=\"cover\"><img src=\"";
					html += obj.HeadUrl;
					html += "\"/></div>";
					html += "<div class=\"info\">";
					html += "<p class=\"title\">";
					html += obj.Poster;
					if (obj.VipLevel > 0) {
						html += "<span class=\"vip\">VIP" + obj.VipLevel + "</span>";
						if (obj.VipType == 1) {
							html += "<span class=\"year\">年费</span>";
						}
					}
					html += "</p>";
					if (obj.ToPostShowDataItems) {
						var topostcount = obj.ToPostShowDataItems.length;
						for (var j = 0; j < obj.ToPostShowDataItems.length; j++) {
							var topost = obj.ToPostShowDataItems[j];
							if (j == 0) {
								html += '<ul class="child-list">'
							}
							if (topostcount >= 4) {
								if (j == 1) {
									html += '<li class="open"><a href="javascript:void(0);" class="openpostbtn" id="openpostbtn' + obj.ID + '" data="' + obj.ID + '">展开全部楼层</a></li>'
								}
								if (j == 0 || j == (topostcount - 1)) {
									html += '<li>';
								}
								else {
									html += '<li class="litopost' + obj.ID + '" style="display:none;">';
								}
							}
							else {
								html += '<li>';
							}
							html += '<div class="cover"><img src="' + topost.HeadUrl + '"></div><div class="info">';
							html += '<p class="title">' + topost.Poster;
							if (topost.VipLevel > 0) {
								html += "<span class=\"vip\">VIP" + topost.VipLevel + "</span>";
								if (topost.VipType == 1) {
									html += "<span class=\"year\">年费</span>";
								}
							}
							html += '</p><p class="content">' + topost.PostContent + '</p>';
							html += '<p class="bottom">' + topost.PostTime + '<span class="right">';
							html += "<a href=\"javascript:void(0)\" data=\"1\" pid=\"" + topost.Id + "\" ";
							html += " class=\"zan";
							if (topost.IsPraise) {
								html += " active";
							}
							html += " zanbtn\">";
							if (topost.PraiseCount > 0) {
								html += topost.PraiseCount;
							}
							else {
								html += "赞";
							}
							html += "</a>";
							html += "<a href=\"javascript:void(0)\"";
							html += " data=\""
							html += topost.Poster;
							html += " \" pid=\"";
							html += topost.Id;
							html += "\" class=\"";
							html += "comment recommentbtn";
							html += "\">";
							html += "评论";
							html += "</a></span></p>";
							if (j == (obj.ToPostShowDataItems.length - 1)) {
								html += '</ul>'
							}
						}
					}
					html += "<p class=\"content\">";
					html += obj.PostContent;
					html += "</p>";
					html += " <p class=\"bottom\">";
					html += obj.PostTime;
					html += "<span class=\"right\">";
					html += "<a href=\"javascript:void(0)\" data=\"1\" pid=\"" + obj.Id + "\" ";
					html += " class=\"zan";
					if (obj.IsPraise) {
						html += " active";
					}
					html += " zanbtn\">";
					if (obj.PraiseCount > 0) {
						html += obj.PraiseCount;
					}
					else {
						html += "赞";
					}
					html += "</a>"
					html += "<a href=\"javascript:void(0)\"";
					html += " data=\""
					html += obj.Poster;
					html += " \" pid=\"";
					html += obj.Id;
					html += "\" class=\"";
					html += "comment recommentbtn";
					html += "\">";
					html += "评论";
					html += "</a></span></p>";
					html += "</div></li>";
				}
				$(".postlist").html($(".postlist").html()+html);
				$(".postlist").find(".recommentbtn").click(function () {
					$('body').addClass('toolbar');
					reComment($(this).attr("pid"), $(this).attr("data"), $(this));
				});
				$(".postlist").find(".openpostbtn").click(function () {
					openpost($(this));
				});
				$(".postlist").find(".zanbtn").click(function () {
					praisepost($(this).attr("pid"), $(this));
				});
				if(rev) {
					if(pageindex>1)	allComments=setTimeout(function(){ getPost2(pageindex-1, pagesize, tid, type, rev); }, 600);
					else	allComments=null;
				}
				else {
					if(pageindex<pagesize)	allComments=setTimeout(function(){ getPost2(pageindex+1, pagesize, tid, type, rev); }, 600);
					else	allComments=null;
				}
			}
		});
	}

	function getMangaPost2(pageindex, pagesize, mid, type, rev=false) {
		$.ajax({
			url: 'pagerdata.ashx?d=' + new Date().getTime(),
			data: { pageindex: pageindex, pagesize: pagesize, mid: mid, t: type },
			error: function (msg) {
				//ShowDialog("服务器出现异常请重试");
			},
			success: function (json) {
				var objs = eval(json);
				var html = "";
				for (var i = 0; i < objs.length; i++) {
					var obj = rev ? objs[objs.length-1-i] : objs[i];
					html += "<li class=\"dashed\">";
					html += "<div class=\"cover\"><img src=\"";
					html += obj.HeadUrl;
					html += "\"/></div>";
					html += "<div class=\"info\">";
					html += "<p class=\"title\">";
					html += obj.Poster;
					if (obj.VipLevel > 0) {
						html += "<span class=\"vip\">VIP" + obj.VipLevel + "</span>";
						if (obj.VipType == 1) {
							html += "<span class=\"year\">年费</span>";
						}
					}
					html += "</p>";
					if (obj.ToPostShowDataItems) {
						var topostcount = obj.ToPostShowDataItems.length;
						for (var j = 0; j < obj.ToPostShowDataItems.length; j++) {
							var topost = obj.ToPostShowDataItems[j];
							if (j == 0) {
								html += '<ul class="child-list">'
							}
							if (topostcount >= 4) {
								if (j == 1) {
									html += '<li class="open"><a href="javascript:void(0);" class="openpostbtn" id="openpostbtn' + obj.ID + '" data="' + obj.ID + '">展开全部楼层</a></li>'
								}
								if (j == 0 || j == (topostcount - 1)) {
									html += '<li>';
								}
								else {
									html += '<li class="litopost' + obj.ID + '" style="display:none;">';
								}
							}
							else {
								html += '<li>';
							}
							html += '<div class="cover"><img src="' + topost.HeadUrl + '"></div><div class="info">';
							html += '<p class="title">' + topost.Poster;
							if (topost.VipLevel > 0) {
								html += "<span class=\"vip\">VIP" + topost.VipLevel + "</span>";
								if (topost.VipType == 1) {
									html += "<span class=\"year\">年费</span>";
								}
							}
							html += '</p><p class="content">' + topost.PostContent + '</p>';
							html += '<p class="bottom">' + topost.PostTime + '<span class="right">';
							html += "<a href=\"javascript:void(0)\" data=\"1\" pid=\"" + topost.Id + "\" ";
							html += " class=\"zan";
							if (topost.IsPraise) {
								html += " active";
							}
							html += " zanbtn\">";
							if (topost.PraiseCount > 0) {
								html += topost.PraiseCount;
							}
							else {
								html += "赞";
							}
							html += "</a>";
							html += "<a href=\"javascript:void(0)\"";
							html += " data=\""
							html += topost.Poster;
							html += " \" pid=\"";
							html += topost.Id;
							html += "\" class=\"";
							html += "comment recommentbtn";
							html += "\">";
							html += "评论";
							html += "</a></span></p>";
							if (j == (obj.ToPostShowDataItems.length - 1)) {
								html += '</ul>'
							}
						}
					}
					html += "<p class=\"content\">";
					html += obj.PostContent;
					html += "</p>";
					html += " <p class=\"bottom\">";
					html += obj.PostTime;
					html += "<span class=\"right\">";
					html += "<a href=\"javascript:void(0)\" data=\"1\" pid=\"" + obj.Id + "\" ";
					html += " class=\"zan";
					if (obj.IsPraise) {
						html += " active";
					}
					html += " zanbtn\">";
					if (obj.PraiseCount > 0) {
						html += obj.PraiseCount;
					}
					else {
						html += "赞";
					}
					html += "</a>"
					html += "<a href=\"javascript:void(0)\"";
					html += " data=\""
					html += obj.Poster;
					html += " \" pid=\"";
					html += obj.Id;
					html += "\" class=\"";
					html += "comment recommentbtn";
					html += "\">";
					html += "评论";
					html += "</a></span></p>";
					html += "</div></li>";
				}
				$(".postlist").html($(".postlist").html()+html);
				$(".postlist").find(".recommentbtn").click(function () {
					$('body').addClass('toolbar');
					reComment($(this).attr("pid"), $(this).attr("data"), $(this));
				});
				$(".postlist").find(".openpostbtn").click(function () {
					openpost($(this));
				});
				$(".postlist").find(".zanbtn").click(function () {
					praisepost($(this).attr("pid"), $(this));
				});
				if(rev) {
					if(pageindex>1)	allComments=setTimeout(function(){ getMangaPost2(pageindex-1, pagesize, mid, type, rev); }, 600);
					else	allComments=null;
				}
				else {
					if(pageindex<pagesize)	allComments=setTimeout(function(){ getMangaPost2(pageindex+1, pagesize, mid, type, rev); }, 600);
					else	allComments=null;
				}
			}
		});
	}

})();