Index: include.preload.js |
=================================================================== |
--- a/include.preload.js |
+++ b/include.preload.js |
@@ -30,21 +30,24 @@ |
["audio", "MEDIA"], |
["video", "MEDIA"], |
["frame", "SUBDOCUMENT"], |
["iframe", "SUBDOCUMENT"], |
["object", "OBJECT"], |
["embed", "OBJECT"] |
]); |
-function getURLsFromObjectElement(element) |
+function* getURLsFromObjectElement(element) |
{ |
let url = element.getAttribute("data"); |
if (url) |
- return [url]; |
+ { |
+ yield url; |
+ return; |
+ } |
for (let child of element.children) |
{ |
if (child.localName != "param") |
continue; |
let name = child.getAttribute("name"); |
if (name != "movie" && // Adobe Flash |
@@ -52,85 +55,55 @@ |
name != "src" && // Real Media + Quicktime |
name != "FileName") // Windows Media |
continue; |
let value = child.getAttribute("value"); |
if (!value) |
continue; |
- return [value]; |
+ yield value; |
+ return; |
} |
- |
- return []; |
} |
-function getURLsFromAttributes(element) |
+function* getURLsFromAttributes({src = "", srcset = ""}) |
{ |
- let urls = []; |
- |
- if (element.src) |
- urls.push(element.src); |
+ yield src; |
- if (element.srcset) |
- { |
- for (let candidate of element.srcset.split(",")) |
- { |
- let url = candidate.trim().replace(/\s+\S+$/, ""); |
- if (url) |
- urls.push(url); |
- } |
- } |
- |
- return urls; |
+ for (let candidate of srcset.split(",")) |
+ yield candidate.trim().replace(/\s+\S+$/, ""); |
} |
-function getURLsFromMediaElement(element) |
+function* getURLsFromMediaElement(element) |
{ |
- let urls = getURLsFromAttributes(element); |
+ yield* getURLsFromAttributes(element); |
for (let child of element.children) |
{ |
if (child.localName == "source" || child.localName == "track") |
- urls.push(...getURLsFromAttributes(child)); |
+ yield* getURLsFromAttributes(child); |
} |
- if (element.poster) |
- urls.push(element.poster); |
- |
- return urls; |
+ yield element.poster; |
} |
function getURLsFromElement(element) |
{ |
- let urls; |
- switch (element.localName) |
- { |
- case "object": |
- urls = getURLsFromObjectElement(element); |
- break; |
- |
- case "video": |
- case "audio": |
- case "picture": |
- urls = getURLsFromMediaElement(element); |
- break; |
+ let urls = null; |
+ if (element.localName == "object") |
+ urls = getURLsFromObjectElement(element); |
+ else if (["video", "audio", "picture"].includes(element.localName)) |
+ urls = getURLsFromMediaElement(element); |
+ else |
+ urls = getURLsFromAttributes(element); |
- default: |
- urls = getURLsFromAttributes(element); |
- break; |
- } |
- |
- for (let i = 0; i < urls.length; i++) |
- { |
- if (/^(?!https?:)[\w-]+:/i.test(urls[i])) |
- urls.splice(i--, 1); |
- } |
- |
- return urls; |
+ return Array.from(urls).filter( |
+ url => url && !/^(?!https?:)[\w-]+:/i.test(url) |
+ ); |
} |
function hideElement(element) |
{ |
function doHide() |
{ |
let propertyName = "display"; |
let propertyValue = "none"; |