// ==UserScript== // @name noPIC 一键隐藏/显示全页面图片(摸鱼必备) // @version 1.8 // @description 隐藏图片和标题 // @author fxalll // @match *://*/* // @grant none // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js // @license MIT // @namespace https://greasyfork.org/users/1043548 // @downloadURL none // ==/UserScript== (function () { let active = false; let currentX; let currentY; let initialX; let initialY; let xOffset = 0; let yOffset = 0; let startTime = 0 window.imgHidenSet = null; window.imgShownSet = null; let imgHiden = function() { $(".RichContent-cover-inner").each(function(){ $(this).hide(); }); $(".ZVideoRecommendationItem-thumbnailImage").each(function(){ $(this).hide(); }); $(".QuestionHeader-title").each(function(){ $(this).hide(); }); $("iframee").each(function(){ $(this).hide(); }); $("img").each(function(){ $(this).hide(); }); }; let imgShown = function() { $(".RichContent-cover-inner").each(function(){ $(this).show(); }); $(".ZVideoRecommendationItem-thumbnailImage").each(function(){ $(this).show(); }); $(".QuestionHeader-title").each(function(){ $(this).show(); }); $("iframee").each(function(){ $(this).show(); }); $("img").each(function(){ $(this).show(); }); }; let handleButtonClick = function(){ if (window.imgHidenSet === null) { clearInterval(window.imgShownSet); window.imgShownSet = null; imgHiden() saveStorageList() window.imgHidenSet = setInterval(function(){ imgHiden(); }, 1000) } else { clearInterval(window.imgHidenSet); window.imgHidenSet = null; imgShown() deleteStorageList() window.imgShownSet = setInterval(function(){ imgShown(); }, 1000) } } let noDetectStorageList = function() { if (localStorage.getItem('nopicValueList') !== null) { let valueList = localStorage.getItem('nopicValueList').split(','); if (valueList.indexOf(location.host) === -1) return true; } else { localStorage.setItem('nopicValueList',['fxalll']) return true; } return false; } let saveStorageList = function() { if (noDetectStorageList()) { let valueList = localStorage.getItem('nopicValueList').split(','); valueList.push(location.host); localStorage.setItem('nopicValueList',valueList) } } let deleteStorageList = function() { if (!noDetectStorageList()) { let valueList = localStorage.getItem('nopicValueList').split(','); valueList = valueList.filter(function(value) { return value !== location.host}); localStorage.setItem('nopicValueList',valueList) } } // 自动隐藏图片 if (!noDetectStorageList()) { imgHiden(); window.imgHidenSet = setInterval(function(){ imgHiden(); }, 300) } let button = document.createElement('div') button.innerText = "◀" button.setAttribute("id", "myButton"); button.style.color = "#0000007d" button.style.padding = "10px 15px" button.style.position = "fixed" button.style.bottom = "20px" button.style.right = "3px" button.style.textAlign = "center" button.style.alignContent = "center" button.style.background = "#7d7d7d33" button.style.borderRadius = "15px" button.style.border = "2px solid #0000007d" button.style.cursor = "pointer" button.style.transform = "translate3d(30%,0,0)" button.style.transition = "1s" button.style.backdropFilter = "saturate(180%) blur(20px)" button.style.zIndex = "99999999999999999999999999999" // 添加鼠标悬停效果 button.addEventListener('mouseover', function() { // 当鼠标悬停在元素上时,改变元素的样式 button.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.5)"; /* 鼠标悬停时的阴影效果 */; button.style.background = "#0000004a" button.style.color = "#ffffff" button.innerText = "图片显隐" button.style.transform = "translateX(0px)" button.style.border = "2px solid #ffffff" setTranslate(0,currentY,button); }); button.addEventListener('mouseout', function() { // 当鼠标离开元素时,恢复元素的样式 button.style.boxShadow = ''; button.style.background = "#7d7d7d33" button.style.color = "#0000007d" button.innerText = "◀" button.style.transform = "translateX(30%)" button.style.border = "2px solid #0000007d" setTranslate(30,currentY,button); }); // 鼠标拖拽 button.addEventListener('mousedown', dragStart, false); //button.addEventListener('mouseup', dragEnd, false); //button.addEventListener('mouseout', dragEnd, false); function dragStart(e) { //记录点击事件,防止拖拽触发点击事件 startTime = e.timeStamp initialX = e.clientX - xOffset; initialY = e.clientY - yOffset; //写外面会导致鼠标一快拖拽就失效了,把拖拽事件写到点击里面,事件处理函数添加到 document 上,而非目标元素上,让 mousemove事件在有延迟的情况下仍然可以被响应 document.addEventListener('mousemove', drag); document.addEventListener('mouseup', dragEnd, false); // 阻止默认事件 e.preventDefault() } function dragEnd(e) { if (startTime) { let diffTime = e.timeStamp - startTime diffTime < 150 && handleButtonClick() //小于150就执行单击操作 startTime = 0 } initialX = currentX; initialY = currentY; button.style.transition = "1s" setTranslate(30, currentY, button); document.removeEventListener('mousemove', drag); } function drag(e) { e.preventDefault(); //currentX = e.clientX - initialX; currentY = e.clientY - initialY; //xOffset = currentX; yOffset = currentY; button.style.transition = "0" setTranslate(0, currentY, button); } function setTranslate(xPos, yPos, el) { el.style.transform = "translate3d(" + xPos + "%, " + yPos + "px, 0)"; //el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)"; } document.body.appendChild(button); })()