-
Notifications
You must be signed in to change notification settings - Fork 0
/
tv.media.js
60 lines (48 loc) · 1.87 KB
/
tv.media.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function ($) {
var getTvVendorByUserAgent = function (strUserAgent) {
var patterns = {
'loewe': 'link[media*="loewe"]',
'smart;': 'link[media*="smartbox"]',
'videoweb;': 'link[media*="videoweb"]',
'technisat': 'link[media*="technisat"]',
'philips': 'link[media*="philips"]',
'nettv': 'link[media*="philips"]',
'lg netcast': 'link[media*="lgelectronics"]'
};
for (var p in patterns) {
if (strUserAgent.indexOf(p) >= 0) {
return patterns[p];
}
}
return undefined;
};
var getMediasForLoad = function (strUserAgent) {
var arrMediasForLoad = [];
var strMediaVendorSelector = getTvVendorByUserAgent(strUserAgent);
if (strMediaVendorSelector != undefined) {
arrMediasForLoad.push(strMediaVendorSelector);
}
if (strUserAgent.indexOf('opera') >= 0) {
arrMediasForLoad.push('link[media*="opera-tv"]');
return arrMediasForLoad;
}
if (strUserAgent.indexOf('webkit') >= 0) {
arrMediasForLoad.push('link[media*="webkit-tv"]');
return arrMediasForLoad;
}
return arrMediasForLoad;
};
var runPlugin = function () {
headNode = document.getElementsByTagName('head')[0];
var arrMediasForLoad = getMediasForLoad(navigator.userAgent.toLowerCase());
arrMediasForLoad = arrMediasForLoad.join(', ');
var strLogMessage = 'Pseudo medias: ' + arrMediasForLoad;
window.console.log(strLogMessage);
var links = headNode.querySelectorAll(arrMediasForLoad);
for (var i = links.length - 1; i >= 0 ; --i) {
links[i].setAttribute('media', 'screen');
}
};
var headNode;
$(document).ready(runPlugin);
})(jQuery);