// ==UserScript== // @name 游戏社区(TapTap)列表页贴子预览 // @namespace https://github.com/QIUZAIYOU/Taptap-PostPreview // @version 1.2.72 // @description 【因TapTap更新本脚本目前已废】TapTap游戏社区列表页贴子(除图片和视频贴)卡片新增预览按钮,可在列表页直接预览贴子内容。 // @author QIAN // @match *://www.taptap.com/app* // @match *://www.taptap.com/forum/hot // @grant none // @require https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js // @downloadURL none // ==/UserScript== $(function() { const pvBtn = "预览"; //创建预览贴子样式 const pvBtnCss = `` let pvCssCustom = ``; let pvCssOfficialTopic = ` `; let pvCssOfficialMoment = ` `; $("body").prepend(pvBtnCss); $("body").prepend(pvCssCustom); //延迟执行等待贴子列表加载完成 setTimeout(function() { //创建预览和取消预览按钮 $(".moment-list-item .moment-card__footer").append(pvBtn); //遍历每个贴子 $(".moment-list-item").each(function() { $(this).find(".pvBtn").eq(0).addClass("first"); $(this).find(".pvBtn").not(".first").remove(); let postLinkId = $(this).attr("data-event-log").split(',')[0].replace(/[^\d]/g, ""); let postLinkType = $(this).attr("data-event-log").split(',')[1].replace('"paramType":"', '').replace('Detail"', ''); let postLink = `https://www.taptap.com/${postLinkType}/${postLinkId}` //创建预览贴子容器 let pvBoxWrapper = `
` let pvBox = `
`; //为预览按钮添加点击事件 $(this).find(".pvBtn").click(function(event) { event.stopPropagation(); $("body").append(pvBoxWrapper); $("body").find(".pvBoxWrapper").append( pvBox); //创建进入贴子及取消预览按钮 let btnList = ``; //区分普通贴和其他贴 if (`${postLink}`.indexOf("topic") != -1) { $("body .pvBoxWrapper .pvBox").attr("postlink", `${postLink}`) $("body .pvBoxWrapper .pvBox").load( `${postLink} .topic-main__content`); $("body .pvBoxWrapper .pvContent").prepend(btnList); $("body .pvBoxWrapper").prepend(pvCssOfficialTopic); } else { return false; } //为取消预览按钮添加点击事件 $("body .pvBoxWrapper .pvBtnClose").click(function() { //移除贴子的预览内容及样式文件 $("body .pvBoxWrapper").remove(); }); }); if (`${postLink}`.indexOf("video") != -1) { $(this).find(".pvBtn").text("视频贴无法预览").addClass("disable").unbind(); } else if (`${postLink}`.indexOf("moment") != -1) { $(this).find(".pvBtn").text("动态贴无法预览").addClass("disable").unbind(); }; }); }, 2300); //点击遮罩层关闭预览 $(document).mouseup(function(e) { let con = $(".pvContent"); // 设置目标区域 if (!con.is(e.target) && con.has(e.target).length === 0) { $("body .pvBoxWrapper").remove(); } }); })