修复手机浏览器上PC版百度贴吧bug

随便试下

当前为 2025-09-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         修复手机浏览器上PC版百度贴吧bug
// @namespace    http://tampermonkey.net/
// @version      0.0.2
// @description  随便试下
// @author       shitianshiwa
// @include      http*://tieba.baidu.com/p/*
// @include      http*://tieba.baidu.com/f?*
// @grant        GM_registerMenuCommand
// @run-at       document-idle
// @license      WTFPL
// ==/UserScript==
//用try-catch错误处理代替判断链接,只有贴吧主页有展开置顶按钮可以捕捉,贴子里面捉不到,返回为null
//// @require    http://code.jquery.com/jquery-1.11.0.min.js

(function() {
    'use strict';
    var $ = unsafeWindow.jQuery; // @grant        不能为none,否则不能用
    //var $ = window.jQuery;
    //捕捉class用.,id对象用#?,$=document.getElementById?
    //alert("233");
    var t1;
    //注释:null 表示无值,而 undefined 表示一个未声明的变量,或已声明但没有赋值的变量,或一个并不存在的对象属性。
    function fixyandextieba() {
        clearTimeout(t1);
        //alert("233");
        //激活发贴文本编辑器
        var c = '<p> try 1 </p>'; //文本框
        //改变置顶展开按钮样式
        var cc1 = "display: none; position: absolute; left: 0px; z-index: 399;" //z-index元素图层高度?absolute相对定位
        var cc2 = "display: block; position: absolute; left: 0px; z-index: 399;"
        try {
            let a = $(".old_style_wrapper");// getby class name
            let b = document.getElementById("ueditor_replace"); //找到展开置顶按钮div,和$(".old_style_wrapper")功能一样用来搜索定位div
            if (b != null) {
               b.setAttribute("contenteditable", "true"); //搜索<div class="old_style_wrapper">添加文本框
            }
            //alert(b);
        } catch (error) {
            //alert(error);
        }
    }
    t1 = setTimeout(() => { fixyandextieba(); }, 2000); //延迟2s工作
})();