Some Improvements on Adblocker
Philipp Hülsdunk
philipp_huelsdunk at yahoo.de
Tue Oct 10 14:42:06 BST 2006
I have made the concept:
QString filterBuffer;
vector <int> foundFilter;
void KHTMLPart::write( const QString &str )
{
if ( str.isNull() )
return;
// BEGIN OF AD FILTER //
/*
Firstly, we will remove all ads found in str
*/
/*TODO
for all filters do
find and replace in str the ad for the filter
*/
/*
Now, we will ad str to our buffer
*/
filterBuffer += str;
/*
In foundFilter we now what filters did match partly an end part of the
last filterBuffer
We will now search and replace with that filters
*/
/*TODO
for all filter with the id in found filter do
find and replace the ad for the filter
*/
/*
Now we will find the filters which match partly an end of filterBuffer
We will store this filters id's in foundFilter
So we will clear found filter
*/
foundFilter.clear();
/*
And search for those filters
*/
/* TODO
for all substrings [i,end) of filterBuffer do
for all filters do
if a filter matches a part of the substring then
add the filter-id to foundFilter
*/
/*
If we have not found such a filter,
filterBuffer is ad free and we will write it to khtml
else, filterBuffer contains a part of an ad at the end of filterBuffer.
So, we have to wait for the next string written to khtmlpart
*/
if ( foundFilter.size() != 0 ) then {
return;
} else {
str = filterBuffer;
filterBuffer = "";
}
// END OF AD FILTER
if(d->m_bFirstData) {
// determine the parse mode
d->m_doc->setParseMode( DocumentImpl::Strict );
d->m_bFirstData = false;
}
khtml::Tokenizer* t = d->m_doc->tokenizer();
if(t)
t->write( str, true );
}
If we call khtmlpart::end() we should search filterBuffer for ads and then
call
if ( !filterBuffer.isNull() ) {
if(d->m_bFirstData) {
// determine the parse mode
d->m_doc->setParseMode( DocumentImpl::Strict );
d->m_bFirstData = false;
}
khtml::Tokenizer* t = d->m_doc->tokenizer();
if(t)
t->write( filterBuffer, true );
}
if we call khtmlpart::begin() we should clear foundFilter ad set filterBuffer
to "".
___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
More information about the kfm-devel
mailing list