Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 if ((!selector || target.matches(selector)) && | 484 if ((!selector || target.matches(selector)) && |
485 (!re || re.test(target.textContent))) | 485 (!re || re.test(target.textContent))) |
486 { | 486 { |
487 event.preventDefault(); | 487 event.preventDefault(); |
488 } | 488 } |
489 }, | 489 }, |
490 true); | 490 true); |
491 } | 491 } |
492 | 492 |
493 exports["prevent-inline-scripts"] = preventInlineScripts; | 493 exports["prevent-inline-scripts"] = preventInlineScripts; |
494 | |
495 /** | |
496 * Generates an alphanumeric ID consisting of 5 randomly 6 base-36 digits | |
497 * from the range 100000..zzzzzz (both inclusive) concatenated. | |
498 * | |
499 * @returns {string} The random ID. | |
500 */ | |
501 function randomId() | |
Manish Jethani
2018/10/25 22:22:52
Do you like this version of the function?
I don't
Manish Jethani
2018/10/25 22:59:57
Just to clarify, I'm sorry about leading you down
hub
2018/10/26 15:19:05
Done.
| |
502 { | |
503 let id = ""; | |
504 // | |
505 // 2176782336 is 36^6 which mean 6 chars [a-z0-9] | |
506 // 60466176 is 36^5 | |
507 // 2176782336 - 60466176 = 2116316160. This ensure to always have 6 | |
508 // chars even if Math.random() returns its minimum value 0.0 | |
509 // | |
510 for (let i = 0; i < 5; i++) | |
511 id += Math.floor(Math.random() * 2116316160 + 60466176).toString(36); | |
512 | |
513 return id; | |
514 } | |
515 | |
516 function wrapPropertyAccess(object, property, descriptor) | |
517 { | |
518 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | |
519 if (!currentDescriptor) | |
520 currentDescriptor = {}; | |
521 if (typeof descriptor.get != "undefined") | |
522 currentDescriptor.get = descriptor.get; | |
523 if (typeof descriptor.set != "undefined") | |
524 currentDescriptor.set = descriptor.set; | |
525 Object.defineProperty(object, property, currentDescriptor); | |
526 } | |
527 | |
528 /** | |
529 * Will patch a property on the window object to abort when read. | |
530 * It will intercept the onerror callback and block it if tagged. | |
531 * The idea originates from | |
532 * https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237bfc268ec fc9d9d2b/filters/resources.txt#L1703 | |
533 * | |
534 * @todo handle properties of properties. | |
535 * | |
536 * @param {string} property the name of the property. | |
537 */ | |
538 function abortOnPropertyRead(property) | |
539 { | |
540 if (!property) | |
541 return; | |
542 | |
543 let rid = randomId(); | |
544 | |
545 function abort() | |
546 { | |
547 throw new ReferenceError(rid); | |
548 } | |
549 | |
550 let {onerror} = window; | |
551 window.onerror = (message, ...rest) => | |
552 { | |
553 if (typeof message == "string" && message.includes(rid)) | |
554 return true; | |
555 if (typeof onerror == "function") | |
556 return onerror.call(this, message, ...rest); | |
Manish Jethani
2018/10/25 22:22:52
OK, this one I already explained why there's no gu
hub
2018/10/26 15:19:06
Done.
| |
557 }; | |
558 | |
559 wrapPropertyAccess(window, property, {get: abort, set() {}}); | |
560 } | |
561 | |
562 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | |
563 wrapPropertyAccess, | |
564 randomId); | |
OLD | NEW |