OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 17 matching lines...) Expand all Loading... |
28 ["input", "IMAGE"], | 28 ["input", "IMAGE"], |
29 ["picture", "IMAGE"], | 29 ["picture", "IMAGE"], |
30 ["audio", "MEDIA"], | 30 ["audio", "MEDIA"], |
31 ["video", "MEDIA"], | 31 ["video", "MEDIA"], |
32 ["frame", "SUBDOCUMENT"], | 32 ["frame", "SUBDOCUMENT"], |
33 ["iframe", "SUBDOCUMENT"], | 33 ["iframe", "SUBDOCUMENT"], |
34 ["object", "OBJECT"], | 34 ["object", "OBJECT"], |
35 ["embed", "OBJECT"] | 35 ["embed", "OBJECT"] |
36 ]); | 36 ]); |
37 | 37 |
38 function getURLsFromObjectElement(element) | 38 function* getURLsFromObjectElement(element) |
39 { | 39 { |
40 let url = element.getAttribute("data"); | 40 let url = element.getAttribute("data"); |
41 if (url) | 41 if (url) |
42 return [url]; | 42 { |
| 43 yield url; |
| 44 return; |
| 45 } |
43 | 46 |
44 for (let child of element.children) | 47 for (let child of element.children) |
45 { | 48 { |
46 if (child.localName != "param") | 49 if (child.localName != "param") |
47 continue; | 50 continue; |
48 | 51 |
49 let name = child.getAttribute("name"); | 52 let name = child.getAttribute("name"); |
50 if (name != "movie" && // Adobe Flash | 53 if (name != "movie" && // Adobe Flash |
51 name != "source" && // Silverlight | 54 name != "source" && // Silverlight |
52 name != "src" && // Real Media + Quicktime | 55 name != "src" && // Real Media + Quicktime |
53 name != "FileName") // Windows Media | 56 name != "FileName") // Windows Media |
54 continue; | 57 continue; |
55 | 58 |
56 let value = child.getAttribute("value"); | 59 let value = child.getAttribute("value"); |
57 if (!value) | 60 if (!value) |
58 continue; | 61 continue; |
59 | 62 |
60 return [value]; | 63 yield value; |
| 64 return; |
61 } | 65 } |
62 | |
63 return []; | |
64 } | 66 } |
65 | 67 |
66 function getURLsFromAttributes(element) | 68 function* getURLsFromAttributes({src = "", srcset = ""}) |
67 { | 69 { |
68 let urls = []; | 70 yield src; |
69 | 71 |
70 if (element.src) | 72 for (let candidate of srcset.split(",")) |
71 urls.push(element.src); | 73 yield candidate.trim().replace(/\s+\S+$/, ""); |
72 | |
73 if (element.srcset) | |
74 { | |
75 for (let candidate of element.srcset.split(",")) | |
76 { | |
77 let url = candidate.trim().replace(/\s+\S+$/, ""); | |
78 if (url) | |
79 urls.push(url); | |
80 } | |
81 } | |
82 | |
83 return urls; | |
84 } | 74 } |
85 | 75 |
86 function getURLsFromMediaElement(element) | 76 function* getURLsFromMediaElement(element) |
87 { | 77 { |
88 let urls = getURLsFromAttributes(element); | 78 yield* getURLsFromAttributes(element); |
89 | 79 |
90 for (let child of element.children) | 80 for (let child of element.children) |
91 { | 81 { |
92 if (child.localName == "source" || child.localName == "track") | 82 if (child.localName == "source" || child.localName == "track") |
93 urls.push(...getURLsFromAttributes(child)); | 83 yield* getURLsFromAttributes(child); |
94 } | 84 } |
95 | 85 |
96 if (element.poster) | 86 yield element.poster; |
97 urls.push(element.poster); | |
98 | |
99 return urls; | |
100 } | 87 } |
101 | 88 |
102 function getURLsFromElement(element) | 89 function getURLsFromElement(element) |
103 { | 90 { |
104 let urls; | 91 let urls = null; |
105 switch (element.localName) | 92 if (element.localName == "object") |
106 { | 93 urls = getURLsFromObjectElement(element); |
107 case "object": | 94 else if (["video", "audio", "picture"].includes(element.localName)) |
108 urls = getURLsFromObjectElement(element); | 95 urls = getURLsFromMediaElement(element); |
109 break; | 96 else |
| 97 urls = getURLsFromAttributes(element); |
110 | 98 |
111 case "video": | 99 return Array.from(urls).filter( |
112 case "audio": | 100 url => url && !/^(?!https?:)[\w-]+:/i.test(url) |
113 case "picture": | 101 ); |
114 urls = getURLsFromMediaElement(element); | |
115 break; | |
116 | |
117 default: | |
118 urls = getURLsFromAttributes(element); | |
119 break; | |
120 } | |
121 | |
122 for (let i = 0; i < urls.length; i++) | |
123 { | |
124 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) | |
125 urls.splice(i--, 1); | |
126 } | |
127 | |
128 return urls; | |
129 } | 102 } |
130 | 103 |
131 function hideElement(element) | 104 function hideElement(element) |
132 { | 105 { |
133 function doHide() | 106 function doHide() |
134 { | 107 { |
135 let propertyName = "display"; | 108 let propertyName = "display"; |
136 let propertyValue = "none"; | 109 let propertyValue = "none"; |
137 if (element.localName == "frame") | 110 if (element.localName == "frame") |
138 { | 111 { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 let element = event.target; | 510 let element = event.target; |
538 if (/^i?frame$/.test(element.localName)) | 511 if (/^i?frame$/.test(element.localName)) |
539 checkCollapse(element); | 512 checkCollapse(element); |
540 }, true); | 513 }, true); |
541 } | 514 } |
542 | 515 |
543 window.checkCollapse = checkCollapse; | 516 window.checkCollapse = checkCollapse; |
544 window.elemhide = elemhide; | 517 window.elemhide = elemhide; |
545 window.typeMap = typeMap; | 518 window.typeMap = typeMap; |
546 window.getURLsFromElement = getURLsFromElement; | 519 window.getURLsFromElement = getURLsFromElement; |
OLD | NEW |