百度网盘替换标题

百度网盘替换标题显示完整标题

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         百度网盘替换标题
// @namespace    https://greasyfork.org/zh-CN
// @version      1.1.0
// @description  百度网盘替换标题显示完整标题
// @author       冰冻大西瓜
// @license      AGPL-3.0-only
// @match        https://pan.baidu.com/s/*
// @match        https://pan.baidu.com/share/init?surl=*&pwd=*
// @grant        GM_addStyle
// @note         2024年2月24日 如果链接含提取码,自动跳转
// ==/UserScript==

if (!window.location.href.includes('share/init?surl')) {
  GM_addStyle(`
/* 隐藏无用按钮,为完整标题展示腾出显示空间 */
.slide-show-right a:is([title="保存到手机"],[title="举报"]){
  display: none;
}
/* 取消对标题长度的限制,防止标题内容被隐藏 */
h2.file-name{
  max-width:unset !important;
}
/* 改变按钮位置,为完整标题腾出显示空间 */
.slide-show-center{
  float: right !important;
}
`)

  const showTitle = document.querySelector('.file-name')
  const sourceTitle = document.title.split('_免费')[0]
  // 创建观察实例,监听标题变化
  const observer = new MutationObserver(() => {
    showTitle.innerHTML = sourceTitle
    // 标题替换完成后停止观察 === 会先于 && 执行
    showTitle.innerHTML === sourceTitle && observer.disconnect()
  })

  observer.observe(showTitle, { childList: true })
} else {
  // 如果有提取码,自动跳转
  const accessCode = document.getElementById('accessCode').value

  accessCode && document.getElementById('submitBtn').click()
}