Minor code review

This commit is contained in:
Raymond Hill 2021-10-14 09:22:36 -04:00
parent 1285f78e05
commit aceaea0122
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
4 changed files with 15 additions and 15 deletions

View file

@ -1534,27 +1534,27 @@
/// damoh-defuser.js
(function() {
var handled = new WeakSet();
var asyncTimer;
var cleanVideo = function() {
const handled = new WeakSet();
let asyncTimer;
const cleanVideo = function() {
asyncTimer = undefined;
var v = document.querySelector('video');
const v = document.querySelector('video');
if ( v === null ) { return; }
if ( handled.has(v) ) { return; }
handled.add(v);
v.pause();
v.controls = true;
var el = v.querySelector('meta[itemprop="contentURL"][content]');
let el = v.querySelector('meta[itemprop="contentURL"][content]');
if ( el === null ) { return; }
v.src = el.getAttribute('content');
el = v.querySelector('meta[itemprop="thumbnailUrl"][content]');
if ( el !== null ) { v.poster = el.getAttribute('content'); }
};
var cleanVideoAsync = function() {
const cleanVideoAsync = function() {
if ( asyncTimer !== undefined ) { return; }
asyncTimer = window.requestAnimationFrame(cleanVideo);
};
var observer = new MutationObserver(cleanVideoAsync);
const observer = new MutationObserver(cleanVideoAsync);
observer.observe(document, { childList: true, subtree: true });
})();

View file

@ -473,9 +473,7 @@ vAPI.injectScriptlet = function(doc, text) {
} catch (ex) {
}
if ( script ) {
if ( script.parentNode ) {
script.parentNode.removeChild(script);
}
script.remove();
script.textContent = '';
}
};
@ -1171,11 +1169,11 @@ vAPI.DOMFilterer = class {
// Look-up safe-only selectors to mitigate probability of
// html/body elements of erroneously being targeted.
const ids = [], classes = [];
if (document.documentElement !== null) {
if ( document.documentElement !== null ) {
idFromNode(document.documentElement, ids);
classesFromNode(document.documentElement, classes);
}
if (document.body !== null) {
if ( document.body !== null ) {
idFromNode(document.body, ids);
classesFromNode(document.body, classes);
}

View file

@ -264,7 +264,7 @@ const domLayout = (function() {
continue;
}
// sibling
if (node instanceof Element) {
if ( node instanceof Element ) {
if ( node.nextElementSibling === null ) {
do {
node = stack.pop();
@ -549,7 +549,7 @@ const cosmeticFilterMapper = (function() {
const reset = function() {
roRedNodes.clear();
if (document.documentElement !== null) {
if ( document.documentElement !== null ) {
incremental(document.documentElement);
}
};

View file

@ -74,7 +74,9 @@
}
}
if ( surveyResults.scriptCount === -1 ) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1756
// Mind that there might be no body element.
if ( surveyResults.scriptCount === -1 && document.body !== null ) {
surveyResults.scriptCount = 0;
const onHandlers = new Set([
'onabort', 'onblur', 'oncancel', 'oncanplay',