|
| 1 | +/******************************************************************************* |
| 2 | +
|
| 3 | + uBlock Origin - a comprehensive, efficient content blocker |
| 4 | + Copyright (C) 2019-present Raymond Hill |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see {http://www.gnu.org/licenses/}. |
| 18 | +
|
| 19 | + Home: https://github.com/gorhill/uBlock |
| 20 | +
|
| 21 | +*/ |
| 22 | + |
| 23 | +import { proxyApplyFn } from './proxy-apply.js'; |
| 24 | +import { registerScriptlet } from './base.js'; |
| 25 | +import { safeSelf } from './safe-self.js'; |
| 26 | + |
| 27 | +/******************************************************************************/ |
| 28 | + |
| 29 | +function noEvalIf( |
| 30 | + needle = '' |
| 31 | +) { |
| 32 | + if ( typeof needle !== 'string' ) { return; } |
| 33 | + const safe = safeSelf(); |
| 34 | + const logPrefix = safe.makeLogPrefix('noeval-if', needle); |
| 35 | + const reNeedle = safe.patternToRegex(needle); |
| 36 | + proxyApplyFn('eval', function(context) { |
| 37 | + const { callArgs } = context; |
| 38 | + const a = String(callArgs[0]); |
| 39 | + if ( needle !== '' && reNeedle.test(a) ) { |
| 40 | + safe.uboLog(logPrefix, 'Prevented:\n', a); |
| 41 | + return; |
| 42 | + } |
| 43 | + if ( needle === '' || safe.logLevel > 1 ) { |
| 44 | + safe.uboLog(logPrefix, 'Not prevented:\n', a); |
| 45 | + } |
| 46 | + return context.reflect(); |
| 47 | + }); |
| 48 | +} |
| 49 | +registerScriptlet(noEvalIf, { |
| 50 | + name: 'noeval-if.js', |
| 51 | + aliases: [ |
| 52 | + 'prevent-eval-if.js', |
| 53 | + ], |
| 54 | + dependencies: [ |
| 55 | + proxyApplyFn, |
| 56 | + safeSelf, |
| 57 | + ], |
| 58 | +}); |
0 commit comments