@@ -303,7 +303,7 @@ Readability.prototype = {
303
303
304
304
if ( ! this . _keepClasses ) {
305
305
// Remove classes.
306
- this . _cleanClasses ( articleContent ) ;
306
+ this . _cleanElement ( articleContent ) ;
307
307
}
308
308
} ,
309
309
@@ -456,7 +456,7 @@ Readability.prototype = {
456
456
* @param Element
457
457
* @return void
458
458
*/
459
- _cleanClasses : function ( node ) {
459
+ _cleanElement : function ( node ) {
460
460
if ( node . className && node . className . startsWith && node . className . startsWith ( '_omnivore' ) ) {
461
461
return ;
462
462
}
@@ -483,8 +483,10 @@ Readability.prototype = {
483
483
node . removeAttribute ( "class" ) ;
484
484
}
485
485
486
+ this . _removeAllEventHandlers ( node )
487
+
486
488
for ( node = node . firstElementChild ; node ; node = node . nextElementSibling ) {
487
- this . _cleanClasses ( node ) ;
489
+ this . _cleanElement ( node ) ;
488
490
}
489
491
} ,
490
492
@@ -546,7 +548,6 @@ Readability.prototype = {
546
548
this . _forEachNode ( medias , function ( media ) {
547
549
var src = media . getAttribute ( "src" ) ;
548
550
var poster = media . getAttribute ( "poster" ) ;
549
- var srcset = media . getAttribute ( "srcset" ) ;
550
551
551
552
if ( src ) {
552
553
media . setAttribute ( "src" , this . toAbsoluteURI ( src ) ) ;
@@ -558,6 +559,20 @@ Readability.prototype = {
558
559
} ) ;
559
560
} ,
560
561
562
+ // removes all the javascript event handlers from the supplied element
563
+ _removeAllEventHandlers ( element ) {
564
+ const attributes = element . attributes ;
565
+
566
+ // Iterate in reverse because removing attributes changes the length
567
+ for ( let i = attributes . length - 1 ; i >= 0 ; i -- ) {
568
+ const attribute = attributes [ i ] ;
569
+ // Check if the attribute starts with "on" (like "onload", "onerror", etc.)
570
+ if ( attribute . name . startsWith ( 'on' ) ) {
571
+ element . removeAttribute ( attribute . name ) ;
572
+ }
573
+ }
574
+ } ,
575
+
561
576
/** Creates imageproxy links for all article images with href source */
562
577
_createImageProxyLinks : function ( articleContent ) {
563
578
if ( this . createImageProxyUrl !== undefined ) {
0 commit comments