-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wordnik - Link to other dictionaries.user.js
259 lines (231 loc) · 8.34 KB
/
Wordnik - Link to other dictionaries.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// ==UserScript==
// @name Wordnik - Link to other dictionaries
// @namespace https://github.com/adamhotep/userscripts
// @author Adam Katz
// @version 0.5.20230302.0
// @include https://www.wordnik.com/words/*
// @require https://git.io/waitForKeyElements.js
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// ==/UserScript==
// Copyright 2009+ by Adam Katz, GPL v3+ {{{
//
// 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 <https://www.gnu.org/licenses/>. }}}
//// Greasemonkey 4 changed a lot. Here are some GM 3->4 compatibilty shims. {{{
if (typeof GM_xmlhttpRequest == 'undefined'
&& GM && typeof GM.xmlHttpRequest == 'function') {
var GM_xmlhttpRequest = GM.xmlHttpRequest;
}
// This GM_addStyle implementation is slightly modified from the GM 3->4 shim at
// https://arantius.com/misc/greasemonkey/imports/greasemonkey4-polyfill.js
if (typeof GM_addStyle == 'undefined') {
function GM_addStyle(aCss) {
'use strict';
let head = document.head;
if (head) {
let style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.textContent = aCss;
head.appendChild(style);
return style;
}
return null;
}
}
//// }}} end GM compatibility shims
// linkify cross-references (why doesn't Wordnik do this?)
waitForKeyElements('xref', function(xref) {
let link = document.createElement("a");
link.textContent = xref.innerText;
xref.textContent = "";
xref.appendChild(link);
link.href = "/words/" + link.textContent;
});
var term = location.pathname.substr(7); // remove the "/words/" prefix
term = term.replace(/\/$/, '');
var extra = document.createElement("div");
Node.prototype.prependChild = function(elem) {
if (this.childElementCount == 0) { return this.appendChild(elem); }
return this.insertBefore(elem, this.firstElementChild);
}
function addSection(header) {
let section = document.createElement("ul");
section.classList.add(header.replace(/\W+/g, "_"));
let item = document.createElement("li");
item.append(header);
item.classList.add("h");
section.appendChild(item);
extra.appendChild(section);
return section;
}
function addLink(section, href, text, title="") {
let item = document.createElement("li");
let link = document.createElement("a");
link.href = href;
if (title) { link.title = title; }
link.append(text);
item.appendChild(link);
return section.appendChild(item);
}
//var up = document.querySelector(".word_page");
var up = document.querySelector(".module-2columnRight");
if (term && up) {
up.prependChild(extra);
// close button
let checker = document.createElement("input");
checker.type = "checkbox";
checker.checked = false;
checker.id = "wnkxtra_hidden";
up.insertBefore(checker, extra);
let x = document.createElement("label");
x.id = "wnkxtra_x";
x.htmlFor = checker.id;
x.title = "shrink/grow";
extra.prependChild(x);
extra.id = "wnkxtra";
let dicts = addSection("More Dictionaries");
/*
addLink(dicts,
"https://www.wordnik.com/words/" + term,
"Wordnik",
"American Heritage 4e, Century Dictionary, GNU Collaborative Int'l, Roget's II 3e, Wordnet 3.0, Wiktionary"
);
*/
addLink(dicts,
"https://en.wiktionary.org/wiki/Special:Search?go=Go&search=" + term,
"Wiktionary", "User-driven general dictionary, sister to Wikipedia"
);
addLink(dicts,
"https://www.urbandictionary.com/define.php?term=" + term,
"Urban Dictionary", "User-driven slang dictionary, can be NSFW"
);
addLink(dicts,
"https://www.collinsdictionary.com/dictionary/english/" + term,
"Collins",
"Unabridged Collins, Official Scrabble, frequencies via Google Ngrams"
);
addLink(dicts,
"https://www.dictionary.com/browse/" + term,
"Dictionary.com", "Random House Unabridged, Collins, American Heritage, +"
);
addLink(dicts,
"https://www.merriam-webster.com/dictionary/" + term,
"Merriam-Webster"
);
let thesrs = addSection("Thesauruses");
addLink(thesrs,
"https://www.merriam-webster.com/thesaurus/" + term,
"Merriam-Webster", "Roget's Thesaurus?"
);
addLink(thesrs,
"http://www.moby-thesaurus.org/search?q=" + term,
"Moby Thesaurus", "Perhaps the biggest thesaurus out there"
);
addLink(thesrs,
`https://www.wordnik.com/words/${term}#related`,
"Wordnik",
"American Heritage 4e, Century, GNU Collaborative Int'l, Roget's II 3e, Wordnet 3.0, Wiktionary"
);
addLink(thesrs,
"http://words.bighugelabs.com/" + term,
"Big Huge Thesaurus", "Princeton Wordnet, CMU Pronouncing Dictionary"
);
addLink(thesrs,
"https://www.thesaurus.com/browse/" + term,
"Thesaurus.com", "Random House Unabridged, Collins, American Heritage, +"
);
addLink(thesrs,
"https://thesaurus.yourdictionary.com/" + term,
"YourDictionary", "YourDictionary Thesaurus"
);
let others = addSection("Other");
addLink(others,
"https://en.wikipedia.org/wiki/Special:Search?go=Go&search=" + term,
"Wikipedia", "User-driven general encyclopedia"
);
addLink(others,
"https://books.google.com/ngrams/graph?content=" + term
+ "&case_insensitive=on&year_start=1900&year_end=2999"
+ "&corpus=15&smoothing=3",
"Google Ngrams", "Popularity of this word in printed books"
);
addLink(others,
"https://duckduckgo.com/?ko=s&kp=-1&kw=w&kd=-1&ia=news&iax=1&q=" + term,
"DuckDuckGo News"
);
addLink(others,
"https://duckduckgo.com/?ko=s&kp=-1&kw=w&kd=-1&ia=web&iax=1&q=" + term,
"DuckDuckGo Web"
);
addLink(others,
"https://duckduckgo.com/?ko=s&kp=-1&kw=w&kd=-1&ia=images&iax=1&q=" + term,
"DuckDuckGo Images"
);
img_link = addLink(others,
"https://www.startpage.com/do/search?cat=pics&query=" + term,
"Google Images"
).childNodes[0];
img_link.id = "img_link";
img_link.title = "Google Images via Startpage.com";
GM_xmlhttpRequest({
method: 'GET',
url: img_link.href,
onload: function(response) {
let dom = response.responseXML;
// https://wiki.greasespot.net/index.php?title=GM.xmlHttpRequest#GET_request
if (!dom) {
dom = new DOMParser()
.parseFromString(response.responseText, "text/html");
}
dom = dom.body;
let img = dom.querySelector(`img.image-thumbnail[src]`);
if (img) {
let new_img = document.createElement("img");
new_img.loading = "lazy";
new_img.title = "First Google Image hit (anonymized by Startpage.com)";
new_img.src = img.src.replace(location.host, "www.startpage.com");
new_img.classList.add("startpage_image");
img_link.appendChild(new_img);
}
}
});
}
var css = document.createElement("style");
css.type = "text/css";
css.textContent = /* syn=css */ `
.content { padding-left:7em; }
#wnkxtra_hidden { display:none; }
#wnkxtra_x { float:right; border:1px solid #bbb; color:#aaa;
border-radius:1em; width:1.2em; text-align:center;
cursor:pointer; }
#wnkxtra_hidden:checked + #wnkxtra { width:1em; height:1em; overflow:hidden; }
#wnkxtra_hidden + #wnkxtra #wnkxtra_x:after { content: "−"; }
#wnkxtra_hidden:checked + #wnkxtra #wnkxtra_x:after { content: "+"; }
#wnkxtra { float:right; width:100%; color:#777; background:#fff8;
border:1px solid #eee; border-radius:1ex;
margin:3em 0 0 .5ex; padding:1ex 1ex 1ex 2ex; }
#wnkxtra ul { clear:right; float:left; width:50%; }
#wnkxtra ul.Other { clear:both; width:100%; }
#wnkxtra li { list-style-type:none; line-height:1em; }
#wnkxtra li.h { font-weight:bold; margin:3ex 0 0 -1ex; }
#wnkxtra li:not(.h)::before { content:"🠞"; padding-right:.2em; }
#wnkxtra a { text-decoration:none; }
#wnkxtra a:hover { text-decoration:underline; }
#wnkxtra .startpage_image { display:block; margin-top:3px; }
#wnkxtra .startpage_image:not(:hover) { max-width:100%; }
#wnkxtra + * { clear:right; }
xref > a { color:#148; }
`;
document.head.appendChild(css);