forked from omrihar/mathflowy
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontentscript.js
67 lines (61 loc) · 2.14 KB
/
contentscript.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
// inject needed scripts
var delimiters_inline = [];
var delimiters_display = [];
var option_delimiters = {
"inline-(": ["\\(", "\\)"],
"inline-$": ["$", "$"],
"display-[": ["\\[", "\\]"],
"display-$$": ["$$", "$$"]
}
var storage = chrome.storage.local;
if (chrome.storage.sync) {
storage = chrome.storage.sync;
}
storage.get({
"inline-(": true,
"inline-$": true,
"display-[": true,
"display-$$": true,
"inline-custom": false,
"display-custom": false,
"inline-custom-left": "",
"inline-custom-right": "",
"display-custom-left": "",
"display-custom-right": ""
}, function(prefs) {
for (var key in option_delimiters) {
if (prefs[key]) {
if (key.startsWith("inline")) {
delimiters_inline.push(option_delimiters[key]);
} else {
delimiters_display.push(option_delimiters[key]);
}
}
}
if (prefs["inline-custom"] && prefs["inline-custom-left"] != "" && prefs["inline-custom-left"] != "") {
delimiters_inline.push([prefs["inline-custom-left"], prefs["inline-custom-right"]]);
}
if (prefs["display-custom"] && prefs["display-custom-left"] != "" && prefs["display-custom-left"] != "") {
delimiters_display.push([prefs["display-custom-left"], prefs["display-custom-right"]]);
}
// 1. custom mathjax configuration
var s = document.createElement('script');
s.type = "text/x-mathjax-config";
s.text = 'MathJax.Hub.Config({\
tex2jax: {\
inlineMath: ' + JSON.stringify(delimiters_inline) + ',\
displayMath: ' + JSON.stringify(delimiters_display) + ',\
}\
});';
(document.head||document.documentElement).appendChild(s);
// 2. mathjax itself
s = document.createElement('script');
s.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML";
(document.head||document.documentElement).appendChild(s);
// 3. mods to render mathjax
s = document.createElement('script');
s.dataset.delimiters_inline = JSON.stringify(delimiters_inline);
s.dataset.delimiters_display = JSON.stringify(delimiters_display);
s.src = chrome.extension.getURL("render.js");
(document.head||document.documentElement).appendChild(s);
});