在网页右下角添加一个按钮,可以隐藏和显示页面上的所有img标签
// ==UserScript== // @name 隐藏/显示页面图片 // @name:en hide/display image // @namespace None // @version 1.2 // @description 在网页右下角添加一个按钮,可以隐藏和显示页面上的所有img标签 // @description:en Add a button for all websites which can back to the top and go to the bottom,and there is a sliding effecct. // @author mofiter // @create 2023-06-06 // @lastmodified 2023-06-06 // @include http*://*/* // @license MIT // ==/UserScript== function creatIcon(){ const img = document.createElement("img"); img.src = "https://i.niupic.com/images/2023/06/19/bqao.png"; img.style.position = "fixed"; img.style.width = "45px"; img.style.height = "45px"; img.style.bottom = "60px"; img.style.right = "6vw"; img.style.opacity = "0.5"; img.id="baojin_ovo"; img.title="crtl+alt"; img.addEventListener("click", () => { const images = document.querySelectorAll("img"); const elementToRemove = document.getElementById("baojin_ovo"); images.forEach(image => { image.style.display = "inline"; }); elementToRemove.parentNode.removeChild(elementToRemove); }); document.body.appendChild(img); } const img = document.createElement("img"); img.src = "https://i.niupic.com/images/2023/06/19/bqad.png"; img.style.position = "fixed"; img.style.width = "45px"; img.style.height = "45px"; img.style.bottom = "-60px"; img.style.right = "6vw"; img.style.opacity = "0.5"; img.id="baojin_owo"; img.title="crtl+alt"; img.addEventListener("click", () => { const images = document.querySelectorAll("img"); images.forEach(image => { image.style.display = "none"; }); creatIcon(); }); document.body.appendChild(img); const placeholder = document.getElementById("img-placeholder"); setTimeout(() => { img.style.transition = "transform 1.2s"; img.style.transform = "translateY(-120px)"; // placeholder.remove(); }, 1000); var i = 1; var A = (function() { return function() { if (i%2===0){ const images = document.querySelectorAll("img"); const elementToRemove = document.getElementById("baojin_ovo"); images.forEach(image => { image.style.display = "inline"; }); elementToRemove.parentNode.removeChild(elementToRemove); console.log("on") }else{ const images = document.querySelectorAll("img"); images.forEach(image => { image.style.display = "none"; }); creatIcon(); console.log("off"); } i++; console.log(i) } })(); document.addEventListener('keydown', function(event) { if (event.ctrlKey && event.altKey) { // 判断是否按下ctrl+A A(); // 执行function A() } });