User:Conrad.Irwin/subsectionpreload.js

if (wgPageName == 'Wiktionary:Beer_parlour') addOnloadHook(function {    // Loads a section from the archive and puts it at the top of the page    function load_section_from_archive(section_title)    {        var page_title = 'Wiktionary:Beer_parlour/' + section_title;        if (!arguments.callee.div)        {            var insert_after = document.getElementById('jump-to-nav');            arguments.callee.div = newNode('div',{class:'toc'});            insert_after.parentNode.insertBefore(arguments.callee.div, insert_after.nextSibling);        }        var div = arguments.callee.div;

div.innerHTML = ""; div.appendChild(newNode('b', "Loading, '" + section_title + "' from Archive. Please wait."))

JsMwApi.page(page_title).parse(function (section, result)       {            if (!result || !result.parse || !result.parse.revid)            {                div.innerHTML = "";                div.appendChild(newNode('b',"Could not find '" + section_title + "' in Archives. Sorry."));            }            else            {                div.innerHTML = section;                div.insertBefore(newNode('b', "This is an archived discussion from ",                     newNode('a', {href:wgArticlePath.replace("%s", encodeURIComponent(page_title))}, page_title),                    newNode('br')                ), div.firstChild);            }        }); }

// __init__

var location = window.location.toString;

// If we are at a section title that isn't in the document, try loading it from the archives location.replace(/^.*#(.*)$/, function (match, section_title)   {        if (! document.getElementById(section_title) )           load_section_from_archive(decodeURIComponent(section_title.replace('.', '%')));    }); });