after the basic layout of the page is created i can put the content of the pages in. for the content of the page displaying the results, a simple
leftFrame.setAttribute('src',document.location.href);
would suffice.
However we would need some way of preventing the script from recursively injecting itself(since the contentscript is injected into all levels, which means a seperate copy is injected into each frame).
this can be done by:
if(parent){
...//main execution part
}
else{
...//seperate handler for when it is in a frame
}
this works because of the weirdness of the scoping with injected javascripts. When injected into a frame, the top level domwindow object is NOT visible to the injected javascript, thus if parent is NOT null, the page must not be in a frame.
the src for the frame on the right is just about:blank, and it carries a unique name that can be the target of the links on the results page, so the results would be displayed on the right.
we can stick all the code that reformats the search results into the if(parent){} clause and not worry about it afterwards.
in order to change the targets of the links on the results page, we would have to have access to the dom objects of that page. the code block from before becomes quite convenient, as we can just stick that in the else{} clause (executes when the page IS in a frame).
to find all the links we would have to invoke the links[] object, and loop through it to find out which ones we modify.

these are the links we want to modify to display in the other frame. by looking through the elements list of the google's webpage, we can see that each div has its unique class. all the classes can be found and made to be the condition to modify.
after we identify the links to modify, we change them by just
links[i].setAttribute("target","targetFrame");
after this point, the extension is pretty much finished. anything more we add on will not be necessary, and so we must consider the trade off between loading speed/memory usage and functionality.
0 comments:
Post a Comment