您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
针对百度云新版重命名时提示【文件名不能包含以下字符:<,>,|,*,?,,/】,自动将特殊文件替换成空格
当前为
// ==UserScript== // @name 百度云重命名剔除特殊符号-自用 // @namespace http://tampermonkey.net/ // @version 0.16 // @description 针对百度云新版重命名时提示【文件名不能包含以下字符:<,>,|,*,?,,/】,自动将特殊文件替换成空格 // @author zyb // @match https://pan.baidu.com/disk/* // @exclude https://pan.baidu.com/share/* // @icon https://www.google.com/s2/favicons?sz=64&domain=baidu.com // @require https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js // @grant GM_addStyle // @license MIT // ==/UserScript== (function() { 'use strict'; // Your code here... let action = ""; const head = document.head; const style = document.createElement("style"); // 增加一个蒙版,以便触发新建文件夹的监听事件 const styleStr =` .newFolderBtnBox{ width:118px; height:100%; position:absolute; top:0; left:115px; cursor: pointer; } ` style.appendChild(document.createTextNode(styleStr)); head.appendChild(style); const newFolderBtnBoxDivDom = document.createElement("div"); newFolderBtnBoxDivDom.setAttribute("class","newFolderBtnBox"); const headerToolBar=document.querySelectorAll(".wp-s-agile-tool-bar.is-header-tool")[0]; headerToolBar.style.position="relative"; headerToolBar.appendChild(newFolderBtnBoxDivDom); setTimeout(()=>{ newFolderBtnBoxDivDom.addEventListener("click",e => { // 定位新建文件夹 let newFolderDom = document.querySelectorAll("button[title='新建文件夹']")[0]; if(!newFolderDom){ console.log(e) let shareDom = document.querySelectorAll(".is-header-tool button[title='共享']")[0]; if(e.clientX>455){ // 下载或者取消共享按钮 shareDom.parentNode.parentNode.children[2].children[0].click(); }else{ shareDom.click(); } return; } // 因为覆盖了原来的新建文件夹,所以只能手动触发,有新bug newFolderDom.click(); action = "newFolder"; console.log("action",action); }) },500) document.addEventListener('paste', (event) => { let inputDom = document.querySelectorAll(".wp-s-pan-list__file-name-edit--title-edit-input input")[0]; let miaochuanInputDom = document.querySelectorAll("#mzf-path-input")[0]; if(!miaochuanInputDom && !inputDom){ return; } // 阻止新文件名覆盖旧文件名,目的是获取就文件名 event.preventDefault(); // 获取解析 粘贴的文本 const clipboard = navigator.clipboard; let clipPromise = clipboard.readText(); clipPromise.then(function(clipText){ let newname = clipText.replaceAll(/<|>|\||\*|\?|\,|\/|:/g," "); console.log(newname); // 将新文件名回写到剪切板中 clipboard.writeText(newname); let inputDom = document.querySelectorAll(".wp-s-pan-list__file-name-edit--title-edit-input input")[0]; let miaochuanInputDom = document.querySelectorAll("#mzf-path-input")[0]; // 秒传重命名 if(miaochuanInputDom){ miaochuanInputDom.value = newname; return; } // 是否存在重命名按钮 let reNameBox = document.querySelectorAll(".is-header-tool button[title='重命名']")[0]; // 如果存在重命名按钮,说明用户选择的是重命名模式 if(reNameBox){ action = "rename"; console.log("action",action); } // 获取hash链接: "#/index?category=all&path=%2Fapps" let hashStr = location.hash || ""; // 解析hash链接获取路径 let pathStr = decodeURIComponent(hashStr.split('&').filter(function(item){return item.indexOf("path=")>-1})[0].split("path=")[1]); // 使用unsafeWindow获取最外层window数据 let bdstoken = unsafeWindow.locals.userInfo.bdstoken; // 计算logId let dpLogid = getLogID(); // 新建文件夹模式 if(action==="newFolder"){ inputDom && (inputDom.value = newname); $.ajax(`https://pan.baidu.com/api/create?a=commit&bdstoken=${bdstoken}&clienttype=0&app_id=250528&web=1&dp-logid=${dpLogid}`,{ type:'post', data:{ path : `${pathStr}/${newname}`, isdir: 1, block_list: [], }, complete:function () { console.log("complete!!"); location.reload(); } }); return; } // 重命名文件夹模式 if(action === "rename"){ // 获取原文件名 let oldName = inputDom.value || document.querySelectorAll(".nd-detail-filelist__name")[0]?.textContent || ""; if(newname===oldName || !oldName){ oldName = prompt("重命名失败,请输入旧文件名"); console.log("oldName",oldName) } inputDom && (inputDom.value = newname); if(inputDom){ $.ajax(`https://pan.baidu.com/api/filemanager?async=2&onnest=fail&opera=rename&bdstoken=${bdstoken}&clienttype=0&app_id=250528&web=1&dp-logid=${dpLogid}`,{ type:'post', data:{ filelist : JSON.stringify([{ path : `${pathStr}/${oldName}`, newname : newname }]) }, complete:function () { console.log("complete!!"); location.reload(); } }); } } }); }) function getLogID() { var n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#¥%……&"; var r = String.fromCharCode; var a = function(e) { if (e.length < 2) { var t = e.charCodeAt(0); return 128 > t ? e: 2048 > t ? r(192 | t >>> 6) + r(128 | 63 & t) : r(224 | t >>> 12 & 15) + r(128 | t >>> 6 & 63) + r(128 | 63 & t) } var t2 = 65536 + 1024 * (e.charCodeAt(0) - 55296) + (e.charCodeAt(1) - 56320); return r(240 | t2 >>> 18 & 7) + r(128 | t2 >>> 12 & 63) + r(128 | t2 >>> 6 & 63) + r(128 | 63 & t2) }; var o = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; var c = function(e) { return (e + "" + Math.random()).replace(o, a) }; var i = function(e) { var t = [0, 2, 1][e.length % 3], r = e.charCodeAt(0) << 16 | (e.length > 1 ? e.charCodeAt(1) : 0) << 8 | (e.length > 2 ? e.charCodeAt(2) : 0), a = [n.charAt(r >>> 18), n.charAt(r >>> 12 & 63), t >= 2 ? "=": n.charAt(r >>> 6 & 63), t >= 1 ? "=": n.charAt(63 & r)]; return a.join("") }; var d = function(e) { return e.replace(/[\s\S]{1,3}/g, i) }; var l = function() { return d(c((new Date).getTime())) }; var u = function(e, t) { return t ? l(String(e)).replace(/[+\/]/g, function(e) { return "+" == e ? "-": "_" }).replace(/=/g, "") : l(String(e)) }; var f = function(e) { var t, n; if(document.cookie.length > 0 && (t = document.cookie.indexOf(e + "="), -1 != t)){ t = t + e.length + 1; n = document.cookie.indexOf(";", t); -1 == n && (n = document.cookie.length); return decodeURI(document.cookie.substring(t, n)) }else{ return ""; } // return document.cookie.length > 0 && (t = document.cookie.indexOf(e + "="), -1 != t) ? (t = t + e.length + 1, n = document.cookie.indexOf(";", t), -1 == n && (n = document.cookie.length), decodeURI(document.cookie.substring(t, n))) : "" }; var h = function(e) { var t = new RegExp(e + "=([^#&]*)", "g"), n = t.exec(location.hash); return n ? decodeURIComponent(n[1]) : "" } return u(f('BAIDUID')); } })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址