-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadertoy_fps_mode.user.js
105 lines (95 loc) · 3.8 KB
/
shadertoy_fps_mode.user.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
// ==UserScript==
// @name Shadertoy FPS mode
// @namespace http://tampermonkey.net/
// @version 0.5.20190605
// @description Less restrictive mouse input with new, switchable FPS mode
// @author Andrei Drexler
// @match https://www.shadertoy.com/view/*
// @match https://www.shadertoy.com/new
// @run-at document-end
// @grant none
// ==/UserScript==
/* global gShaderToy, gThemeName, watchInit:true */
(function() {
'use strict';
const icon_header = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAW";
const icon_on = [
icon_header + "CAYAAADEtGw7AAAAL0lEQVQ4y2NgGAVkgP9QTBRgopUrRg0ewoARS5LCpeY/Dj5W80bDeDRLj2bpYQUAWiwHECGpwrgAAAAASUVORK5CYII=)",
icon_header + "CAYAAADEtGw7AAAAO0lEQVQ4y2NgGAWkgg0bNvzfsGHDf2LVM9HKIaMGD2HAiJ6k0BUEBAQwIsuh87GpHQ3j0Sw9mqWHHQAAtNMYULFAdhIAAAAASUVORK5CYII=)"
];
const icon_off = [
icon_header + "CAYAAADEtGw7AAAAaklEQVQ4y+2UQQrAIAwEt32G/7/mD34ofmF7SS9SjAZLKWTAg8YdMEKA5EsKAAGgAGhntL1YPYSYiJ34XhIVqyPWUfgY1Phwl7P583c/v9KKpfxrrUjxlLg52RYVV0dco6/phxB3DaFkDxerBCFgDNeTOAAAAABJRU5ErkJggg==)",
icon_header + "BAMAAAA2mnEIAAAAD1BMVEUAAACxsbGvr6+wsLCwsLBbYh4HAAAABHRSTlMAGq3tZzAcXQAAADVJREFUGNNjYCAdCJmwGAkAaSYQWwCEIGwBKEZnYwOMQOwCxH8OoKohlv0BitHZ7z6AEOkAAMlDCqSp7BzsAAAAAElFTkSuQmCC)"
];
var playerBar = document.getElementById("playerBar");
var lockStatus = false;
if (playerBar) {
var lockStatusDiv = document.createElement("div");
lockStatusDiv.className = "uiButton";
lockStatusDiv.style = "width:22px;height:22px;top:1px;right:164px;position:absolute;";
var updateStatus = function() {
var theme = (gThemeName == "dark") ? 1 : 0;
if (lockStatus) {
lockStatusDiv.title = "Disable FPS mode";
lockStatusDiv.style.background = icon_off[theme];
} else {
lockStatusDiv.title = "Enable FPS mode";
lockStatusDiv.style.background = icon_on[theme];
}
if (gShaderToy && gShaderToy.mCanvas) {
gShaderToy.mCanvas.focus();
}
};
updateStatus();
lockStatusDiv.onclick = function(ev) {
lockStatus = !lockStatus;
updateStatus();
};
playerBar.appendChild(lockStatusDiv);
}
var oldWatchInit = watchInit;
watchInit = function() {
oldWatchInit();
var canvas = gShaderToy.mCanvas;
var oldOnMouseDown = canvas.onmousedown;
var oldOnMouseUp = canvas.onmouseup;
var oldOnMouseMove = canvas.onmousemove;
var mCurrentX = 0, mCurrentY = 0;
document.addEventListener("pointerlockchange", function() {
if (document.pointerLockElement !== canvas) {
var ev = {
clientX : mCurrentX,
clientY : mCurrentY
};
oldOnMouseUp(ev);
}
}, false);
canvas.onmousedown = function(ev) {
if (document.pointerLockElement === canvas) {
return;
}
mCurrentX = ev.clientX;
mCurrentY = ev.clientY;
if (lockStatus) {
canvas.requestPointerLock();
}
oldOnMouseDown(ev);
}
canvas.onmouseup = function(ev) {
if (document.pointerLockElement !== canvas) {
oldOnMouseUp(ev);
}
}
canvas.onmousemove = function(ev) {
if (document.pointerLockElement === canvas) {
mCurrentX += ev.movementX;
mCurrentY += ev.movementY;
ev = {
clientX : mCurrentX,
clientY : mCurrentY
};
}
oldOnMouseMove(ev);
}
}
})();