// ==UserScript== // @name 115一键选择相同 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 115文件去重助手 // @author f5f5 // @match https://115.com/?ct=file* // @icon https://www.google.com/s2/favicons?sz=64&domain=115.com // @grant none // @license GPL // @downloadURL none // ==/UserScript== (function() { 'use strict'; setTimeout(function(){ const el = jQuery('#js-panel_model_switch').next() const styleEl = document.createElement('style') styleEl.innerHTML = ` .check-btn{ border: 1px solid #f60; border-radius: 5px; padding: 0 8px; margin-right: 8px; cursor: pointer; color: #f60; line-height: 30px; display: inline-block; float: left; }` console.warn(el) if(el[0]) { document.head.appendChild(styleEl) var btnSize = $('大小') var btnTitle = $('名字') var btnTime = $('时长') var btnOne = $('(1)') var btnStart = $('开头') el.after(btnStart) el.after(btnOne) el.after(btnTime) el.after(btnTitle) el.after(btnSize) btnSize.on('click', function(){ Array.from(jQuery('.list-contents li')).forEach(el => { let thisStr = $(el).attr('file_size') let thisType = $(el).attr('file_type') let $prev = $(el).prev() if($prev[0]) { let prevStr = $prev.attr('file_size') if(thisType == '0' || !thisStr) return if(thisStr === prevStr) { $prev.find('.checkbox').click() } } }) }) btnTitle.on('click', function(){ Array.from(jQuery('.list-contents li')).forEach(el => { let thisStr = $(el).attr('title') let thisType = $(el).attr('file_type') let $prev = $(el).prev() if($prev[0]) { let prevStr = $prev.attr('title') if(thisType == '0' || !thisStr) return if(thisStr === prevStr) { $prev.find('.checkbox').click() } } }) }) btnTime.on('click', function(){ Array.from(jQuery('.list-contents li')).forEach(el => { let thisStr = $(el).find('.duration').attr('duration') let thisType = $(el).attr('file_type') let $prev = $(el).prev() if($prev[0]) { let prevStr = $prev.find('.duration').attr('duration') if(thisType == '0' || !thisStr) return if(thisStr === prevStr) { $prev.find('.checkbox').click() } } }) }) btnOne.on('click', function(){ Array.from(jQuery('.list-contents li')).forEach(el => { let thisStr = $(el).attr('title') let thisType = $(el).attr('file_type') let str = '' if(thisType === '0') { str = thisStr.slice(thisStr.length-3, thisStr.length) } else { let index = thisStr.lastIndexOf('.') str = thisStr.slice(index-3 ,index) } // if(thisType == '0' || !thisStr) return if(!thisStr) return if(str === '(1)') { $(el).find('.checkbox').click() } }) }) btnStart.on('click', function(){ var len = window.prompt('要匹配前几位数?') len = Number(len) if(!len) return alert('输入不合法') Array.from(jQuery('.list-contents li')).forEach(el => { let thisStr = $(el).attr('title') thisStr = thisStr.slice(0, len) // thisStr = thisStr.replace(/^([a-zA-Z0-9]+-?[0-9]+)(.+)?/i, '$1') let $prev = $(el).prev() if($prev[0]) { let prevStr = $prev.attr('title') if(!thisStr) return try { if(prevStr.match(new RegExp(thisStr,'ig'))) { $prev.find('.checkbox').click() } } catch (error) { console.error(error); } } }) }) } document.addEventListener('keydown', e => { console.log(e.keyCode) if(e.keyCode === 46 || e.keyCode === 8) { try{ document.querySelector('[menu="delete"]').click() }catch(e){console.log(e)} } }) }, 2000) })();