Get URLs with properties instead of getAttribute

This commit is contained in:
Deathamns 2015-02-10 18:22:17 +01:00
parent 2d507b3edc
commit b3a2c9c5d3

View file

@ -137,7 +137,6 @@ var svgOcean = null;
var svgIslands = null; var svgIslands = null;
var dialog = null; var dialog = null;
var taCandidate = null; var taCandidate = null;
var urlNormalizer = null;
var netFilterCandidates = []; var netFilterCandidates = [];
var cosmeticFilterCandidates = []; var cosmeticFilterCandidates = [];
@ -246,8 +245,8 @@ var netFilterFromElement = function(elem, out) {
if ( netFilterSources.hasOwnProperty(tagName) === false ) { if ( netFilterSources.hasOwnProperty(tagName) === false ) {
return; return;
} }
var src = elem.getAttribute(netFilterSources[tagName]); var src = elem[netFilterSources[tagName]];
if ( typeof src !== 'string' || src.length === 0 ) { if ( src.length === 0 ) {
return; return;
} }
// Remove fragment // Remove fragment
@ -255,10 +254,6 @@ var netFilterFromElement = function(elem, out) {
if ( pos !== -1 ) { if ( pos !== -1 ) {
src = src.slice(0, pos); src = src.slice(0, pos);
} }
// Feed the attribute to a link element, then retrieve back: this
// should normalize it.
urlNormalizer.href = src;
src = urlNormalizer.href;
// Anchor absolute filter to hostname // Anchor absolute filter to hostname
src = src.replace(/^https?:\/\//, '||'); src = src.replace(/^https?:\/\//, '||');
out.push(src); out.push(src);
@ -417,11 +412,7 @@ var elementsFromFilter = function(filter) {
while ( i-- ) { while ( i-- ) {
elem = elems[i]; elem = elems[i];
src = elem[netFilterSources[elem.tagName.toLowerCase()]]; src = elem[netFilterSources[elem.tagName.toLowerCase()]];
if ( typeof src !== 'string' ) { if ( src && src.indexOf(filter) !== -1 ) {
continue;
}
if ( src.indexOf(filter) !== -1 ) {
out.push(elem); out.push(elem);
} }
} }
@ -682,8 +673,7 @@ var stopPicker = function() {
pickerRoot = pickerRoot =
dialog = dialog =
svgOcean = svgIslands = svgOcean = svgIslands =
taCandidate = taCandidate = null;
urlNormalizer = null;
localMessager.close(); localMessager.close();
window.focus(); window.focus();
@ -722,8 +712,6 @@ var startPicker = function(details) {
svgIslands = svgRoot.lastChild; svgIslands = svgRoot.lastChild;
svgListening(true); svgListening(true);
urlNormalizer = document.createElement('a');
window.addEventListener('scroll', onScrolled, true); window.addEventListener('scroll', onScrolled, true);
pickerRoot.contentWindow.addEventListener('keydown', onKeyPressed, true); pickerRoot.contentWindow.addEventListener('keydown', onKeyPressed, true);
pickerRoot.contentWindow.focus(); pickerRoot.contentWindow.focus();