/******************************************************************************* ηMatrix - a browser extension to black/white list requests. Copyright (C) 2014-2019 Raymond Hill Copyright (C) 2019-2022 Alessio Vanni This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see {http://www.gnu.org/licenses/}. Home: https://gitlab.com/vannilla/ematrix uMatrix Home: https://github.com/gorhill/uBlock */ /* global DOMTokenList */ /* exported uDom */ 'use strict'; // It's just a silly, minimalist DOM framework: this allows me to not rely // on jQuery. jQuery contains way too much stuff than I need, and as per // Opera rules, I am not allowed to use a cut-down version of jQuery. So // the code here does *only* what I need, and nothing more, and with a lot // of assumption on passed parameters, etc. I grow it on a per-need-basis only. // ηMatrix: well, we are not bound by these rules, but not being // reliant on jQuery is not a bad thing. var uDom = (function () { let DOMList = function () { this.nodes = []; }; Object.defineProperty(DOMList.prototype, 'length', { get: function() { return this.nodes.length; } }); let DOMListFactory = function (selector, context) { let r = new DOMList(); if (typeof selector === 'string') { selector = selector.trim(); if (selector !== '') { return addSelectorToList(r, selector, context); } } if (selector instanceof Node) { return addNodeToList(r, selector); } if (selector instanceof NodeList) { return addNodeListToList(r, selector); } if (selector instanceof DOMList) { return addListToList(r, selector); } return r; }; DOMListFactory.onLoad = function (callback) { window.addEventListener('load', callback); }; DOMListFactory.nodeFromId = function (id) { return document.getElementById(id); }; DOMListFactory.nodeFromSelector = function (selector) { return document.querySelector(selector); }; let addNodeToList = function (list, node) { if (node) { list.nodes.push(node); } return list; }; let addNodeListToList = function (list, nodelist) { if (nodelist) { let n = nodelist.length; for (let i=0; i ' + selector); let i = nl.length; while (doesMatch === false && i--) { doesMatch = nl[i] === node; } parentNode.removeAttribute('uDom-32kXc6xEZA7o73AMB8vLbLct1RZOkeoO'); return doesMatch; }; DOMList.prototype.nodeAt = function (i) { return this.nodes[i] || null; }; DOMList.prototype.at = function (i) { return addNodeToList(new DOMList(), this.nodes[i]); }; DOMList.prototype.toArray = function () { return this.nodes.slice(); }; DOMList.prototype.pop = function () { return addNodeToList(new DOMList(), this.nodes.pop()); }; DOMList.prototype.forEach = function (fn) { let n = this.nodes.length; for (let i=0; i