-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullscreen-detector.js
66 lines (57 loc) · 1.72 KB
/
fullscreen-detector.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
/*
Scratch Fullscreen Detector
Created by: Nathan Piercy (nathanprocks)
*/
(function(ext) {
// Cleanup function when the extension is unloaded
ext._shutdown = function() {
document.body.removeEventListener('mousedown', checkFullscreen);
};
// Status reporting code
// Use this to report missing hardware, plugin or unsupported browser
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
var fullscreen = false;
var efsLeft;
var efsTop;
var S = Scratch.FlashApp.ASobj; // Scratch SWF object
ext.isFullscreen = function() {
return fullscreen;
};
function checkFullscreen(e) {
updateFullscreenButtonPosition();
if (fullscreen) {
var magicPixel = (S.clientWidth/4+2 > (S.clientHeight-39)/3) ? 1 : 0; // Not so magic :/
if (e.clientX >= efsLeft && e.clientX <= (efsLeft + 25 + magicPixel) &&
e.clientY >= efsTop && e.clientY <= (efsTop + 19)) {
fullscreen = false;
}
} else {
if (e.clientX >= 17 && e.clientX <= 41 &&
e.clientY >= 42 && e.clientY <= 61) {
fullscreen = true;
}
}
}
function updateFullscreenButtonPosition(e) {
if (S.clientWidth/4+2 > (S.clientHeight-39)/3) {
efsLeft = (S.clientWidth - ((S.clientHeight - 39) * 4/3)) / 2 + 23;
efsLeft += (S.clientWidth + 1) % 2; // This works. Don't touch or it might break :P
efsTop = 18;
} else {
efsLeft = 20;
efsTop = (S.clientHeight - ((S.clientWidth + 37) * 3/4)) / 2 + 9;
}
}
updateFullscreenButtonPosition();
document.body.addEventListener('mousedown', checkFullscreen);
// Block and block menu descriptions
var descriptor = {
blocks: [
['b', 'is fullscreen?', 'isFullscreen']
]
};
// Register the extension
ScratchExtensions.register('Fullscreen Detector', descriptor, ext);
})({});