-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmt_hotlist.user.js
140 lines (130 loc) · 5.12 KB
/
mt_hotlist.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
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
// ==UserScript==
// @name Monkeytype: Hotlist
// @namespace http://tampermonkey.net/
// @version 0.1.0
// @updateURL https://raw.githubusercontent.com/PoemOnTyperacer/tampermonkey/master/mt_hotlist.user.js
// @downloadURL https://raw.githubusercontent.com/PoemOnTyperacer/tampermonkey/master/mt_hotlist.user.js
// @description Highlight words of your choosing in monkeytype tests
// @author poem#3305
// @match https://monkeytype.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=monkeytype.com
// @grant GM_addStyle
// @noframes
// ==/UserScript==
const DEBUG = false;
const THEME='var(--main-color)';
const SEPARATOR=';'
const HL_DATA_ITEM='HotlistDataItemV2'
const WELCOME_MESSAGE='Customize your highlighted words list in the "behavior" settings.';
const GLOW_MULTIPLIER = 1.3; // overflow hidden over 1.3
const GLOW_MULTIPLIER_BIS = 0.6;
let createdMenu=false;
let HIGHLIGHT_LIST = [];
function log(msg){
if(DEBUG)
console.log('[Hotlist] '+msg)
}
function storeData(data) {
log("Storing settings data: "+data);
window.localStorage.setItem(HL_DATA_ITEM,data);
}
function loadData() {
let data = window.localStorage.getItem(HL_DATA_ITEM);
let message="Welcome to poem#3305's Hotlist mod\n===========================\n\n"+WELCOME_MESSAGE+"\n\n(This message won't show again.)";
if(data===null) {
log('No existing settings data found -- creating default');
storeData('');
window.alert(message);
return;
}
if(data=='') {
log('loaded data: highlight list is empty');
HIGHLIGHT_LIST=[];
return;
}
else {
HIGHLIGHT_LIST=data.split(';').map(function(e) {return e.trim();});
log('loaded highlight list: '+HIGHLIGHT_LIST);
}
}
loadData();
GM_addStyle(`
.glow {
-webkit-animation: glow 1s ease-in-out infinite alternate;
-moz-animation: glow 1s ease-in-out infinite alternate;
animation: glow 1s ease-in-out infinite alternate;
z-index:-2;
}
@-webkit-keyframes glow {
from {
text-shadow: 0 0 `+(GLOW_MULTIPLIER)+`px #fff, 0 0 `+(2*GLOW_MULTIPLIER)+`px #fff, 0 0 `+(3*GLOW_MULTIPLIER)+`px `+THEME+`, 0 0 `+(4*GLOW_MULTIPLIER)+`px `+THEME+`, 0 0 `+(5*GLOW_MULTIPLIER)+`px `+THEME+`, 0 0 `+(6*GLOW_MULTIPLIER)+`px `+THEME+`, 0 0 `+(7*GLOW_MULTIPLIER)+`px `+THEME+`;
}
to {
text-shadow: 0 0 `+(2*GLOW_MULTIPLIER_BIS)+`px #fff, 0 0 `+(3*GLOW_MULTIPLIER_BIS)+`px `+THEME+`, 0 0 `+(4*GLOW_MULTIPLIER_BIS)+`px `+THEME+`, 0 0 `+(5*GLOW_MULTIPLIER_BIS)+`px `+THEME+`, 0 0 `+(6*GLOW_MULTIPLIER_BIS)+`px `+THEME+`, 0 0 `+(7*GLOW_MULTIPLIER_BIS)+`px `+THEME+`, 0 0 `+(8*GLOW_MULTIPLIER_BIS)+`px `+THEME+`;
}
}
`);
const SETTINGS_HTML=`
<div class="groupTitle"><i class="fas fa-exclamation"></i> <span>hotlist</span></div>
<div class="text">Custom list of words to be highlighted during tests.</div>
<div class="inputs">
<div class="inputAndButton">
<input id="hotlistInputField" type="text" placeholder="placeholder; word; list" class="input customHotlist" value="`+HIGHLIGHT_LIST.join('; ')+`">
<div id="hotlistSaveButton" class="button save" tabindex="0" ><i class="fas fa-save fa-fw"></i></div>
</div>
</div>`;
const ELEMENT_CONFIG = {childList: true, subtree: true, attributes: true, characterData: false};
function elementMutate(mutations_list) {
for(let j=0;j<mutations_list.length;j++) {
let mutation=mutations_list[j];
for(let i=0;i<mutation.addedNodes.length;i++) {
let added_node=mutation.addedNodes[i];
let classList=added_node.classList;
if(classList==undefined)
continue;
if(classList.contains('pageSettings')) {
insertCustomHTML();
}
if(classList.contains('word'))
onNewWord(added_node);
}
}
}
const elementObserver = new MutationObserver(elementMutate);
elementObserver.observe(document.body, ELEMENT_CONFIG);
function insertCustomHTML() {
if(createdMenu)
return;
let sections=document.getElementsByClassName('behavior');
if(sections.length==0)
return;
let section=sections[0];
let customDiv=document.createElement('div');
customDiv.classList.add('section');
customDiv.classList.add('hotlist');
customDiv.innerHTML=SETTINGS_HTML;
section.insertBefore(customDiv, section.firstChild);
let saveButton=document.getElementById('hotlistSaveButton');
saveButton.onclick = function() {
let hotlistInputField=document.getElementById('hotlistInputField');
log('save button clicked ; loading and saving input field value='+hotlistInputField.value);
storeData(hotlistInputField.value);
loadData();
this.blur();
};
createdMenu=true;
}
function onNewWord(word) {
if(word.parentNode.id!='words')
return;
if(!word.classList.contains('glow')) {
let wordContent='';
let letters=word.childNodes;
for(let j=0;j<letters.length;j++) {
wordContent+=letters[j].innerText;
}
if(HIGHLIGHT_LIST.includes(wordContent)) {
word.classList.add('glow');
}
}
}