Changeset 424
- Timestamp:
- 06/28/08 14:56:23 (2 months ago)
- Files:
-
- extension/kabl/components/nsIKablPolicy.idl (modified) (1 diff, 1 prop)
- extension/kabl/components/nsIKablPolicy.xpt (modified) (1 prop)
- extension/kabl/content/kabl-overlay.js (modified) (1 diff)
- extension/kabl/content/kabl-policy.js (modified) (6 diffs)
- extension/kabl/install.rdf (modified) (1 diff)
- extension/kabl/kabl.rdf (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
extension/kabl/components/nsIKablPolicy.idl
- Property svn:executable deleted
r352 r424 11 11 void openMonitorWindow(in nsIDOMWindow parentWin); 12 12 void closeMonitorWindow(); 13 14 void collapse(in nsIDOMEvent event); 13 15 }; extension/kabl/components/nsIKablPolicy.xpt
- Property svn:executable deleted
extension/kabl/content/kabl-overlay.js
r354 r424 57 57 window.removeEventListener('DOMContentLoaded', gKabl.onLoad, false); 58 58 gKabl.setImage(); 59 60 var kablService=Components.classes['@arantius.com/kabl-policy;1'] 61 .createInstance(Components.interfaces.nsIKablPolicy); 62 63 document.getElementById('appcontent') 64 .addEventListener('DOMContentLoaded', kablService.collapse, false); 59 65 } 60 66 }; extension/kabl/content/kabl-policy.js
r354 r424 40 40 } 41 41 }; 42 43 function strippedTextContent(el) { 44 var text=el.innerHTML || el.textContent; 45 if (!text) return ''; 46 47 text=text.replace(/[\s]+/g, ' '); //collapse whitespace 48 text=text.replace(/^\s+|\s+$/g, ''); //strip leading/trailing whitespace 49 text=text.replace(/<script.*?\/script>/gi, ''); //strip js 50 text=text.replace(/<noscript.*?\/noscript>/gi, ''); //strip no-js 51 text=text.replace(/<iframe.*?\/iframe>/gi, ''); // iframe, alternate content 52 text=text.replace(/<!--.*?-->/gi, ''); //strip comments 53 text=text.replace(/<\/?[^>]+>/gi, ''); //strip tags 54 55 return text; 56 } 57 58 const gKablCollapseMarker=String(Math.floor(Math.random()*100000)); 59 const UNORDERED_NODE_SNAPSHOT_TYPE=6; 60 const COLLAPSE_TEXT_LENGTH=25; 42 61 43 62 var gKablPolicy={ … … 121 140 break; 122 141 default: 123 if (gKablDebug ) {142 if (gKablDebug) { 124 143 dump( 125 144 'kabl error condition, unknown origin scheme for\n '+ … … 192 211 fields.node=fields.node 193 212 .QueryInterface(Components.interfaces.nsIDOMNode); 194 fields.node.style.display='none !important'; 213 fields.node.setAttribute('style', 'display: none !important'); 214 } catch (e) { 215 if (gKablDebug) dump('Error in evalScore: '+e+'\n'); 216 } 217 218 // mark a node for extended hiding 219 try { 220 fields.node=fields.node 221 .QueryInterface(Components.interfaces.nsIDOMNode); 222 fields.node.setAttribute('kabl', gKablCollapseMarker); 195 223 } catch (e) { 196 224 if (gKablDebug) dump('Error in evalScore: '+e+'\n'); … … 219 247 }, 220 248 221 // nsIKablPolicy222 249 closeMonitorWindow:function() { 223 250 this.monitorWin.close(); … … 232 259 }, 233 260 234 // nsIContentPolicy interface implementation 261 collapse:function(event) { 262 // called when a content page loads, this looks for elements that were 263 // marked as blocked, and looks for a parent node that should be 264 // collapsed down (because it's probably just a wrapper around the ad) 265 266 var doc=event.target; 267 var xpr=doc.evaluate( 268 '//*[@kabl="'+gKablCollapseMarker+'"]', 269 doc, null, UNORDERED_NODE_SNAPSHOT_TYPE, null 270 ); 271 for (var i=0, item=null; item=xpr.snapshotItem(i); i++) { 272 // Climb the DOM, from this item, to find a container to collapse. 273 var el=null; 274 while (item=item.parentNode) { 275 if (strippedTextContent(item).length>COLLAPSE_TEXT_LENGTH) break; 276 277 el=item; 278 } 279 280 // If we selected an item, collapse it. 281 // try block just in case, attempt to hide the node, i.e. 282 // if a non-loaded image will result in an alt tag showing 283 try { 284 if (el) { 285 el=el.QueryInterface(Components.interfaces.nsIDOMNode); 286 //el.style.display='none !important'; 287 el.setAttribute('style', 'display: none !important'); 288 el.setAttribute('kablcollapse', '1'); 289 } 290 } catch (e) { 291 if (gKablDebug) dump('Error in collapse: '+e+'\n'); 292 } 293 } 294 }, 295 296 // nsIContentPolicy 235 297 shouldLoad:function( 236 298 contentType, contentLocation, requestOrigin, requestingNode, mimeTypeGuess, extra … … 254 316 // if it is chrome, and so is the origin, let it through 255 317 if (contentLocation.schemeIs('chrome') && 256 requestOrigin .schemeIs('chrome')318 requestOrigin && requestOrigin.schemeIs('chrome') 257 319 ) { 258 320 return this.ACCEPT; extension/kabl/install.rdf
r358 r424 4 4 <em:id>kabl@trac.arantius.com</em:id> 5 5 <em:name>Karma Blocker</em:name> 6 <em:version>0. 3</em:version>6 <em:version>0.4</em:version> 7 7 <em:description>Block resources based on their karma.</em:description> 8 8