-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompactor_content_script.js
More file actions
30 lines (27 loc) · 948 Bytes
/
Copy pathcompactor_content_script.js
File metadata and controls
30 lines (27 loc) · 948 Bytes
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
function findCompactMenuEntry() {
//document.getElementById(':65');
var tags = document.getElementsByClassName('goog-menuitem-content');
for(var i = 0; i < tags.length; i++) {
if(tags[i].innerText.match("Compact controls") != null) {
console.log('Found menu entry');
return tags[i]
}
}
console.log('Unable to locate menu entry.');
return null;
}
// Make Google Docs default to compact view.
function toggleCompactView() {
var menuEntry = findCompactMenuEntry();
if (menuEntry) {
var mouseDownEvt = document.createEvent('MouseEvent');
var mouseUpEvt = document.createEvent('MouseEvent');
mouseDownEvt.initMouseEvent('mousedown', true, true, window, 1,0,0,0,0);
mouseUpEvt.initMouseEvent('mouseup', true, true, window, 1,0,0,0,0);
// Send the events
menuEntry.dispatchEvent(mouseDownEvt);
menuEntry.dispatchEvent(mouseUpEvt);
}
}
console.log('Compactor script running');
toggleCompactView();