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

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

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

// ==UserScript==
// @name         百度云重命名剔除特殊符号-输入框版
// @namespace    http://tampermonkey.net/
// @version      0.21
// @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';
	// 创建输入框CSS样式
	const head = document.head;
	const style = document.createElement("style");
	const styleStr =`
	  #removeSpecialSymbolsInput{
	    width:20%;
	    position:absolute;
	    top:103px;
	    left:11%;
	  }
	  .u-input__inner{
	    -webkit-appearance: none;
	    background-color: #fff;
	    background-image: none;
	    border-radius: 4px;
	    border: 1px solid #dcdfe6;
	    box-sizing: border-box;
	    color: #03081a;
	    display: inline-block;
	    font-size: inherit;
	    height: 40px;
	    line-height: 40px;
	    outline: 0;
	    padding: 0 12px;
	    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
	    width: 100%;
	  }
	`
	style.appendChild(document.createTextNode(styleStr));
	head.appendChild(style);

	// 创建input输入框
	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","请输入需要去除特殊符号的文本");

	// 获取要插入的dom
	const fatherDom = document.querySelectorAll('.nd-main-layout__body .wp-s-core-pan__body-contain--list')[0] || document.querySelectorAll("#layoutMain")[0];
	if(document.querySelectorAll("#layoutMain")[0]){
		inputDom.setAttribute("style","top:79px;z-index:999;");
	}
	if(!fatherDom){
		return;
	}
	fatherDom.appendChild(inputDom);

	// 顶部通知类实例
	let showMsg = null;
	// 是否已经触发粘贴事件
	let hasPaste = false;

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

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

			type==="paste"&&(hasPaste = true);
		});

	}

	// 监听粘贴事件
	inputDom.addEventListener('paste', (event) => {
		createClipboardFuc("paste");
	})

	inputDom.onchange = function(e){
		if(hasPaste){
			hasPaste= false;
			return;
		}
		let value = e.target.value;
		createClipboardFuc("onchange",value);
	}

	// 创建顶部通知类
	class ShowMsg{
		constructor(){
			this.createClassFuc();
		}
		createClassFuc(){
			const head = document.head;
			let style = document.createElement("style");
			const styleStr =`
					#toastBox{
					  min-width: auto;
					  height: 40px;
					  background:#fff;
					  box-sizing: border-box;
					  border-radius: 22px;
					  position: fixed;
					  left: 50%;
					  top: -100px;
					  transform: translateX(-50%);
					  transition: opacity .3s,transform .4s,top .4s;
					  overflow: hidden;
					  padding: 10px 20px;
					  display: flex;
					  align-items: center;
					  box-shadow: 0 2px 16px 0 rgb(3 11 26 / 10%);
					  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: 15px;
				     height: 15px;
				     background: #0bd6a7;
				     border-radius: 50%;
				     position: relative;
				     translate: -8px -0.5px;
				   }
				   #toastBox i:before{
				     content: "";
				     width: 8px;
				     height: 3px;
				     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: 3px;
				     top: 5px;
				   }
				   #toastBox p{
				     padding: 0;
				     font-size: 14px;
				     line-height: 1;
				   }
				`
			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或关注我们的公众号极客氢云获取最新地址