javascript - 如何将两个小书签合二为一来切换亮度?

标签 javascript html css bookmarklet

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

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:亮度("+b+"%)}"})})(文件,100)

更新:

javascript:(函数(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+"%)}"})(文档, “书签亮度”)

关于javascript - 如何将两个小书签合二为一来切换亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52480311/

相关文章:

javascript - 根据背景图像更改文本颜色

css - 在 IE 选项中添加 css 样式

javascript - 删除 Google map 圆形/形状

javascript - 如何保证出站消息的顺序

html - 绝对位置,使右列高度与左列相同

html - 从 <ul> 中删除列表元素符号

javascript - 正则表达式在 github 身份验证 URL 中屏蔽 GITHUB_ACCESS_TOKEN

javascript - jquery removeClass 似乎不起作用

html - 如何在 bootstrap 4 中使我的 table 高度变小?

html - 为什么我的字体颜色设置不起作用?