mirror of https://github.com/gorhill/uBlock.git
Skip handling non-media elements
This commit is contained in:
parent
163035dc92
commit
b41463d437
|
@ -43,6 +43,12 @@ const largeMediaElementSelector =
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
const isMediaElement = function(elem) {
|
||||||
|
return /^(?:audio|img|picture|video)$/.test(elem.localName);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
const mediaNotLoaded = function(elem) {
|
const mediaNotLoaded = function(elem) {
|
||||||
switch ( elem.localName ) {
|
switch ( elem.localName ) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
|
@ -231,7 +237,9 @@ document.addEventListener('loadeddata', onLoadedData);
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const onLoad = function(ev) {
|
const onLoad = function(ev) {
|
||||||
ev.target.removeAttribute(largeMediaElementAttribute);
|
const elem = ev.target;
|
||||||
|
if ( isMediaElement(elem) === false ) { return; }
|
||||||
|
elem.removeAttribute(largeMediaElementAttribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('load', onLoad, true);
|
document.addEventListener('load', onLoad, true);
|
||||||
|
@ -240,6 +248,7 @@ document.addEventListener('load', onLoad, true);
|
||||||
|
|
||||||
const onLoadError = function(ev) {
|
const onLoadError = function(ev) {
|
||||||
const elem = ev.target;
|
const elem = ev.target;
|
||||||
|
if ( isMediaElement(elem) === false ) { return; }
|
||||||
if ( mediaNotLoaded(elem) ) {
|
if ( mediaNotLoaded(elem) ) {
|
||||||
elem.setAttribute(largeMediaElementAttribute, '');
|
elem.setAttribute(largeMediaElementAttribute, '');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue