-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikipedia-latex.js
66 lines (62 loc) · 1.83 KB
/
wikipedia-latex.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
// ==UserScript==
// @name Wikipedia LaTeX Plain Plugin
// @namespace http://sebi.io/
// @version 0.1
// @description Adds a small blue square next to formulas that shows the formula as plain text.
// @match http*://*.wikipedia.org/*
// @copyright 2016+, sebi.io
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
$(document).ready(function () {
addGlobalStyle(`
.sebi_io_latex_tooltip {
display: inline-block;
font-size: 9px;
font-family: monospace;
width: auto;
height: auto;
overflow: hidden;
margin-left: 4px;
}
.sebi_io_latex_tooltip textarea {
display: none;
}
.sebi_io_latex_tooltip_open textarea {
display: inline-block;
}
.sebi_io_latex_tooltip_open {
background-color: white;
width: auto;
height: auto;
display: inline-block;
}
`);
var elements = $('annotation', 'semantics', 'math');
if(elements === null) {
return;
}
elements.each(function () {
var p = $(this).parents().eq(3);
var str = $(this).text();
str = str.substring(14, str.length - 1);
str = $.trim(str);
if (str.length > 2) {
p.append("<div class='sebi_io_latex_tooltip'><img src='https://cloud.githubusercontent.com/assets/2178959/15872148/41aad162-2cf8-11e6-9ba6-ba16493db779.png'></img> <textarea>" + str + "</textarea></div>");
}
});
$('.sebi_io_latex_tooltip > img').click(function () {
$(this).parent().toggleClass('sebi_io_latex_tooltip_open');
});
$('.sebi_io_latex_tooltip').select(function () {
return false;
});
});
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}