替代役
Background.js
ContentScript.js
access all chrome api
can't access Web DOM
access limited chrome api
access Web DOM
message
<img /> Real DOM
this.status.title
this.status.menuitems
flux
flux
onscroll event
getElementInView
Set img src from data attribute
Update React state through Flux
Set img style minHeight and width
var view = {
t: 0,
b: window.innerHeight
};
var inView = function (element, view) {
if (isHidden(element)) {
return false;
}
var box = element.getBoundingClientRect();
return (box.bottom >= view.t && box.top <= view.b);
};
var nodes = document.querySelectorAll('img[data-echo]);
for (var i = 0; i < nodes.length; i++) {
elem = nodes[i];
if (inView(elem, view)) { ...
var bSeachElem=function(nodes,begin,end){
if(begin===end) return index;
var index=Math.floor((begin+end)/2);
var box=nodes[index].getBoundingClientRect();
if(box.bottom<windowView.t){
return bSeachElem(nodes,index,end);
}else if(box.top>windowView.b){
return bSeachElem(nodes,begin,index);
}else if(box.bottom >= View.t && box.top <= View.b){
return index;
}
};
<img /> Real DOM
this.status.title
this.status.menuitems
flux
flux
Chrome Web Store: Comics Scroller
Firefox addon: http://tinyurl.com/ComicsScrolller