forked from minj/foxtrick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.js
129 lines (110 loc) · 3.03 KB
/
layout.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* layout.js
* Utilities for Hattrick layout
* @author unknown (NOTE - fill in yourself!)
*/
'use strict';
/* eslint-disable */
if (!this.Foxtrick)
var Foxtrick = {};
/* eslint-enable */
if (!Foxtrick.util)
Foxtrick.util = {};
Foxtrick.util.layout = {};
// Returns whether the HTML document uses standard theme
Foxtrick.util.layout.isStandard = function(doc) {
var head = doc.head;
if (!head)
throw new Error('Not a valid document');
var links = head.querySelectorAll('link');
if (links.length == 0) { // mobile internet may have style embedded
var styles = head.querySelectorAll('style');
for (var style of styles) {
if (/\/App_Themes\/Simple/i.test(style.textContent))
return false;
}
}
else {
for (var link of links) {
if (/\/App_Themes\/Simple/i.test(link.href))
return false;
}
}
return true;
};
// Returns whether the HTML document uses right-to-left language
Foxtrick.util.layout.isRtl = function(doc) {
var head = doc.head;
if (!head)
throw new Error('Not a valid document');
var links = head.querySelectorAll('link');
if (links.length == 0) { // mobile internet may have style embedded
var styles = head.querySelectorAll('style');
for (var style of styles) {
if (/direction:rtl/i.test(style.textContent))
return true;
}
}
else {
for (var link of links) {
if (/_rtl\.css/.test(link.href))
return true;
}
}
return false;
};
// Returns whether the HTML document uses eastern language
Foxtrick.util.layout.isEastern = function(doc) {
var body = doc.body;
if (!body)
throw new Error('Not a valid document');
var style = body.getAttribute('style');
if (style && style.indexOf('font-size:0.79em;') != -1)
return true;
return false;
};
// Returns whether the match order interface is flipped
Foxtrick.util.layout.isFlipped = function(doc) {
var head = doc.head;
if (!head)
throw new Error('Not a valid document');
var links = head.querySelectorAll('link');
if (links.length == 0) { // mobile internet may have style embedded
var styles = head.querySelectorAll('style');
for (var style of styles) {
if (/field_flip.png/i.test(style.textContent))
return true;
}
}
else {
for (var link of links) {
if (/orders_flip.css/i.test(link.href))
return true;
}
}
return false;
};
// Returns whether the user logged in is supporter
Foxtrick.util.layout.isSupporter = function(doc) {
return doc.getElementsByClassName('hattrickNoSupporter').length === 0;
};
// Returns whether scrolling is on for #mainBody
Foxtrick.util.layout.mainBodyHasScroll = function(doc) {
var mainBody = doc.getElementById('mainBody');
if (!mainBody)
return false;
var mainBodyChildren = mainBody.querySelectorAll('script');
for (var child of mainBodyChildren) {
if (child.textContent && /adjustHeight\('mainBody'/.test(child.textContent))
return true;
}
return false;
};
/**
* tests whether user has multiple teams
* @param {document} doc
* @return {boolean}
*/
Foxtrick.util.layout.hasMultipleTeams = function(doc) {
return doc.querySelector('[id*="ucClubSwitcher"i]') != null;
};