// ==UserScript==
// @name 贴吧手机版
// @namespace https://space.bilibili.com/8286319
// @version 1.5.5
// @description 替代贴吧APP,需要配合user-agent switcher 切换成PC模式
// @author happmaoo
// @match https://tieba.baidu.com/*
// @exclude https://tieba.baidu.com/photo/*
// @exclude https://tieba.baidu.com/home/*
// @exclude http://tieba.baidu.com/mo/*
// @exclude http://tieba.baidu.com/mo/q---1E1A44492752A8CFE48A31DB2C0BB8FE:FG=1--1-3-0--2--wapp_1536855175546_700/m?tn=bdIndex&lp=5014&pinf=1_1_0
// @exclude https://tieba.baidu.com/f/like/mylike
// @icon https://www.baidu.com/favicon.ico
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// @downloadURL https://update.greasyfork.icu/scripts/513598/%E8%B4%B4%E5%90%A7%E6%89%8B%E6%9C%BA%E7%89%88.user.js
// @updateURL https://update.greasyfork.icu/scripts/513598/%E8%B4%B4%E5%90%A7%E6%89%8B%E6%9C%BA%E7%89%88.meta.js
// ==/UserScript==
// 1.5 版本取消引入外部jq,因为会和贴吧jq冲突。
// 1.3 版本更新:@run-at document-start 加载前用一个遮罩挡住原来的网页,免得到时候样式切换的时候闪一下。
// 加载前遮罩挡住
document.documentElement.insertAdjacentHTML('afterbegin', '
');
function viewport() {
if (document.querySelector('meta[name="viewport"]')) {
return;
}
const el = document.createElement("meta");
el.name = "viewport";
el.content = "width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no";
document.head.append(el);
}
(function() {
function waitForJQuery() {
if (typeof $ !== 'undefined') {
// jQuery 已加载
//--------------------------- $(document).ready -------------------------------------
$(document).ready(function() {
'use strict';
//$('link[rel="stylesheet"], style').remove();
$("body").css({
"display": "block"
});
// Your code here...
viewport();
var mycss2 = `
.lottery-thread-modal-post,.u_creative,.u_official,.u_bdhome,.u_member,.u_setting,.media_box,.u_ddl,.j-placeholder-pay-member,.p_share_ding,#d_post_manage,.j_clear_fullscreen,.dialogJmodal,.tbshare_popup_wrapper,.ui_bubble_wrap,.footer,.homeworks_guide,.tbui_aside_smiley,.ip-location,.lzl_more,.replace_tip,.poster_head,.d_badge_title,.d_badge_lv,.threadlist_detail>.threadlist_author,.head_content,.share_btn_wrapper,.icon-jubao,.user-hide-post-down,.right_section,.suggestion_list,.search_top,#fixed_bar,.aside,.nav_wrap,.card_banner{display:none!important;}
/*这个不能隐藏,不然控制台疯狂错误*/
.card_top_wrap{ height: 0;width: 0;display:block;overflow: scroll;}
ul,li{list-style-type:none;padding:0px;margin:0;}
.aaaa{padding:0px!important;margin:0!important;width:auto!important;margin:0!important;}
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";}
.userbar ul li{float: left;}
.userbar {overflow: hidden;display: block;clear: both;}
.u_notity_bd ul li{float: left; margin:0 5px 0 0;}
.u_ddl{display:none;}
.search_ipt{width:100px!important;}
.search_btn{margin:0 5px;}
.dialogJfix{position: fixed;background: #eee;}
/* 列表 */
#thread_list{padding:0px;}
.threadlist_video{display:none!important;}
.threadlist_author{float:right;font-size:14px;color:#777!important;}
.threadlist_author a{font-size:14px;color:#777!important;}
.threadlist_media li,.col2_left{float:left;}
.threadlist_rep_num{background: #917ccd;color: #fff;border-radius: 5px;padding:2px 5px;margin-right:5px;font-size:14px;font-family: sans-serif;font-weight: bold;}
.j_thread_list{background:#fff;overflow:hidden;margin:0 0 10px 0;}
.threadlist_title{margin: 0 0 0 25px;}
.j_thread_list a:link{text-decoration:none;color:#000;}
.j_thread_list a:visited{color:#888!important;}
.threadlist_text {
display: -webkit-box;
font-size: 14px;
color: #999;
line-height: 2.5em;
max-height: 100px;
text-indent: 2em;
overflow: hidden;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.jump_input_bright{width:30px;}
.pb_content h1,.pb_content h3{font-size:20px;width:auto!important;}
/* 回复相关 */
.d_post_content_main{padding-left:10px;display:block;overflow: auto;flex: 0.9;}
.d_post_content img{max-width:300px;height:auto;}
.core_reply_content{background:#fff;margin-left:20px;padding:5px 10px;font-size:14px!important;}
.core_reply_content .j_user_card img{display:none;}
.p_author img{width:30px;height:auto;}
.lzl_jb .lzl_jb_in{width:0;height:0;display:none!important;}
.core_reply_tail ul,.p_reply{float:left;font-size:12px;color:#aaa;}
.core_reply_tail .p_tail li{float:left;}
.core_reply_content a,.core_reply_tail a{}
.d_name a{text-decoration:none;font-size:14px;}
.p_author{float:left;}
.l_post{background:#fff;overflow:hidden;border-bottom: 1px solid #aaa;margin: 10px 0;padding-bottom:10px;}
.post-tail-wrap span{text-indent:0.5em;line-height: 100%;}
.post-tail-wrap,.post-tail-wrap a{font-size:12px;color:#aaa;text-indent:0.5em;line-height: 100%;}
.l_post .d_author{display:block;width:60px;font-size:14px;line-break: anywhere;flex: 0.1;border-right: 1px solid #ccc;}
/* 编辑器相关 */
.edui-popup{display:block;background:#eee;border: 1px solid #aaa;padding:20px;left:10px!important;}
.edui-popup .s_face {width:30px!important;height:30px!important;}
.edui-btn-image{}
.emotion_container .s_face .img {
background: transparent url(https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/default/fFace.png?t=20140529) no-repeat scroll left top;
width: 30px;
height: 30px;
background-size: 100% auto;
}
.edui-btn-image::before,.edui-btn-emotion::before {
content: "🖼️";
color:#fff;margin:0 6px 5px 0;padding:5px 0 0 0;
text-align: center;
float: left;
display:block;width:50px;height:30px;background:#eee;
font-size: 18px; /* 设置字体大小 */
}
.edui-btn-emotion::before {content: "😀";}
.ueditor_emotion_tab,.emotion_preview{display:none!important;}
.tbui_panel_content{height:auto!important;}
.next_step{display:block;width:100px;line-height:2em;background:#ccc;text-align: center;}
.slide_item{float:left;display:none;}
.j_ok {
position: fixed; /* 设置为固定定位 */
left: 0; /* 距离左边 0 像素 */
bottom: 0; /* 距离底部 0 像素 */
background-color: rgba(0, 0, 0, 0.7); /* 背景颜色 */
color: white; /* 字体颜色 */
padding: 10px; /* 内边距 */
}
.i_item_bg{width:60px;height:60px;}
.flash_editor_container,.error{display:none;}
.edui-container .BDE_Image{width:100px!important;height:auto!important;}
#ueditor_replace{width:350px!important;}
.edui-container{width:350px!important;}
.dialogJbody{height:250px!important;}
.poster_submit{margin:5px;display:block;padding:5px;width:100px;background:#eee;text-align: center;font-size: 16px;text-decoration:none;}
.poster_submit em{color:#000;font-style: normal!important;}
.edui-editor-body{border: 1px solid #aaa;width:auto;}
.dialogJcontent img{background-size: contain;}
.edui-toolbar{overflow: hidden;}
.fullscreen-word-limit{margin:0;}
/* reply 回复楼中楼 */
.core_reply_content{
max-height:200px;
overflow: hidden;
}
.core_reply_content:hover{
overflow: auto; /* 鼠标悬停时显示内容 */
}
.editor_for_container{background:#fff;}
.lzl_panel_submit{margin:5px;display:block;padding:5px;width:50px;background:#eee;text-align: center;font-size: 16px;text-decoration:none;}
.core_reply_tail{clear:both; display: block; overflow: hidden;}
.post-tail-wrap span{float:left;}
video{max-width:300px;}
.l_post{
display: flex;
flex-direction: row;
}
.BDE_Image{width:auto!important;}
.test{background:#0f0;}
.mydiv1{clear:both;overflow: hidden;margin:0 0 10px 0;padding:0 0 10px 0;border-bottom: 1px solid #aaa;}
.mydiv1 li{float:left;margin:0 0 0 5px;}
.favlist{clear:both;border-top: 1px solid #aaa;padding: 10px 0 0 0;margin: 10px 0 0 0!important;}
/* 翻页 */
.pagination-default span,.pagination-default a{float:left;margin-left:5px;display:block;padding:2px 5px;background:#eee;}
.pagination-default{clear:both;overflow: hidden;}
.pb_list_pager span,.pb_list_pager a{float:left;margin:5px 0 5px 5px;display:block;padding:2px 5px;background:#eee;}
.art-poster,.art-subtitle,.art-danmuku,.art-layers,.art-mask,.art-bottom,.art-loading,.art-notice,.art-info,.art-mini-header,.art-contextmenus{display:none;}
/* 消息页面 https://tieba.baidu.com/i/i/replyme */
.sub_tab_content{margin: 10px 0;}
.feed ul li{margin:0 0 20px 0;padding:5px;border: 1px solid #aaa;clear: both;background:#fff;color: #888;font-size: 14px;}
.feed ul li a{color: #888;}
.replyme_content,.replyme_content a{padding:10px 5px;color:#000!important;text-decoration:none;font-size: 16px;}
.sub_tab_content li,.tab_content li{float:left;margin-right:5px;}
/* 搜索页面 */
.s_aside{display:none;}
.s_post_list{margin:10px 0 10px 0;}
.s_post{margin:0px 0 20px 0;font-size:14px;}
.s_post_list .p_content{padding:5px;background:#f5f5f5;}
.pager-search span,.pager-search a{float:left;margin:5px 0 5px 5px;display:block;padding:2px 5px;background:#eee;}
/* 弹出框的样式 */
.mypopup {width: 300px;height: 200px;background-color: #fff;color: #333;border: 1px solid #ccc;border-radius: 5px;box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);padding: 20px;position: fixed;top: 20px;left: 20px;}
.mypopup .x{ background: #eee;
position: relative;
float: right;
overflow: hidden;
clear: both;
padding: 5px 10px;}
.mypopup .text{overflow: hidden;
clear: both;}
#backToTop {
display: none; /* 初始隐藏 */
position: fixed;
bottom: 20px;
right: 20px;
width: 40px;
height: 40px;
background-color: #333;
color: #fff;
text-align: center;
line-height: 40px;
border-radius: 50%;
cursor: pointer;
font-size: 14px;
opacity: 0.2;
z-index: 1000;
}
`;
setTimeout(function() {
$('link[rel="stylesheet"], style').remove();
GM_addStyle(mycss2);
//去除遮罩
$("#fullscreen-overlay").remove();
}, 500);
/* 顶部 吧内搜索 */
var keyword = $('input[name="kw1"]').val();
var mysearch = `
↑
`;
$(".content").before(mysearch);
// 关注按钮
$(".mylike").on("dblclick", function() {
var fid = $.getPageData("forum.id", 0);
//var a = $.getPageData("forum.name", 0);
var tbs = $.getPageData("tbs", 0);
var uname = $.getPageData("user.name", "")+'&ie=utf-8';
const data = new URLSearchParams({
fid: fid,
//fname: 'illustrator',
uid: uname,
ie: 'gbk',
tbs: tbs,
jt: ''
}).toString();
var text = $(".mylike").html();
var url = "https://tieba.baidu.com/f/like/commit/add";
if ($(".mylike").html().includes("取消")) {
url = "https://tieba.baidu.com/f/like/commit/delete";
}
GM_xmlhttpRequest({
method: 'POST',
url: url,
data: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
onload: function(response) {
alert("执行完成: "+response.responseText);
$(".mylike").prop("disabled", true);
},
onerror: function(error) {
alert(error);
}
});
});
setTimeout(function() {
// 是否已经关注 延迟1秒执行
if ($(".user_level").html() !== null) {
$(".mylike").html("取消关注");
}
/* 顶部我的消息 */
$('.userbar ul li').not('.u_username, .u_news').hide();
$('.u_news_wrap').attr('href', 'https://tieba.baidu.com/i/sys/jump?type=replyme');
$('.u_news_wrap').attr('onclick', '');
$('.u_news_wrap').attr('target', '_blank');
}, 1000);
let isJobRunning = false;
function job(){
if (isJobRunning) return;
isJobRunning = true;
// 查找内容为 "广告" 的 span
$('span').filter(function() {
return $(this).text().trim() === '广告';
}).each(function() {
$(this).parent().html('ad1');
});
$('.l_post[data-field="{}"]').remove();
/* 视频相关 */
$('video').each(function() {
$(this).attr('controls', true);
$(this).removeAttr('autoplay');
});
//$('video').remove();
$('#thread_list>div').remove();
$('.p_postlist').children().not('.l_post, .p_postlist').html('ad2');
// 修改过长字符
$('.post-tail-wrap,.core_reply_tail ').each(function() {
$(this).find('span,a').each(function() {
$(this).text($(this).text().replace("IP属地:", ""));
$(this).text($(this).text().replace("来自", ""));
$(this).text($(this).text().replace("客户端", ""));
});
});
isJobRunning = false;
}
// 页面加载后 每 x 秒执行一次,运行 x 次
let count = 0;
const intervalId = setInterval(function() {
job();
count++;
if (count >= 10) {
clearInterval(intervalId);
}
}, 500);
// 滚动时执行,不滚动时不执行,优化代码
$(window).on("scroll", function() {
job();
});
$('.poster_submit').on('click', function() {
$(this).css('background-color', '#aaa');
setTimeout(() => {
$(this).css('background-color', '#eee');
}, 1000);
});
// 贴吧主页
if (window.location.href === 'https://tieba.baidu.com/' || window.location.href === 'https://tieba.baidu.com/index.html') {
var mycssindex = `
html{padding:20px;}
a{margin-right:10px;}
`;
setTimeout(function() {
GM_addStyle(mycssindex);
}, 500);
$('img').remove();
// 获取 ID 为 likeforumwraper 的元素的 HTML 内容
var newContent = $('.left-sec').html();
// 替换整个 body 的内容
$('body').html(newContent);
} else {
}
//-------------------------------设置------------------------------------
$("body").prepend("");
// 页面加载时读取设置
if(GM_getValue("liststyle", "normal")=="normal"){
//alert(GM_getValue("liststyle", "normal"));
$('input[name="option"][value="option1"]').prop("checked", true);
}else{
$('input[name="option"][value="option2"]').prop("checked", true);
setTimeout(function() {
GM_addStyle(".threadlist_text{display:none;}");
}, 500);
}
// 选中 设置
$('input[name="option"]').change(function() {
if ($('input[name="option"][value="option1"]').is(':checked')) {
GM_setValue("liststyle", "normal");
}
if ($('input[name="option"][value="option2"]').is(':checked')) {
GM_setValue("liststyle", "onlytit");
}
});
// 关闭按钮 mypopup
$(".mypopup .x").on("click", function() {
$(".mypopup").css({'display': 'none'});
});
// 打开设置 mypopup
$(".mysetting").on("click", function() {
$(".mypopup").css({'display': 'block'});
});
//-------------------------------------------------------------------
//上传图片点击事件 不兼容手机
/*
$('.edui-btn-image').on('click', function() {
//$('.next_step').click();
setTimeout(function() {
$('.next_step').click();
}, 500);
});
*/
//-------------emoji 未使用---------------------
function insertText(text) {
let editor = document.getElementById("ueditor_replace"); // 获取编辑器
editor.focus(); // 确保编辑器获得焦点
let selection = window.getSelection(); // 获取当前选择
//console.log(selection);
let range = selection.getRangeAt(0); // 获取光标所在的范围
// 创建一个文本节点
let textNode = document.createTextNode(text);
// 插入内容到光标位置
range.insertNode(textNode);
// 移动光标到新插入内容的后面
range.setStartAfter(textNode);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
}
// $(".poster_reply").after('😀');
$(".mybtn-emoji").on("click", function() {
$(".mybtn-emoji").after('😀😆😅😍😱🏀🧐😞😓😭👍🐱🚴♂️
');
$(".emoji-char span").on("click", function() {
let char = $(this).text(); // 获取点击的字符
//alert(char);
insertText(char);// 插入到光标位置
$(".emoji-char").remove();
});
});
// 我关注的贴吧列表
$(".fav").on("click", function() {
GM_xmlhttpRequest({
method: "GET",
url: "https://tieba.baidu.com/f/like/mylike",
onload: function(response) {
if (response.status === 200) {
console.log("Request successful:", response.responseText);
let htmlObject = $(response.responseText);
// 使用 jQuery 选择 "吧名" 这一列的元素
let names = [];
htmlObject.find("td:first-child a").each(function() {
names.push($(this).text());
});
let links = names.map(name => `${name}`).join(" - ");
$(".mydiv1").append("" + links + "");
$(".fav").remove();
} else {
console.error("Request failed with status:", response.status);
}
},
onerror: function(error) {
console.error("Request failed:", error);
}
});
});
// 插入图片时的修复,会给html元素插入css让页面无法滚送,并无法显示图片框
// 方法是监控html标签style,发现后自动执行代码
const targetNode = document.documentElement;
const config = { attributes: true, attributeFilter: ["style"] };
let timeoutId = null;
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
// 如果计时器已存在,说明1秒内已执行过清除操作
if (timeoutId) return;
// 清除 style 属性
// 插入图片相关
$('.button_bar').css({
'display': 'none'
});
$('html').css({
'overflow': '', // 清除 overflow 样式
'padding-right': '' // 清除 padding-right 样式
});
$('.dialogJfix').css({
'position': 'fixed',
'padding': '20px', // 清除 overflow 样式
'left': '10px',
'width': '280px',
'border': '1px solid #aaa',
'background': '#eee' // 清除 padding-right 样式
});
// 设置计时器,1秒后允许再次执行清除
timeoutId = setTimeout(() => {
timeoutId = null;
}, 1000);
}
}
});
// 开始观察目标节点
observer.observe(targetNode, config);
/*
// 发完帖自动滚动到底部
$(".poster_submit").on("click", function() {
setTimeout(function() {
$(window).scrollTop($(document).height() - 800);
}, 5000);
});
*/
});//--------------------------------end of $(document).ready ------------------------------
// 返回顶部按钮
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('#backToTop').fadeIn();
} else {
$('#backToTop').fadeOut();
}
});
} else {
// 每隔 100 毫秒检查一次,直到 jQuery 加载完成
setTimeout(waitForJQuery, 100);
}
}
waitForJQuery();
})();
/*
备份
// 设置icon
// 去掉详情页的帖子广告
var nodes = document.querySelectorAll('.l_post');
nodes.forEach(function(node){
if(node.classList.length > 4) {
node.remove();
}
});
*/