forked from FlominatorTM/WikiTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefExtract.js
More file actions
23 lines (21 loc) · 911 Bytes
/
Copy pathRefExtract.js
File metadata and controls
23 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
javascript: var name = prompt("future name of this <ref>?");
/* place cursor inside an inline reference before clicking */
var wpTextbox = document.getElementById("wpTextbox1");
var selectionStart = wpTextbox.selectionStart;
var indexEndRef = wpTextbox.value.indexOf("</ref>", selectionStart);
var indexStartRef = wpTextbox.value.lastIndexOf("<ref>", indexEndRef);
if (indexEndRef == -1 || indexStartRef == -1) {
alert("please place cursor inside the ref tags");
} else {
var lengthSourceEnd = indexEndRef + "</ref>".length - indexStartRef;
var wholeSource = wpTextbox.value.substr(indexStartRef, lengthSourceEnd);
var ref = wholeSource.replace("<ref>", '<ref name="' + name + '">');
wpTextbox.value = wpTextbox.value.replace(
wholeSource,
'<ref name="' + name + '"/>'
);
wpTextbox.selectionStart = selectionStart;
wpTextbox.selectionEnd = selectionStart;
prompt("", ref);
}
void 0;