百度云重命名剔除特殊符号-输入框版

针对百度云新版重命名时提示【文件名不能包含以下字符:<,>,|,*,?,,/】,自动将特殊文件替换成空格

目前為 2023-02-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         百度云重命名剔除特殊符号-输入框版
// @namespace    http://tampermonkey.net/
// @version      0.18
// @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
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
	'use strict';
	const head = document.head;
	const style = document.createElement("style");
	const styleStr =`
	  #removeSpecialSymbolsInput{
	    width:20%;
	    position:absolute;
	    top:103px;
	    left:11%;
	  }
	`
	style.appendChild(document.createTextNode(styleStr));
	head.appendChild(style);

	const inputDom = document.createElement("input");
	inputDom.setAttribute("id","removeSpecialSymbolsInput");
	inputDom.setAttribute("class","u-input__inner");
	inputDom.setAttribute("type","text");
	inputDom.setAttribute("autocomplete","off");
	inputDom.setAttribute("placeholder","请输入需要去除特殊符号的文本");
	const fatherDom = document.querySelectorAll('.nd-main-layout__body .wp-s-core-pan__body-contain--list')[0];
	fatherDom.appendChild(inputDom);

	let showMsg = null;

	inputDom.addEventListener('paste', (event) => {

		// 获取解析 粘贴的文本
		const clipboard = navigator.clipboard;
		let clipPromise = clipboard.readText();
		clipPromise.then(function(clipText){
			let newname = clipText.replaceAll(/<|>|\||\*|\?|\,|\/|:/g," ");
			console.log(newname);
			// 将新文件名回写到剪切板中
			clipboard.writeText(newname);
			inputDom.value = newname;
			if(!showMsg){
				showMsg = new ShowMsg();
			}

			showMsg.toast({
				template:"文本已复制到剪贴板",
				time:3000,
			})
		});

	})

	class ShowMsg{
		constructor(){
			this.createClassFuc();
		}
		createClassFuc(){
			const head = document.head;
			let style = document.createElement("style");
			const styleStr =`
					#toastBox{
					  min-width: 250px;
					  position: absolute;
					  top: -100px;
					  left: 50%;
					  padding: 15px 20px;
					  background: #ebf8f2;
					  border: 1px solid #cfefdf;
					  border-radius: 10px;
					  transform: translate(-50%,0);
					  display: flex;
					  justify-content: center;
					  align-items: center;
					  z-index: 9999;
					  opacity:0;
					}
					#toastBox.show{
					  top:60px;
				     opacity:1;
				     animation-name: showToast;
				     animation-duration: 0.5s;
					}
				   #toastBox.hide{
					  top: -100px;
					  opacity:0;
				     animation-name: hideToast;
				     animation-duration: 0.4s;
				   }
				   @keyframes showToast {
				     0% {
				       top: -100px;
					    opacity:1;
				     }
				     100% {
				       top:60px;
					    opacity:1;
				     }
				   }
				   @keyframes hideToast {
				     0% {
				       top:60px;
				       opacity:1;
				     }
				     99% {
				       top:60px;
				       opacity:0;
				     }
				     100%{
				       top:-100px;
					    opacity:0;
				     }
				   }
				   #toastBox i{
				     width: 20px;
				     height: 20px;
				     background: #00a854;
				     border-radius: 50%;
				     position: relative;
				     translate: -8px 0;
				   }
				   #toastBox i:before{
				     content: "";
				     width: 12px;
				     height: 5px;
				     display: inline-block;
				     border: 1px solid #fff;
				     border-width: 0 0 2px 2px;
				     transform: rotate(-45deg);
				     -ms-transform: rotate(-45deg);
				     -moz-transform: rotate(-45deg);
				     -webkit-transform: rotate(-45deg);
				     -o-transform: rotate(-45deg);
				     vertical-align: baseline;
				     position: absolute;
				     left: 3.5px;
				     top: 6px;
				   }
				`
			style.appendChild(document.createTextNode(styleStr));
			head.appendChild(style);
		};
		createToastBoxFuc(template){
			const body = document.body;
			let divDom = document.createElement("div");
			divDom.setAttribute("id","toastBox");
			divDom.innerHTML = `<i></i><p class="content">${template}</p>`;
			body.appendChild(divDom);

			this.toastBoxDom = divDom;
		}
		toast(obj){
			let template="", time = 2500;
			if(typeof obj !== "String"){
				template = obj.template;
				time = obj.time;
			}else{
				template = obj;
			}

			!this.toastBoxDom && this.createToastBoxFuc(template);
			this.toastBoxDom.setAttribute("class","show");
			setTimeout(()=>{
				this.toastBoxDom.setAttribute("class","hide");
			},time)
		}
	}



})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址