-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.user.js
144 lines (128 loc) · 4.76 KB
/
template.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
141
142
143
144
// ==UserScript==
// @name facebook-!TEANGA!
// @namespace IndigenousTweets.com
// @description Translates Facebook into !ENGLISHNAME!
// @include http*://*.facebook.com/*
// @include http*://facebook.com/*
// @author Kevin Scannell
// @run-at document-start
// @version !LEAGAN!
// @icon http://indigenoustweets.com/resources/gm.png
// ==/UserScript==
// Last updated: !DATA!
// Translations: !TRANSLATORS!
/*
* Copyright 2012 Kevin Scannell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
var tags = new Array();
tags.push('a'); // many...
tags.push('h4'); // Sponsored, Ticker, ...
tags.push('h6'); // %a commented on %a.
tags.push('label'); // Comment
var divclasses = new Array();
divclasses.push('innerWrap'); // Write a comment... <textarea>
divclasses.push('commentActions fsm fwn fcg'); // time stamps on comments
divclasses.push('UIImageBlock_Content UIImageBlock_ICON_Content'); // 2 people like this
//divclasses.push('fsm fwn fcg'); // By:
//divclasses.push('uiImageBlockContent uiImageBlockSmallContent'); // "near"
var spanclasses = new Array();
spanclasses.push('default_message'); // Like/Dislike
spanclasses.push('saving_message'); // Like/Dislike
spanclasses.push('uiStreamSource'); // %T near %a
// Replace the search string with the translated string
function r(dd, s, t) {
if (s == t) {
return (dd);
} else {
var RegExpr = new RegExp(s, "g");
return (dd.replace(RegExpr, t));
}
}
function translate(x) {
d = x;
// Translations go here
return d;
}
function translateOnInsert( node ) {
//var logmsg = 'inserted a ' + node.nodeName + ' node; untranslated elements: ';
for (n = 0; n < tags.length; n++) {
var tagmatches = node.getElementsByTagName(tags[n]);
for ( i = 0; i < tagmatches.length; i++ ) {
// innerHTML often empty (never null)
if (!tagmatches[i].hasAttribute('indigenous') &&
tagmatches[i].innerHTML != '') {
// logmsg = logmsg + tagmatches[i].nodeName + ' ';
tagmatches[i].innerHTML = translate(tagmatches[i].innerHTML);
tagmatches[i].setAttribute('indigenous', true);
}
}
}
var divs = node.getElementsByTagName('div');
for (i = 0; i < divs.length; i++ ) {
if (!divs[i].hasAttribute('indigenous')) {
for (n = 0; n < divclasses.length; n++) {
if (divs[i].className == divclasses[n]) {
// logmsg = logmsg + 'DIV.' + divclasses[n] + ' ';
divs[i].innerHTML = translate(divs[i].innerHTML);
divs[i].setAttribute('indigenous', true);
break;
}
}
}
}
var spans = node.getElementsByTagName('span');
for (i = 0; i < spans.length; i++ ) {
if (!spans[i].hasAttribute('indigenous')) {
for (n = 0; n < spanclasses.length; n++) {
if (spans[i].className == spanclasses[n]) {
// logmsg = logmsg + 'SPAN.' + spanclasses[n] + ' ';
spans[i].innerHTML = translate(spans[i].innerHTML);
spans[i].setAttribute('indigenous', true);
break;
}
}
}
}
// GM_log(logmsg);
}
// This is (only) needed to handle updates to time stamps
function listen_for_change(evt)
{
var node = evt.target;
//GM_log('in change node, data='+node.data+'; was='+evt.prevValue);
document.body.removeEventListener( 'DOMCharacterDataModified', listen_for_change, false );
node.data = translate(node.data);
document.body.addEventListener( 'DOMCharacterDataModified', listen_for_change, false );
}
function listen_for_add(evt)
{
var node = evt.target;
if (node.nodeType == document.ELEMENT_NODE &&
node.nodeName != 'SCRIPT' &&
node.nodeName != 'INPUT') {
document.body.removeEventListener( 'DOMNodeInserted', listen_for_add, false );
translateOnInsert(node);
document.body.addEventListener( 'DOMNodeInserted', listen_for_add, false );
}
}
function initme()
{
document.body.addEventListener( 'DOMNodeInserted', listen_for_add, false );
document.body.addEventListener( 'DOMCharacterDataModified', listen_for_change, false );
document.body.innerHTML = translate(document.body.innerHTML);
}
document.addEventListener( "DOMContentLoaded", initme, false);