User:Joshurtree/talkthread.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Joshurtree/talkthread. |
//<pre><nowiki>
function createMessage(section) {
var edit = document.getElementById('wpTextBox1');
var replyToPos = document.URL.lastIndexOf('replyto=');
edit.value += '{{msg start|id=' + wgArticleId;
if (replyToPos != -1) {
var replyto = document.URL.slice(replyToPos + 8);
edit.value += '|replyto=' + replyto;
document.getElementById('wpSummary').value += 'Reply to ' + replyto;
}
edit.value += '}}\n';
edit.value += '<!--- Insert message here --->\n';
edit.value += '{{msg end|signature=~~~~|username='
+ wgUserName + '|section=' + section + '}}';
}
function addlilink(tabs, url, name, id, title, key){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
tabs.appendChild(li);
if(id)
{
if(key && title)
{
ta[id] = [key, title];
}
else if(key)
{
ta[id] = [key, ''];
}
else if(title)
{
ta[id] = ['', title];
}
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
function addTab(url, name, id, title, key){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
function collapseDescendants() {
alert("collapseDescendants");
}
function showThisThread() {
alert("showThread");
}
function setupCollapsing(collapsed) {
var headers = document.getElementsByName("id");
var collapseDesc = document.createElement("a");
collapseDesc.href = "javascript::collapseDescendants()";
collapseDesc.innerHTML = "↑";
collapseDesc.title = "Collapse descendants";
var showThread = document.createElement("a");
showThread.href = "javascript::showThisThread()";
showThread.innerHTML = "↓";
showThread.title = "Show this thread only";
for (var i = 0; i < headers.length; ++i) {
headers[i].insertBefore(headers[i].firstChild, showThread);
headers[i].insertBefore(headers[i].firstChild, collapseDesc);
}
}
function countSections(url) {
var article = window.open(url, "_blank", "directories=no, height=100, location=no, menubar=no, scrollbars=no, resizable=no, titlebar=no, statusbar=no, toolbar=no, width=no");
return article.document.getElementsByTagName("h2").length + 1;
}
$(function() {
window.alert("test");
var addSection = document.getElementById('ca-addsection');
var section = document.getElementsByName('wpSection');
var edit = document.getElementById('wpTextBox1');
if (addSection && edit == null) {
var name = 'Start thread';
addTab(url, name, 'usStartThread', name, null);
setupCollapsing(false);
} else if (document.URL.indexOf("replyto") != -1) {
createMessage(section[0].value);
} else if (document.URL.indexOf("sectionnum=") != -1) {
var url = document.URL;
var sectionNum =
url.slice(parseInt(url.indexOf("sectionnum=")) + 11);
if (isFinite(sectionNum)) {
var sectionName = prompt("Enter new section name", "");
if (sectionName != null && sectionName != "") {
edit.value += '\n== ' + sectionName + ' ==\n';
document.getElementById("wpSummary").value
+= "/* " + sectionName + " */";
createMessage(sectionNum);
}
}
}
});
//</nowiki></pre>