-
Notifications
You must be signed in to change notification settings - Fork 0
/
explain.js
79 lines (75 loc) · 2.38 KB
/
explain.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
console.log("Loaded Tone Extension. Double-click to add hover-over guidance.");
indicator_and_meanings = {
// Please order these so that possible substrings follow the larger match
// e.g. place "gen" first, and then "g"
// otherwise, "g" will be extracted and "gen" will not be able to be matched
"/gen": "genuine",
"/g": "genuine",
"/j": "joking",
"/jk": "just kidding",
"/hj": "half-joking",
"/s": "sarcastic",
"/srs": "serious",
"/nsrs": "not serious",
"/lh": "light hearted",
"/pos": "positive",
"/pc": "positive connotations",
"/neg": "negative",
"/nc": "negative connotations",
"/neu": "neutral",
"/p": "platonic",
"/r": "romantic",
"/c": "copypasta",
"/l": "lyrics",
"/ly": "lyrics",
"/nm": "not mad",
"/lu": "little upset",
"/nbh": "nobody here (not talking about anybody here)",
"/nsb": "not subtweeting (not talking about anybody here)",
"/sx": "sexual",
"/x": "sexual",
"/nx": "non-sexual",
"/nsx": "non-sexual",
"/t": "teasing",
"/ij": "inside joke",
"/ref": "reference",
"/m": "metaphorically",
"/li": "literally",
"/hyp": "hyperbole",
"/ex": "exaggeration",
"/f": "fake",
"/th": "threat",
"/cb": "clickbait",
"/rh": "rhetorical",
"/rt": "rhetorical",
"/pa": "passive-aggressive",
"/npa": "not passive-aggressive",
"/nf": "not forced",
"/nbr": "not being rude",
"/q": "quote",
}
function addClassAndTitleToSelection(sel, cls, title){
if(sel.getRangeAt){ // Webkit browsers
var range = sel.getRangeAt(0);
var newNode = document.createElement("span");
newNode.setAttribute('class', cls);
newNode.setAttribute('title', title);
range.surroundContents(newNode);
} else { // Backup
sel.pasteHTML(`<span title="{title}" class="${cls}>`+sel.htmlText+'</span>');
}
}
f=function(){
chosen = window.getSelection()
selection_str = chosen.toString().trim();
if (! selection_str.includes("/")){
selection_str = "/" + selection_str
}
console.log("Double Clicked Selection:", selection_str);
indicator = indicator_and_meanings[selection_str]
if (indicator != undefined){
console.log("Tone:", indicator)
addClassAndTitleToSelection(chosen, 'tone_indicator_highlight', indicator)
}
}
document.body.addEventListener('dblclick',f);