// ==UserScript== // @name 度盘文件列表、分享页面显示MD5 // @author Crab // @namespace pan@baidu.com // @description 百度网盘文件列表、分享页面显示分享文件的MD5值。 // @include /^https?://(yun|pan)\.baidu\.com\/(s(hare)?|disk)\/*/ // @compatible firefox 34+ // @compatible Chrome 45+ // @version 0.3.1 // @grant none // @downloadURL none // ==/UserScript== (function(){ 'use strict'; const {cache, yunData} = window; //单文件分享页MD5 if(yunData && yunData.FILEINFO && yunData.FILEINFO.length === 1 && yunData.FILEINFO[0].isdir !== 1 && yunData.FILEINFO[0].md5 ){ let fTitle = document.querySelector('h2.file-name'); if(fTitle){ fTitle.parentNode.insertAdjacentHTML('beforeend', `
MD5:
${yunData.FILEINFO[0].md5}
`); } } //文件列表MD5 if(!cache || Object.keys(cache).length < 1){ return; } document.head.appendChild(document.createElement('style')).textContent = ` @keyframes bdFileMd5 {from{opacity:.9}to{opacity:1}} :not(.dir-small):not(.dir-large) + .file-name .text>a:not([data-md5]){animation:bdFileMd5 1ms} .file-name .text>a[data-md5]{position:relative; top: -6px;} [class*=fileicon] + .file-name .text>a[data-md5]::after, .default-small + .file-name .text>a[data-md5]::after{ content:'MD5: 'attr(data-md5); text-transform: uppercase; position:absolute; left: -80px; top: 2px; font-size: 95%; color: #aaa; } `; let timeout, dir; const getPath = () => { let m = location.hash.match(/^#([^/]+)\/(?:[^\/]+?(?![^\/&]).)?(?:path|type)=([^&\?#]+)/); if(m){ m = Array.from(m, decodeURIComponent); return {list: m[1], path: m[2]}; } return null; }, onAnimationstart = e => { if(e.animationName !== 'bdFileMd5') return; clearTimeout(timeout); timeout = setTimeout(() => {dir = null}, 500); if(!dir){ if(!(dir = getPath())){ return removeEventListener('animationstart', onAnimationstart); } } const {path, list} = dir; if(!cache[list].data[path] || !cache[list].data[path].list) return; const targetName = e.target.textContent, fileInfo = cache[list].data[path].list.find(file => { tempDiv.innerHTML = file.path.split('/').pop(); return tempDiv.textContent === targetName; }); if(fileInfo){ e.target.dataset.md5 = fileInfo.md5; } }, tempDiv = document.createElement('div'); addEventListener('animationstart', onAnimationstart); })();