javascript - 如何将两个小书签合二为一来切换亮度?
问题描述
我希望通过单击书签栏中的小书签将这些小书签组合成一个小书签,以切换图像亮度:
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 了。通过编码或指出正确的方向,我们将不胜感激任何帮助。
谢谢!
解决方案
它通过按“+”或“-”来工作。核实:
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-亮度”)
推荐阅读
- javascript - 使用我们从 create-react-app 获得的配置或创建我们自己的自定义 webpack 和 babel 配置并安装 react
- reactjs - 如何让一个地方的纬度和经度反应谷歌地图?
- html - 如何在 HTML 中使用这个特定的选择器
- laravel - 我该如何解决这个错误“函数 App\Http\Controllers\CtnController::show() 的参数太少,通过了 0,预期正好 1”
- python - 如何执行以下操作:加入
- css - 反应原生文本在中间打断单词
- python - 对于每个 NAME,计算每个月的平均 SNOW
- java - Navigation Drawer 不处理点击事件
- google-tag-manager - 在 Google 跟踪代码管理器的事务事件中推送额外的自定义变量
- c# - “并非所有代码路径都返回值”错误发生在方法中,但我确实使用了一些 if 语句来涵盖所有场景