-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
160 lines (133 loc) · 5.16 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Superstonk's rPlace</title>
<style>
.container {
position: relative;
}
.container > canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div>
<p>
OVERLAY INSTRUCTIONS
<br />
If you use Chrome:
<a href="https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en">https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en</a>
<br />
If you use Opera:
<a href="https://www.tampermonkey.net/">https://www.tampermonkey.net/</a>
<br />
If you use Firefox:
<a href="https://addons.mozilla.org/en-US/firefox/addon/violentmonkey/">https://addons.mozilla.org/en-US/firefox/addon/violentmonkey/</a>
<br />
To install, click here:<a href="https://rplacesuperstonk.github.io/rplace-image/userscript.user.js">https://rplacesuperstonk.github.io/rplace-image/userscript.user.js</a>
</p>
</div>
<div id = "container" class = "container">
<canvas id = "canvas_background" width = "800" height = "500"></canvas>
<canvas id = "canvas_foreground" width = "800" height = "500"></canvas>
</div>
<script>
const X_PIXELS=23
const Y_PIXELS=23
const X_OFFSET=400
const Y_OFFSET=100
const X_IN_PLACE=773
const Y_IN_PLACE=735
function getMousePos(canvas, evt) {
const rect = canvas.getBoundingClientRect();
return {
x: (evt.clientX - rect.left - 20) / (rect.right - rect.left) * canvas.width,
y: (evt.clientY - rect.top) / (rect.bottom - rect.top) * canvas.height
};
}
function drawGrid(x_0, y_0, x_max, y_max, ctx) {
for (let x = x_0; x <= x_max; x += X_PIXELS) {
ctx.moveTo(x, y_0);
ctx.lineTo(x, y_max);
for (let y = y_0; y <= y_max; y += Y_PIXELS) {
ctx.moveTo(x_0, y);
ctx.lineTo(x_max, y);
}
}
ctx.strokeStyle = '#bbbbbb';
ctx.stroke();
}
const background = document.getElementById("canvas_background");
const bg = background.getContext("2d");
const foreground = document.getElementById("canvas_foreground");
const fg = foreground.getContext("2d");
const img = new Image();
img.onload = function(){
w = img.width * X_PIXELS
h = img.height * Y_PIXELS
bg.canvas.width = w + X_OFFSET;
bg.canvas.height = h + 2*Y_OFFSET;
fg.canvas.width = bg.canvas.width;
fg.canvas.height = bg.canvas.height;
bg.imageSmoothingEnabled = false;
bg.drawImage(img, 0, 0, img.width, img.height, 0, Y_OFFSET, w, h)
drawGrid(0, Y_OFFSET, w, h + Y_OFFSET, bg)
};
img.src = "https://raw.githubusercontent.com/rplacesuperstonk/rplace-image/main/reference.png";
function drawText(text, x, y){
fg.font = '80px Sans-serif';
fg.strokeStyle = 'black';
fg.lineWidth = 8;
fg.strokeText(text, x, y);
fg.fillStyle = 'white';
fg.fillText(text, x, y);
}
foreground.addEventListener('mousemove', event =>
{
let p = getMousePos(foreground, event);
let x = Math.floor((p.x)/X_PIXELS);
let y = Math.floor((p.y-Y_OFFSET)/Y_PIXELS) ;
fg.clearRect(0, 0, fg.canvas.width, fg.canvas.height);
if (y<0){
return;
}
drawText((x+ X_IN_PLACE)+"", p.x+40, p.y - 30)
drawText((y+ Y_IN_PLACE)+"", p.x+40, p.y + 50)
fg.lineWidth = 4;
let circle_x = x*X_PIXELS+X_PIXELS/2;
let circle_y = y*Y_PIXELS+Y_OFFSET+Y_PIXELS/2;
fg.beginPath()
fg.strokeStyle = 'red';
fg.arc(circle_x, circle_y, X_PIXELS-6, 0, 2 * Math.PI, false);
fg.stroke()
fg.beginPath()
fg.strokeStyle = 'white';
fg.arc(circle_x, circle_y, X_PIXELS-4, 0, 2 * Math.PI, false);
fg.stroke()
fg.beginPath()
fg.strokeStyle = 'black';
fg.arc(circle_x, circle_y, X_PIXELS, 0, 2 * Math.PI, false);
fg.stroke()
});
foreground.addEventListener('click', event =>
{
let p = getMousePos(foreground, event);
let x = Math.floor((p.x)/X_PIXELS) + X_IN_PLACE;
let y = Math.floor((p.y-Y_OFFSET)/Y_PIXELS) + Y_IN_PLACE;
if (y<Y_IN_PLACE){
return;
}
let url ="https://new.reddit.com/r/place/?cx="+x+"&cy="+y+"&px=23"
window.open(url, '_blank').focus();
});
setTimeout(() => {
// Reload every 5 minutes to fetch updates from the gh
location.reload();
}, 60000 * 5)
</script>
</body>
</html>