首页 > 解决方案 > 如何将两个小书签合二为一来切换亮度?

问题描述

我希望通过单击书签栏中的小书签将这些小书签组合成一个小书签,以切换图像亮度:

javascript:(function(){!function(e) {e.head.appendChild(e.createElement("style"))
  .innerText = ".img,img{-webkit-filter:brightness(50%)}"}(document)})()

和:

javascript:(function(){!function(e) {e.head.appendChild(e.createElement("style"))
  .innerText = ".img,img{-webkit-filter:brightness(100%)}"}(document)})()

我自己尝试过,但我失败了,因为我已经很久没有使用 javascript 了。通过编码或指出正确的方向,我们将不胜感激任何帮助。

谢谢!

标签: javascripthtmlcssbookmarklet

解决方案


它通过按“+”或“-”来工作。核实:

javascript:(function(d,b,s){s=d.head.appendChild(d.createElement("style"));d.addEventListener('keypress',function(e){if (e.key== '+'&&b<100)b+=10;else if(e.key=='-'&&b>0)b-=10;s.innerText = ".img,img{-webkit-filter:brightness("+ b+"%)}"})})(文档,100)

更新:

javascript:(function(d,id,b,s){s=d.getElementById(id);if (!s)d.head.appendChild(s=d.createElement("style")).id=id; b=s.brightness=150-(s.brightness || 100);s.innerText = ".img,img{-webkit-filter:brightness("+b+"%)}"})(document,"bookmarklet-亮度”)


推荐阅读