// ==UserScript==
// @name 游戏社区(TapTap)列表页贴子预览
// @namespace 游戏社区列表页贴子预览
// @version 1.1.2
// @description TapTap游戏社区列表页贴子(除图片和视频贴)卡片新增预览按钮,可在列表页直接预览贴子内容。
// @author QIAN
// @match *://www.taptap.com/app*
// @match *://www.taptap.com/forum/hot
// @grant none
// @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @downloadURL none
// ==/UserScript==
$(function () {
//获取浏览器页面链接
var location = window.location.href;
location = location.toLowerCase();
//如果为TapTap域名
if (location.indexOf("taptap") != -1) {
//创建预览和取消预览按钮
var pvBtn = "
预览";
var pvBtnClose = "取消预览";
//创建预览贴子样式
var pvBtnCss =
''
//var pvCss = '';
var pvCssCustom =
'';
var pvCssOfficial =
'';
var pvCssVideo =
'';
var pvCssMoment =
'';
//在除图片和视频贴以外的贴子卡片上追加预览和取消预览按钮以及按钮样式
$(".app-body").prepend(pvBtnCss);
$(".topic-item[data-filter-id*='moment'] .item-text-footer").prepend(pvBtn);
$(".topic-item[data-filter-id*='moment'] .item-text-footer").prepend(pvBtnClose);
//遍历每个贴子
$(".topic-item[data-filter-id*='moment']").each(function () {
//获取贴子链接
//var postLink = $(this).find(".topic-share").attr("data-share-url");
var postLink = $(this).find(".taptap-btn-link").attr("href");
//创建预览贴子容器
var pvBoxWrapper = ``
var pvBox =
``;
//为预览按钮添加点击事件
$(this).find(".pvBtn").click(function () {
//获取预览按钮相对文档顶部的偏移量
var pvBtnOffset = $(this).offset().top;
// var otherPvBoxHeight = parseInt($(this).parents(
// ".topic-item[data-filter-id*='moment']").siblings().find(
// ".pvBoxWrapper").css("height"));
// var documentHeight = $(document).height();
// var offsetAbs = Math.abs(pvBtnOffset - otherPvBoxHeight);
// //浏览器滚动条自动定位至预览按钮
// if (isNaN(otherPvBoxHeight) == true) {
// $("html,body").animate({
// scrollTop: offsetAbs - 12 + "px"
// }, 300);
// } else {
// $("html,body").animate({
// scrollTop: pvBtnOffset - 12 + "px"
// }, 300);
// }
$("html,body").animate({
scrollTop: pvBtnOffset - 12 + "px"
}, 300);
//创建进入贴子按钮
var enterBtn =
`进入贴子`;
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".item-text-footer").prepend(enterBtn);
//显示贴子内容
$(this).parents(".topic-item[data-filter-id*='moment']").append(pvBoxWrapper);
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvBoxWrapper").append(
pvBox);
//区分普通贴和视频贴内容
if (`${postLink}`.indexOf("topic") != -1) {
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvBox").load(
`${postLink} .topic-main__content`);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssCustom);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssOfficial);
} else if (`${postLink}`.indexOf("video") != -1) {
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvBox").load(
`${postLink} .video-page__main-content`);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssCustom);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssVideo);
} else if (`${postLink}`.indexOf("moment") != -1) {
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvBox").load(
`${postLink} .moment-main`);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssCustom);
$(this).parents(".topic-item[data-filter-id*='moment']").find(
".pvBoxWrapper").prepend(pvCssMoment);
}
//隐藏预览按钮,显示取消预览按钮
$(this).css("display", "none");
$(this).siblings(".pvBtnClose").css("display", "block");
//移除其他贴子的预览内容、进入按钮及样式文件,并切换预览按钮为取消预览按钮
$(this).parents(".topic-item[data-filter-id*='moment']").siblings().find(
".pvBoxWrapper").remove();
$(this).parents(".topic-item[data-filter-id*='moment']").siblings().find(
".pvStyle").remove();
$(this).parents(".topic-item[data-filter-id*='moment']").siblings().find(
".pvBtnClose").css("display", "none");
$(this).parents(".topic-item[data-filter-id*='moment']").siblings().find(
".pvBtn").css("display", "block");
$(this).parents(".topic-item[data-filter-id*='moment']").siblings().find(
".enterBtn").remove();
});
//为取消预览按钮添加点击事件
$(this).find(".pvBtnClose").click(function () {
//移除贴子的预览内容及样式文件,并切换预览按钮为取消预览按钮
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvBoxWrapper").remove();
$(this).parents(".topic-item[data-filter-id*='moment']").find(".pvStyle").remove();
$(this).css("display", "none");
$(this).siblings(".pvBtn").css("display", "block");
//移除进入贴子按钮
$(this).siblings(".enterBtn").remove();
});
});
//其他域名待补充
} else if (location.indexOf("aiideai") != -1) {};
});