-
Notifications
You must be signed in to change notification settings - Fork 1
/
musify.js
75 lines (67 loc) · 3.08 KB
/
musify.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
//Musify.js by Corey Mwamba, 9 Oct 2010
//Dustin Diaz' selective ClassName hack
function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) { // use native implementation if available
return node.getElementsByClassName(classname);
} else {
return (function getElementsByClass(searchClass,node) {
if ( node == null )
node = document;
var classElements = [],
els = node.getElementsByTagName("*"),
elsLen = els.length,
pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
})(classname, node);
}
}
var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
//THIS LINE IS THE ONE TO EDIT - change to where you have put the CSS file
cssNode.href = 'http://musify.coreymwamba.co.uk/musify_1.0/musify.css';
headID.appendChild(cssNode);
var tes = document.getElementsByClassName('musify');
for (var i=0; i < tes.length; i++ ) {
tes[i].style.display = "normal";
//new way: regexp the brackets first
setthlxp = new RegExp ("(\\<\\|)(\\s*)(\\d\\W\\s*)", "g");
setthrxp = new RegExp ("(\\d*)(\\s*)(\\|\\>)", "g");
sevsubun = new RegExp ("(<sub>)([^7]*)(<sup>)(7)(<\\/sup>)", "g");
setthelb = "❬"
settherb = "❭"
ubo = tes[i].innerHTML.replace (/\[-/g, "<sub>");
ubc = ubo.replace (/-\]/g, "</sub>");
sharp = ubc.replace (/\#/g, "<abbr title='sharp'>♯</abbr>");
dsharp = sharp.replace (/\<abbr title='sharp'>\&\#9839;\<\/abbr\>\<abbr title='sharp'>\&\#9839;\<\/abbr\>/g, "<abbr class='dblsharp' title='double sharp'>✢</abbr>");
resubo = dsharp.replace ("[<sub>", "<sup>♯");
tied = resubo.replace (/(\-\-)/g, "<span class='musitie'>⏝</span>");
tieu = tied.replace (/(\=\=)/g, "<span class='musotie'>⏜</span>");
losq = tieu.replace (setthlxp, setthelb+"$2$3");
rosq = losq.replace (setthrxp, "$1$2"+settherb);
hdim = rosq.replace ("~", "<sup class='mushdim'><abbr title='half-diminished'>ø</abbr></sup>");
snbo = hdim.replace (/(\[\[)/g, "<sup>");
snbc = snbo.replace (/(\]\])/g,"</sup>");
sbo = snbc.replace (/\(\(/g, "<sup>(");
sbc = sbo.replace (/\)\)/g, ")</sup>");
scbo = sbc.replace (/\{\{/g, "<span class='musnum'>");
scbc = scbo.replace (/(\}\})/g, "</span>");
scbs = scbc.replace (/(\/\/)/g, "</span>⁄<span class='musden'>");
scbns = scbs.replace (/\@/g, "</span><span class='timden'>");
dim = scbns.replace (/\_/g, "<sup class='musdim'>°</sup>");
tri =dim.replace (/\^/g, "Δ");
mult = tri.replace (/\*/g, "×");
flat = mult.replace (/(\£)|(\¤)|(\$)|(\€)|(\¥)/g, "<abbr title='flat'>♭</abbr>");
sim = flat.replace (/\%/g, "<abbr title='simile'>÷</abbr>");
ell = sim.replace (/(\.\.\.)/g, "…");
nat = ell.replace (/\?/g, "<abbr title='natural'>♮</abbr>");
bre = nat.replace (/(\!\!)/g, "<br />");
tes[i].innerHTML = bre;
}