User:Porter21/SectionNotice.js

// ============================================================ // BEGIN Empty section notice // ============================================================

// Description: Automatically insert "Add it!" notice into empty article sections // Credit:     User:Porter21

function addEmptySectionNotice { var content; var linktext = 'writing it'; var textbeforelink = 'This section has not been written yet. You can help The Vault by '; var textafterlink = '.'; var noticeclass = 'hatnote'; var noticestyle = 'background-color: orange;';

// Restrict to article namespace if (wgNamespaceNumber != 0) { return; }

// Get content container if (skin == 'oasis') { content = document.getElementById('WikiaArticle'); } else if (skin == 'monaco') { content = document.getElementById('article'); } else if (skin == 'monobook') { content = document.getElementById('content'); } else { return; }

// Check sections and add notices if (content) { var sectiontitles = $('span.mw-headline');

if (sectiontitles) { for (var i = 0; i < sectiontitles.length; i++) { var nextelement, nextelement2; var nextnode, nextnode2; var editlink = $('span.editsection > a', sectiontitles[i].parentNode).attr("href") || "";

// Get next 2 HTML nodes nextnode = sectiontitles[i].parentNode.nextSibling; while (nextnode) { if (nextnode.nodeType == 1) { nextelement = nextnode;

nextnode2 = nextnode.nextSibling; while (nextnode2) { if (nextnode2.nodeType == 1) { nextelement2 = nextnode2; break; }                    nextnode2 = nextnode2.nextSibling; }                 break; }              nextnode = nextnode.nextSibling; }

// Add notices to empty sections which are followed by a headline of same or higher level (or end of page) if (nextelement2.tagName.substr(1, 2) <= sectiontitles[i].parentNode.tagName.substr(1, 2)               && ((nextelement.tagName.toLowerCase == 'a') || (nextelement.tagName.toLowerCase == 'div'                && nextelement.className == 'printfooter'))) { $('' + textbeforelink + '' + linktext + '' + textafterlink + ' ').insertAfter(sectiontitles[i].parentNode); }        }      }   } }

addOnloadHook( addEmptySectionNotice );

// ============================================================ // END Empty section notice // ============================================================