-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
228 lines (206 loc) · 15.8 KB
/
index.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const state = {
xRayOn: false
};
chrome.browserAction.onClicked.addListener(tab => {
state.xRayOn = !state.xRayOn
toggleIcon(state.xRayOn)
chrome.tabs.executeScript({
code: `
(function() {
const prevStyle = document.getElementById('tachyons-x-ray')
const prevMenu = document.getElementById('tachyons-x-ray-menu')
if (prevStyle) {
prevStyle.parentNode.removeChild(prevStyle)
prevMenu.parentNode.removeChild(prevMenu)
} else {
let style = document.createElement('style')
style.id = 'tachyons-x-ray' // So we can toggle the grid by removing it later
document.body.appendChild(style)
style.sheet.insertRule("body { background: transparent url('${ grids.alpha8 }') repeat top left !important; }", style.sheet.cssRules.length)
// Some sites like to use !important liberally, so let's try and win
// this specificity battle with 10 chained ids _and_ !important :)
let id = document.body.id || 'tachyons-x-ray-body'
document.body.id = id // In case there is no id on the body already
let superSpecificHammerTime = ''
for (var i = 0; i < 10; i++) {
superSpecificHammerTime += '#' + id
}
superSpecificHammerTime += ' * { background: transparent !important; color: #444 !important }'
style.sheet.insertRule(superSpecificHammerTime, style.sheet.cssRules.length)
// Create the menu and styles for it
style.sheet.insertRule("#tachyons-x-ray-menu { display: inline-block; position: fixed; top: 16px; right: 16px; width: 32px; height: 32px; font-size: 16px; line-height: 32px; border-radius: 50%; box-shadow: 0 0 16px #666; text-align: center; cursor: pointer; color: #444; z-index: 2147483647; }", style.sheet.cssRules.length)
style.sheet.insertRule("#tachyons-x-ray-menu:hover { box-shadow: 0 0 16px #0074D9; }", style.sheet.cssRules.length)
const menu = document.createElement('button')
menu.appendChild(document.createTextNode('⊞'))
menu.id = 'tachyons-x-ray-menu'
menu.style = 'background-color:#fff !important;outline:none !important;margin:0;border:0;padding:0;display:inline-block;vertical-align:middle;white-space:normal;background:none;line-height:1;'
menu.onclick = toggleOptionsList
document.body.appendChild(menu)
// Create options list and styles for it
const optionsList = document.createElement('ul')
optionsList.style = 'background-color: #fff !important; outline: none !important; margin: 0; list-style-type: none; padding: 0; border-radius: 3px; border: 1px solid #444; font-family: monospace; font-size: 12px; position: fixed; top: 48px; right: 48px; overflow: hidden;'
const options = ['alpha 8', 'solid 8', 'alpha 16', 'solid 16']
options.forEach((opt, idx) => {
const option = document.createElement('li')
option.appendChild(document.createTextNode(opt))
option.style = 'background-color: #fff !important; outline: none !important; padding: 4px 8px; cursor: pointer; line-height: 1; border-bottom: 1px solid #444'
option.onclick = selectGrid(opt.replace(/ /g, ''))
optionsList.appendChild(option)
})
// Create the option to toggle element grid
const option = document.createElement('li')
option.appendChild(document.createTextNode('Toggle Element Grid'))
option.style = 'background-color: #fff !important; outline: none !important; padding: 4px 8px; cursor: pointer; line-height: 1;'
option.onclick = toggleDebugRules
optionsList.appendChild(option)
document.body.appendChild(optionsList)
let debugRules = [
'body { outline: 1px solid !important; }',
'article { outline: 1px solid !important; }',
'nav { outline: 1px solid !important; }',
'aside { outline: 1px solid !important; }',
'section { outline: 1px solid !important; }',
'header { outline: 1px solid !important; }',
'footer { outline: 1px solid !important; }',
'h1 { outline: 1px solid !important; }',
'h2 { outline: 1px solid !important; }',
'h3 { outline: 1px solid !important; }',
'h4 { outline: 1px solid !important; }',
'h5 { outline: 1px solid !important; }',
'h6 { outline: 1px solid !important; }',
'main { outline: 1px solid !important; }',
'address { outline: 1px solid !important; }',
'div { outline: 1px solid !important; }',
'p { outline: 1px solid !important; }',
'hr { outline: 1px solid !important; }',
'pre { outline: 1px solid !important; }',
'blockquote { outline: 1px solid !important; }',
'ol { outline: 1px solid !important; }',
'ul { outline: 1px solid !important; }',
'li { outline: 1px solid !important; }',
'dl { outline: 1px solid !important; }',
'dt { outline: 1px solid !important; }',
'dd { outline: 1px solid !important; }',
'figure { outline: 1px solid !important; }',
'figcaption { outline: 1px solid !important; }',
'table { outline: 1px solid !important; }',
'caption { outline: 1px solid !important; }',
'thead { outline: 1px solid !important; }',
'tbody { outline: 1px solid !important; }',
'tfoot { outline: 1px solid !important; }',
'tr { outline: 1px solid !important; }',
'th { outline: 1px solid !important; }',
'td { outline: 1px solid !important; }',
'col { outline: 1px solid !important; }',
'colgroup { outline: 1px solid !important; }',
'button { outline: 1px solid !important; }',
'datalist { outline: 1px solid !important; }',
'fieldset { outline: 1px solid !important; }',
'form { outline: 1px solid !important; }',
'input { outline: 1px solid !important; }',
'keygen { outline: 1px solid !important; }',
'label { outline: 1px solid !important; }',
'legend { outline: 1px solid !important; }',
'meter { outline: 1px solid !important; }',
'optgroup { outline: 1px solid !important; }',
'option { outline: 1px solid !important; }',
'output { outline: 1px solid !important; }',
'progress { outline: 1px solid !important; }',
'select { outline: 1px solid !important; }',
'textarea { outline: 1px solid !important; }',
'details { outline: 1px solid !important; }',
'summary { outline: 1px solid !important; }',
'command { outline: 1px solid !important; }',
'menu { outline: 1px solid !important; }',
'del { outline: 1px solid !important; }',
'ins { outline: 1px solid !important; }',
'img { outline: 1px solid !important; }',
'iframe { outline: 1px solid !important; }',
'embed { outline: 1px solid !important; }',
'object { outline: 1px solid !important; }',
'param { outline: 1px solid !important; }',
'video { outline: 1px solid !important; }',
'audio { outline: 1px solid !important; }',
'source { outline: 1px solid !important; }',
'canvas { outline: 1px solid !important; }',
'track { outline: 1px solid !important; }',
'map { outline: 1px solid !important; }',
'area { outline: 1px solid !important; }',
'a { outline: 1px solid !important; }',
'em { outline: 1px solid !important; }',
'strong { outline: 1px solid !important; }',
'i { outline: 1px solid !important; }',
'b { outline: 1px solid !important; }',
'u { outline: 1px solid !important; }',
's { outline: 1px solid !important; }',
'small { outline: 1px solid !important; }',
'abbr { outline: 1px solid !important; }',
'q { outline: 1px solid !important; }',
'cite { outline: 1px solid !important; }',
'dfn { outline: 1px solid !important; }',
'sub { outline: 1px solid !important; }',
'sup { outline: 1px solid !important; }',
'time { outline: 1px solid !important; }',
'code { outline: 1px solid !important; }',
'kbd { outline: 1px solid !important; }',
'samp { outline: 1px solid !important; }',
'var { outline: 1px solid !important; }',
'mark { outline: 1px solid !important; }',
'bdi { outline: 1px solid !important; }',
'bdo { outline: 1px solid !important; }',
'ruby { outline: 1px solid !important; }',
'rt { outline: 1px solid !important; }',
'rp { outline: 1px solid !important; }',
'span { outline: 1px solid !important; }',
'br { outline: 1px solid !important; }',
'wbr { outline: 1px solid !important; }'
]
debugRulesVisible = false;
toggleDebugRules()
function toggleDebugRules() {
if (!debugRulesVisible) {
debugRules.forEach(r =>
style.sheet.insertRule(r, style.sheet.cssRules.length))
debugRulesVisible = true
} else {
debugRules.forEach((_, idx) =>
style.sheet.deleteRule(style.sheet.cssRules.length - 1))
debugRulesVisible = false
}
toggleOptionsList()
}
function toggleOptionsList() {
optionsList.style.display = (
optionsList.style.display === 'none' ? 'block' : 'none'
)
}
const grids = ${ JSON.stringify(grids) }
function selectGrid(type) {
return () => {
const background = (
'url("' + grids[type] + '") left top repeat transparent'
)
style.sheet.rules[0].style.background = background
toggleOptionsList()
}
}
}
})()
`
})
})
function toggleIcon(isOn) {
const icon = isOn ? 'icon-on' : 'icon'
chrome.browserAction.setIcon({
path : {
'19': `icons/${ icon }19x.png`,
'38': `icons/${ icon }38x.png`
}
})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