在公司摸鱼不是很方便,每次打开一个帖子顶部一个大大的标题,现学现卖,废九牛二虎写了一个油猴脚本,一打开帖子就把顶部隐藏,这下放心多了
this.$ = this.jQuery = jQuery.noConflict(true);
// ==UserScript==
// @name LinuxDo
// @namespace http://tampermonkey.net/
// @version 2024-11-25
// @description ⚡️去除LinuxDo头部大标题⚡️
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @require https://cdn.tailwindcss.com
// @author You
// @match *://*.linux.do/*
// @run-at document-start
// @icon https://www.google.com/s2/favicons?sz=64&domain=linux.do
// @grant none
// ==/UserScript==
(function () {
'use strict';
$(function () {
class LinuxDo {
ButtonCallback = {
"hide-title": this.HideTopTitle
}
UserStyleId = "user-style";
constructor() {
this.CreateCssStyle()
}
CreateCssStyle(css = "") {
let userStyle = $(this.UserStyleId);
if (userStyle.length > 0) {
userStyle.append(css);
return;
}
const style = $('<style>');
style.text(css);
style.attr("id", this.UserStyleId);
$('head').append(style);
}
HideTopTitle(dataType, hide = true) {
localStorage.setItem(dataType, hide.toString());
if (hide) {
this.CreateCssStyle(".title-wrapper span[dir='auto']{display:none !important}");
return
}
this.CreateCssStyle(".title-wrapper span[dir='auto']{display:block !important}");
}
Run() {
this.UserDesktop();
this.Init();
}
Init() {
Object.entries(this.ButtonCallback).forEach(([key, value]) => {
const checked = (localStorage.getItem(key) || null) === "true";
this.ButtonCallback[key]?.call(this, key, checked);
$(`input[data-type=${key}]`).prop("checked", checked);
});
}
UserDesktop() {
const userPanel = $(`<div class="box-border w-[150px] fixed top-[88px] right-[15px] flex flex-col justify-around border border-solid border-black rounded-[5px]">
<div class="p-[5px] flex flex-row justify-between">
<label class="form-control flex items-center gap-1">
<input type="checkbox" class="switch" data-type="hide-title"/>
<span class="label cursor-pointer flex-col items-start">
<span class="text-base-content/90 text-[#1e9fff] font-normal">隐藏顶部标题</span>
</span>
</label>
</div>
<div class="p-[5px] flex flex-row justify-between">
<label class="form-control flex items-center gap-1">
<input type="checkbox" class="switch" data-type="other"/>
<span class="label cursor-pointer flex-col items-start">
<span class="text-base-content/90 text-[#1e9fff] font-normal">其他功能</span>
</span>
</label>
</div>
</div>`);
let Instans = this;
$(userPanel).on("click", ".switch", function () {
let dataType = $(this).attr("data-type");
let callback = Instans.ButtonCallback[dataType] || null;
if (!callback) {
return;
}
let checked = $(this).is(":checked");
if (checked) {
callback.call(Instans, dataType, true)
return;
}
callback.call(Instans, dataType, false)
});
$("body").append(userPanel);
}
}
let app = new LinuxDo();
app.Run()
});
})();