From ebcafc8db24c17ff1b2cbcee3552ce9bd7a87478 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 3 Apr 2016 08:34:28 -0400 Subject: [PATCH] this fixes #1529: harden element picker styles against external changes --- src/js/scriptlets/element-picker.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/scriptlets/element-picker.js b/src/js/scriptlets/element-picker.js index 1d077c6c3..f02f6f8b6 100644 --- a/src/js/scriptlets/element-picker.js +++ b/src/js/scriptlets/element-picker.js @@ -130,11 +130,11 @@ if ( window.top !== window ) { } var pickerRoot = document.getElementById(vAPI.sessionId); - if ( pickerRoot ) { return; } +var pickerStyle = null; var svgOcean = null; var svgIslands = null; var svgRoot = null; @@ -902,6 +902,7 @@ var stopPicker = function() { dialog.removeEventListener('click', onDialogClicked); svgListening(false); svgRoot.removeEventListener('click', onSvgClicked); + pickerStyle.parentNode.removeChild(pickerStyle); pickerRoot.parentNode.removeChild(pickerRoot); pickerRoot.onload = null; pickerRoot = @@ -1042,6 +1043,13 @@ pickerRoot.style.cssText = [ '' ].join('!important; '); +// https://github.com/gorhill/uBlock/issues/1529 +// In addition to inline styles, harden the element picker styles by using +// a dedicated style tag. +pickerStyle = document.createElement('style'); +pickerStyle.textContent = '#' + pickerRoot.id + ' { ' + pickerRoot.style.cssText + ' }'; +document.documentElement.appendChild(pickerStyle); + pickerRoot.onload = function() { vAPI.shutdown.add(stopPicker); vAPI.messaging.send(