-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
102 lines (87 loc) · 3.03 KB
/
main.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
// ==UserScript==
// @name Only Connect cheat
// @namespace https://github.com/gixid192/only-connect-bbc-cheat/
// @version 0.1
// @description Cheat the game
// @author Jimmy
// @match http://www.puzzgrid.com/grid/*
// @grant none
// ==/UserScript==
(function() {
//only connect
// answers //summary answer
// groups //4 rows answer
// stopTheClock(); //no timer
'use strict';
const menu = document.querySelector('#menu');
const beginBtn = document.querySelector('#overlay');
const appendCheatBtn = () => {
const cheatDiv = document.createElement('div');
menu.style.top = '50px';
cheatDiv.style.margin = "20px auto";
menu.appendChild(cheatDiv);
const noTimer = document.createElement('p');
const revealRow = document.createElement('p');
const revealSummary = document.createElement('p');
noTimer.textContent = 'Stop Timer';
noTimer.id = 'noTimer';
revealRow.textContent = 'Reveal Row';
revealRow.id = 'revealRow';
revealSummary.textContent = 'Reveal Summary';
revealSummary.id = 'revealSummary';
const styleBtn = "color: #deadbeef; margin-right: 20px; display: inline-block; font-weight: 600; cursor: pointer";
noTimer.style.cssText = styleBtn;
revealRow.style.cssText = styleBtn;
revealSummary.style.cssText = styleBtn;
cheatDiv.appendChild(noTimer);
cheatDiv.appendChild(revealRow);
cheatDiv.appendChild(revealSummary);
};
const revealRow = () => {
const colors = ["red", "blue", "green", "yellow"];
groups.map( (group,key) => {
group.map(number => {
const elm = document.querySelector('#tile' + number);
elm.style.color = colors[key];
});
});
};
const revealSummary = () => {
const ianswers = answers.map(arr => arr[0]);
groups.map( (group,key) => {
group.map(number => {
const elm = document.querySelector('#tile' + number);
elm.innerHTML = elm.textContent + '<br>' + ianswers[key];
});
});
};
const initListener = () => {
menu.addEventListener('click', function(e){
const target = e.target;
const elID = target.id;
if(target.getAttribute('clicked')){
return;
}
target.setAttribute('clicked',1);
switch (elID){
case "noTimer":
stopTheClock();
break;
case "revealRow":
revealRow();
break;
case "revealSummary":
revealSummary();
break;
default: return;
}
});
};
const waitFor = setInterval(function(){
if(beginBtn.style.display){
clearInterval(waitFor);
appendCheatBtn();
initListener();
}
}, 1000);
})();