Raymond Hill 2018-08-15 07:58:42 -04:00
parent 76c2682627
commit ed492bc485
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 28 additions and 22 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2018 Raymond Hill Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -1495,8 +1495,8 @@ var stopPicker = function() {
var startPicker = function(details) { var startPicker = function(details) {
pickerRoot.addEventListener('load', stopPicker); pickerRoot.addEventListener('load', stopPicker);
var frameDoc = pickerRoot.contentDocument; let frameDoc = pickerRoot.contentDocument;
var parsedDom = (new DOMParser()).parseFromString( let parsedDom = (new DOMParser()).parseFromString(
details.frameContent, details.frameContent,
'text/html' 'text/html'
); );
@ -1505,6 +1505,17 @@ var startPicker = function(details) {
// picker style properties. // picker style properties.
parsedDom.documentElement.id = 'ublock0-epicker'; parsedDom.documentElement.id = 'ublock0-epicker';
// https://github.com/gorhill/uBlock/issues/2240
// https://github.com/uBlockOrigin/uBlock-issues/issues/170
// Remove the already declared inline style tag: we will create a new
// one based on the removed one, and replace the old one.
let style = parsedDom.querySelector('style');
let styleText = style.textContent;
style.parentNode.removeChild(style);
style = frameDoc.createElement('style');
style.textContent = styleText;
parsedDom.head.appendChild(style);
frameDoc.replaceChild( frameDoc.replaceChild(
frameDoc.adoptNode(parsedDom.documentElement), frameDoc.adoptNode(parsedDom.documentElement),
frameDoc.documentElement frameDoc.documentElement
@ -1533,7 +1544,7 @@ var startPicker = function(details) {
pickerRoot.contentWindow.focus(); pickerRoot.contentWindow.focus();
// Restore net filter union data if it originate from the same URL. // Restore net filter union data if it originate from the same URL.
var eprom = details.eprom || null; let eprom = details.eprom || null;
if ( eprom !== null && eprom.lastNetFilterSession === lastNetFilterSession ) { if ( eprom !== null && eprom.lastNetFilterSession === lastNetFilterSession ) {
lastNetFilterHostname = eprom.lastNetFilterHostname || ''; lastNetFilterHostname = eprom.lastNetFilterHostname || '';
lastNetFilterUnion = eprom.lastNetFilterUnion || ''; lastNetFilterUnion = eprom.lastNetFilterUnion || '';
@ -1552,12 +1563,11 @@ var startPicker = function(details) {
} }
// No mouse position available, use suggested target // No mouse position available, use suggested target
var target = details.target || ''; let target = details.target || '';
var pos = target.indexOf('\t'); let pos = target.indexOf('\t');
if ( pos === -1 ) { if ( pos === -1 ) { return; }
return;
} let srcAttrMap = {
var srcAttrMap = {
'a': 'href', 'a': 'href',
'audio': 'src', 'audio': 'src',
'embed': 'src', 'embed': 'src',
@ -1565,24 +1575,20 @@ var startPicker = function(details) {
'img': 'src', 'img': 'src',
'video': 'src', 'video': 'src',
}; };
var tagName = target.slice(0, pos); let tagName = target.slice(0, pos);
var url = target.slice(pos + 1); let url = target.slice(pos + 1);
var attr = srcAttrMap[tagName]; let attr = srcAttrMap[tagName];
if ( attr === undefined ) { if ( attr === undefined ) {
return; return;
} }
var elems = document.querySelectorAll(tagName + '[' + attr + ']'); let elems = document.querySelectorAll(tagName + '[' + attr + ']');
var i = elems.length; let i = elems.length;
var elem, src; let elem, src;
while ( i-- ) { while ( i-- ) {
elem = elems[i]; elem = elems[i];
src = elem[attr]; src = elem[attr];
if ( typeof src !== 'string' || src === '' ) { if ( typeof src !== 'string' || src === '' ) { continue; }
continue; if ( src !== url ) { continue; }
}
if ( src !== url ) {
continue;
}
elem.scrollIntoView({ elem.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
block: 'start' block: 'start'