-
Notifications
You must be signed in to change notification settings - Fork 3
/
codeInjection_basicTranslation.html
140 lines (124 loc) · 5.79 KB
/
codeInjection_basicTranslation.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
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
basicTranslation_dictionary = {
"mobileBar": {
"Email": "Email",
"Call": "Anruf",
"Map": "Karte",
"Hours": "Zeiten"
},
"contactFormLabel": {
"First Name": "Vorname",
"Last Name": "Nachname"
},
"contactFormError": {
"is required.": "ist erforderlich.",
"is not valid. Email addresses should follow the format user@domain.com.": "folgt die Konvention benutzer@domain.com.",
"Your form has encountered a problem.": "Oops, da ging etwas schief.",
"Please scroll down to review.": "",
"Please scroll up to review.": ""
},
"commentingSectionHeader": {
"Comments": "Kommentare",
"Newest First": "Neuste zuerst",
"Oldest First": "Älteste zuerst",
"Most Liked": "Beliebteste zuerst",
"Least Liked": "Unbeliebteste zuerst",
"Subscribe via e-mail": "Per E-Mail Abonieren"
},
"commentingEntryHeader": {
"Pending": "In Prozess",
"Awaiting Moderation": "Wartet auf Moderator",
"Not Logged In": "Nicht eingelogged"
},
"commentingEntryButtons": {
"Preview": "Vorschau",
"Edit": "Editieren",
"Post Comment": "Veröffentlichen",
"Post Reply": "Antworten"
},
"commentingTime": {
"Just now": "Jetzt",
"An": "",
"A": "",
"minute ago": "Minute alt",
"minutes ago": "Minuten alt",
"hour ago": "Stunde alt",
"hours ago": "Stunden alt",
"day ago": "Tag alt",
"days ago": "Tage alt"
}
};
/************************************************************************************/
basicTranslation_selectors = {
"mobileBar": ".sqs-mobile-info-bar-trigger-label", //direct, assign
"contactFormLabel": "form label.caption", //filter, assign
"contactFormError": "form div.field-error", //direct, replace
"commentingSectionHeader": "h3.comment-count span, div.comment-controls span, div.comment-controls option", //direct, assign
"commentingEntryHeader": "div.comment-header span", //direct, replace
"commentingEntryButtons": "div.comment-btn-wrapper>span", //direct, assign
"commentingTime": "div.comment-header span.timesince" //direct, replace
};
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
jQuery(document).ready( function() {
var mutationObserver = new MutationObserver(basicTranslation_mutationObserver);
mutationObserver.observe(document, { subtree: true, childList: true, characterData: true });
basicTranslation_naiveReplace(jQuery(basicTranslation_selectors["mobileBar"]), "mobileBar", basicTranslation_isTextNode);
basicTranslation_naiveReplace(jQuery(basicTranslation_selectors["contactFormLabel"]), "contactFormLabel", basicTranslation_isTextNode);
}); //onStartup
/************************************************************************************/
basicTranslation_isTextNode = function() {
return this.nodeType === 3;
}; //routine
basicTranslation_isAnyNode = function() {
return true;
}; //routine
/************************************************************************************/
basicTranslation_mutationObserver = function(mutations, observer) {
for (var i=0; i<mutations.length; i++) {
var mutationRecord = mutations[i];
switch (mutationRecord.type) {
case "childList":
if (!("addedNodes" in mutationRecord) || mutationRecord.addedNodes.length===0) {
break;
} //if
var addedNodes = jQuery(mutationRecord.addedNodes);
basicTranslation_naiveReplace(addedNodes, "contactFormLabel", basicTranslation_isTextNode);
basicTranslation_naiveReplace(addedNodes, "contactFormError", basicTranslation_isTextNode);
basicTranslation_naiveReplace(addedNodes, "commentingSectionHeader", basicTranslation_isTextNode);
basicTranslation_naiveReplace(addedNodes, "commentingEntryHeader", basicTranslation_isTextNode);
basicTranslation_naiveReplace(addedNodes, "commentingEntryButtons", basicTranslation_isTextNode);
basicTranslation_naiveReplace(addedNodes, "commentingTime", basicTranslation_isTextNode);
break;
case "characterData":
switch (mutationRecord.target.parentNode.className) {
case "timesince":
basicTranslation_naiveReplace(jQuery(mutationRecord.target.parentNode), "commentingTime", basicTranslation_isTextNode);
break;
case "btn-text preview-comment top-level-preview-btn":
console.log(mutationRecord.target.parentNode.className, mutationRecord.target.data);
basicTranslation_naiveReplace(jQuery(mutationRecord.target.parentNode), "commentingEntryButtons", basicTranslation_isTextNode);
break;
} //switch
break;
} //switch
} //for
observer.takeRecords();
}; //onDemand
/************************************************************************************/
basicTranslation_naiveReplace = function(nodes, section, filter) {
nodes
.find(basicTranslation_selectors[section])
.addBack(basicTranslation_selectors[section])
.contents()
.filter(filter)
.each(function() {
for (var originPhrase in basicTranslation_dictionary[section]) {
var destinationPhrase = basicTranslation_dictionary[section][originPhrase];
this.data = this.data.replace(originPhrase, destinationPhrase);
}
});
}; //routine
</script>