forked from halfdane/rplace
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
133 lines (111 loc) · 4.19 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>/r/2007scape rPlace</title>
<style>
.container {
position: relative;
}
.container > canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<a href="https://raw.githubusercontent.com/MESLewis/rplace/main/images/overlay-script.js">Tamper Monkey overlay</a>
<a href="runelite.html">RuneLite Start Button</a>
<a href="index.html">North West Alliance</a>
<a href="ge.html">Grand Exchange</a>
<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=0
const Y_IN_PLACE=0
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 = "images/combined.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);
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;
let url ="https://new.reddit.com/r/place/?cx="+x+"&cy="+y+"&px=23"
window.open(url, '_blank').focus();
});
</script>
</body>
</html>