// ==UserScript== // @name 抽屉评论本页打开 // @version 1.0.4 // @icon https://dig.chouti.com/images/favicon-d38b877458.png // @description 抽屉打开评论区直接本页显示 // @author mjc // @create 2019-07-01 // @match https://dig.chouti.com/* // @exclude https://dig.chouti.com/zone/video/ // @exclude https://dig.chouti.com/publish/links/cdu_* // @exclude https://dig.chouti.com/voted/links/cdu_* // @namespace https://greasyfork.org/users/212546 // @grant GM_addStyle // @run-at document-end // @downloadURL none // ==/UserScript== (function ($) { 'use strict'; if (!window.location.href.endsWith("#comment-area")) { //首页 $(function () { //监听 评论点击事件 $(".outer-container").on("click", "a.operate-item.comment", function (e) { var self = this; if ($(self).parents(".link-item").find("#comment-iframe").length > 0) { $("#comment-iframe,#comment-loading").remove(); return false; } if ($("#comment-iframe").length > 0) { $("#comment-iframe,#comment-loading").remove(); $(self).parents(".link-item")[0].scrollIntoView(); } var comment_loading='
'; $(self).parents(".link-item").append(comment_loading); var comment_iframe = $('') .css({ width: "840px", padding: "8px", height: "300px", "margin-top": "-15px;"}) .load(function () { $("#comment-loading").remove(); }).attr("src", self.href + "#comment-area"); $(self).parents(".link-item").append(comment_iframe); return false; }); $('.msg-alert,.loading-more-btn').on('click', function (e) { $("#comment-iframe,#comment-loading").remove(); }); $('body').on('click', function (e) { if ($('#comment-iframe').length <= 0) return; if ($(e.target).is("a,button,img,.mask")) return; if ($(e.target).css("cursor") === "pointer") return; if ($("#mask").length > 0 && $("#mask").is(":visible")) return; var view = $(e.target).parents(".link-item"); if (view.length == 0) view = $('#comment-iframe').parent(); $("#comment-iframe,#comment-loading").remove(); view[0].scrollIntoView(); }); }); } else { //iframe 中打开的评论页面 //隐藏 不必要内容 var comment_page_style = [ ".header-fix{display: none !important;}", ".footer{display: none !important;}", ".link-area{display: none !important;}", ".extra{display: none !important;}", ".original-link-top-area{display: none !important;}", ".original-link-area{display: none !important;}", ".original-link-operate-con{display: none !important;}", ".main-container {margin-top: 0px!important;}" ].join("\n"); setStyle(comment_page_style); $(function () { //评论 加载完成 设置 iframe高度 $(document).ajaxSuccess(function (evt, request, settings) { if (settings.url.includes("/comments/show?id=")) { setTimeout(() => $("#comment-iframe", window.parent.document).height($(".comment-area").innerHeight()+30), 10); } }); }); } function setStyle(css) { if (typeof GM_addStyle != "undefined") { GM_addStyle(css); } else if (typeof PRO_addStyle != "undefined") { PRO_addStyle(css); } else if (typeof addStyle != "undefined") { addStyle(css); } else { var node = document.createElement("style"); node.type = "text/css"; node.appendChild(document.createTextNode(css)); var heads = document.getElementsByTagName("head"); if (heads.length > 0) { heads[0].appendChild(node); } else { document.documentElement.appendChild(node); } } } })(jQuery);