11
22/**
33 * AdGuard Scriptlets
4- * Version 1.3.23
4+ * Version 1.4.0
55 */
66
77/**
@@ -1721,6 +1721,10 @@ abortOnPropertyWrite.injections = [randomId, setPropertyAccess, getPropertyInCha
17211721/* eslint-enable max-len */
17221722
17231723function preventSetTimeout ( source , match , delay ) {
1724+ // if browser does not support Proxy (e.g. Internet Explorer),
1725+ // we use none-proxy "legacy" wrapper for preventing
1726+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
1727+ var isProxySupported = typeof Proxy !== 'undefined' ;
17241728 var nativeTimeout = window . setTimeout ;
17251729 var log = console . log . bind ( console ) ; // eslint-disable-line no-console
17261730 // logs setTimeouts to console if no arguments have been specified
@@ -1735,20 +1739,30 @@ function preventSetTimeout(source, match, delay) {
17351739 isInvertedDelayMatch = _parseDelayArg . isInvertedDelayMatch ,
17361740 delayMatch = _parseDelayArg . delayMatch ;
17371741
1738- var timeoutWrapper = function timeoutWrapper ( callback , timeout ) {
1742+ var getShouldPrevent = function getShouldPrevent ( callbackStr , timeout ) {
1743+ var shouldPrevent = false ;
1744+
1745+ if ( ! delayMatch ) {
1746+ shouldPrevent = matchRegexp . test ( callbackStr ) !== isInvertedMatch ;
1747+ } else if ( ! match ) {
1748+ shouldPrevent = timeout === delayMatch !== isInvertedDelayMatch ;
1749+ } else {
1750+ shouldPrevent = matchRegexp . test ( callbackStr ) !== isInvertedMatch && timeout === delayMatch !== isInvertedDelayMatch ;
1751+ }
1752+
1753+ return shouldPrevent ;
1754+ } ;
1755+
1756+ var legacyTimeoutWrapper = function legacyTimeoutWrapper ( callback , timeout ) {
17391757 var shouldPrevent = false ; // https://github.com/AdguardTeam/Scriptlets/issues/105
17401758
17411759 var cbString = String ( callback ) ;
17421760
17431761 if ( shouldLog ) {
17441762 hit ( source ) ;
17451763 log ( "setTimeout(" . concat ( cbString , ", " ) . concat ( timeout , ")" ) ) ;
1746- } else if ( ! delayMatch ) {
1747- shouldPrevent = matchRegexp . test ( cbString ) !== isInvertedMatch ;
1748- } else if ( ! match ) {
1749- shouldPrevent = timeout === delayMatch !== isInvertedDelayMatch ;
17501764 } else {
1751- shouldPrevent = matchRegexp . test ( cbString ) !== isInvertedMatch && timeout === delayMatch !== isInvertedDelayMatch ;
1765+ shouldPrevent = getShouldPrevent ( cbString , timeout ) ;
17521766 }
17531767
17541768 if ( shouldPrevent ) {
@@ -1763,7 +1777,32 @@ function preventSetTimeout(source, match, delay) {
17631777 return nativeTimeout . apply ( window , [ callback , timeout ] . concat ( args ) ) ;
17641778 } ;
17651779
1766- window . setTimeout = timeoutWrapper ;
1780+ var handlerWrapper = function handlerWrapper ( target , thisArg , args ) {
1781+ var callback = args [ 0 ] ;
1782+ var timeout = args [ 1 ] ;
1783+ var shouldPrevent = false ; // https://github.com/AdguardTeam/Scriptlets/issues/105
1784+
1785+ var cbString = String ( callback ) ;
1786+
1787+ if ( shouldLog ) {
1788+ hit ( source ) ;
1789+ log ( "setTimeout(" . concat ( cbString , ", " ) . concat ( timeout , ")" ) ) ;
1790+ } else {
1791+ shouldPrevent = getShouldPrevent ( cbString , timeout ) ;
1792+ }
1793+
1794+ if ( shouldPrevent ) {
1795+ hit ( source ) ;
1796+ args [ 0 ] = noopFunc ;
1797+ }
1798+
1799+ return target . apply ( thisArg , args ) ;
1800+ } ;
1801+
1802+ var setTimeoutHandler = {
1803+ apply : handlerWrapper
1804+ } ;
1805+ window . setTimeout = isProxySupported ? new Proxy ( window . setTimeout , setTimeoutHandler ) : legacyTimeoutWrapper ;
17671806}
17681807preventSetTimeout . names = [ 'prevent-setTimeout' , // aliases are needed for matching the related scriptlet converted into our syntax
17691808'no-setTimeout-if.js' , // new implementation of setTimeout-defuser.js
@@ -1880,6 +1919,10 @@ preventSetTimeout.injections = [hit, noopFunc, parseMatchArg, parseDelayArg, toR
18801919/* eslint-enable max-len */
18811920
18821921function preventSetInterval ( source , match , delay ) {
1922+ // if browser does not support Proxy (e.g. Internet Explorer),
1923+ // we use none-proxy "legacy" wrapper for preventing
1924+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
1925+ var isProxySupported = typeof Proxy !== 'undefined' ;
18831926 var nativeInterval = window . setInterval ;
18841927 var log = console . log . bind ( console ) ; // eslint-disable-line no-console
18851928 // logs setIntervals to console if no arguments have been specified
@@ -1894,20 +1937,30 @@ function preventSetInterval(source, match, delay) {
18941937 isInvertedDelayMatch = _parseDelayArg . isInvertedDelayMatch ,
18951938 delayMatch = _parseDelayArg . delayMatch ;
18961939
1897- var intervalWrapper = function intervalWrapper ( callback , interval ) {
1940+ var getShouldPrevent = function getShouldPrevent ( callbackStr , interval ) {
1941+ var shouldPrevent = false ;
1942+
1943+ if ( ! delayMatch ) {
1944+ shouldPrevent = matchRegexp . test ( callbackStr ) !== isInvertedMatch ;
1945+ } else if ( ! match ) {
1946+ shouldPrevent = interval === delayMatch !== isInvertedDelayMatch ;
1947+ } else {
1948+ shouldPrevent = matchRegexp . test ( callbackStr ) !== isInvertedMatch && interval === delayMatch !== isInvertedDelayMatch ;
1949+ }
1950+
1951+ return shouldPrevent ;
1952+ } ;
1953+
1954+ var legachyIntervalWrapper = function legachyIntervalWrapper ( callback , interval ) {
18981955 var shouldPrevent = false ; // https://github.com/AdguardTeam/Scriptlets/issues/105
18991956
19001957 var cbString = String ( callback ) ;
19011958
19021959 if ( shouldLog ) {
19031960 hit ( source ) ;
19041961 log ( "setInterval(" . concat ( cbString , ", " ) . concat ( interval , ")" ) ) ;
1905- } else if ( ! delayMatch ) {
1906- shouldPrevent = matchRegexp . test ( cbString ) !== isInvertedMatch ;
1907- } else if ( ! match ) {
1908- shouldPrevent = interval === delayMatch !== isInvertedDelayMatch ;
19091962 } else {
1910- shouldPrevent = matchRegexp . test ( cbString ) !== isInvertedMatch && interval === delayMatch !== isInvertedDelayMatch ;
1963+ shouldPrevent = getShouldPrevent ( cbString , interval ) ;
19111964 }
19121965
19131966 if ( shouldPrevent ) {
@@ -1922,7 +1975,32 @@ function preventSetInterval(source, match, delay) {
19221975 return nativeInterval . apply ( window , [ callback , interval ] . concat ( args ) ) ;
19231976 } ;
19241977
1925- window . setInterval = intervalWrapper ;
1978+ var handlerWrapper = function handlerWrapper ( target , thisArg , args ) {
1979+ var callback = args [ 0 ] ;
1980+ var interval = args [ 1 ] ;
1981+ var shouldPrevent = false ; // https://github.com/AdguardTeam/Scriptlets/issues/105
1982+
1983+ var cbString = String ( callback ) ;
1984+
1985+ if ( shouldLog ) {
1986+ hit ( source ) ;
1987+ log ( "setTimeout(" . concat ( cbString , ", " ) . concat ( interval , ")" ) ) ;
1988+ } else {
1989+ shouldPrevent = getShouldPrevent ( cbString , interval ) ;
1990+ }
1991+
1992+ if ( shouldPrevent ) {
1993+ hit ( source ) ;
1994+ args [ 0 ] = noopFunc ;
1995+ }
1996+
1997+ return target . apply ( thisArg , args ) ;
1998+ } ;
1999+
2000+ var setIntervalHandler = {
2001+ apply : handlerWrapper
2002+ } ;
2003+ window . setInterval = isProxySupported ? new Proxy ( window . setInterval , setIntervalHandler ) : legachyIntervalWrapper ;
19262004}
19272005preventSetInterval . names = [ 'prevent-setInterval' , // aliases are needed for matching the related scriptlet converted into our syntax
19282006'no-setInterval-if.js' , // new implementation of setInterval-defuser.js
0 commit comments