Comments (5)
there is a some sort of hack, multiple images can be inverted by selecting and inverting a parent element of the images on the page
from invertimage.
not working on the sample page
when i right-click on a whole paragraph and run "invert images"
then images are inverted, but also all the text is inverted
screenshot:
i expect the "invert images" plugin to only invert images, not invert all html tags
or did i miss something?
from invertimage.
yes, this is unique style on unique site.
For this purpose Stylus addon can be used. For example: after inverting a parent element on the page I turned on style written in Stylus
#bookchapter {
color: #220;
}
from invertimage.
same effect with only stylus addon:
@-moz-document url-prefix("https://www.dsprelated.com/freebooks/mdft/") {
div#bookchapter img {
filter: invert(1);
-webkit-filter: invert(1);
background: #fff;
}
}
but i still want a "point and click" solution ....
i did a quick edit of your code, to optimize for speed and readability, and to "only invert images"
code is not tested, feel free to use it = no warranty + public domain
// target node from "context menu" click
var clicked_node = null // not a dictionary
// css code to invert image
// we use the css comments /*[*/..../*]*/ for more uniqueness
// so we dont accidentaly replace any original css code
// at the cost of a slower s.indexOf(invert_style)
const invert_style = "/*[*/;filter:invert(1);/*]*/"
browser.runtime.onMessage.addListener(function(msg){
if (msg.cmd !== "invert") return
// css selectors for ancestor node
// TODO sort by frequency, most frequent first
// TODO maybe remove to avoid "magic numbers"
const invert_ancestors = [
".media-image",
"#AdaptiveMedia"
".css-1dbjc4n",
".rn-156q2ks",
".rn-16y2uox",
".rn-10m9thr",
"._26ii _-_b",
"._2a2q",
"._2rea",
"._5rgt",
"._5dec",
".uiScaledImageContainer",
".tcu-imageWrapper",
"._5rgu",
"._3x-2",
]
// search ancestor node
var ancestor_node = null // not a list
for(let s of invert_ancestors){
ancestor_node = clicked_node.closest(s)
if(ancestor_node){
toggle_invert(ancestor_node)
return
}
}
// ancestor node was not found
// invert images in clicked node
for(let i of clicked_node.getElementsByTagName("img")){
toggle_invert(i)
}
//// ancestor node was not found
//// invert clicked node
//toggle_invert(clicked_node)
})
function toggle_invert(e){
var s = e.getAttribute("style")
var i = -1
if(!s){
// set style
s = invert_style
}else{
i = s.indexOf(invert_style)
if(i == -1){
// append style
s = s + invert_style
}else{
// delete style
// re-use the result of s.indexOf(invert_style)
s = s.substr(0, i) + s.substr(i + invert_style.length)
}
}
e.setAttribute("style", s)
}
addEventListener('contextmenu', function (e) {
clicked_node = e.target
}, false)
from invertimage.
Thanks for advice. This addon made for very general case in mind, to work with all type of web pages and elements. Even common case to invert video element or whole pdf document.
from invertimage.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invertimage.