User:Finnusertop/serendipity.js

/** * Serendipity * * Endows Wikipedia with the “sense of wonder” and “serendipitous discoveries” * that proud owners of the print Encyclopædia Britannica find sorely lacking on * the Internet. Now, whenever you look up an entry in this ephemeral reference, * “lose yourself” in the alphabetically adjacent bounty of knowledge that any * self-respecting encyclopedia should offer by default. * * :-P */

if (mw.config.get("wgAction") == "view" && mw.config.get("wgNamespaceNumber") == 0) { mw.loader.using("mediawiki.api", function {        var api = new mw.Api;        /**         * Retrieves the rendered HTML content of an alphabetically adjacent         * article and passes the content to a callback function.         *          * @param forward   {boolean}   True to get the next page; false to get         *                              the previous one.         * @param ok        {function}  A callback function that takes two         *                              arguments: title, html.         */        function fetchAdjacentArticle(forward, ok) {            api.get({ list: "allpages", apfrom: mw.config.get("wgPageName"), apnamespace: 0, apfilterredir: "nonredirects", aplimit: 2, apdir: forward ? "ascending" : "descending", }).done(function (data) { var pages = data.query && data.query.allpages; var page = pages && data.query.allpages[1]; if(!page) return; $.get(mw.util.wikiScript("index"), {                   title: page.title,                    action: "render",                }, function (html) {                    if (ok) ok(page.title, html);                }, "html"); });       }        /**         * Hides content features that facilitate user contributions, multimedia         * experiences, non-linear navigation, or fact-checking.         */        function hideNewFangledFeatures {            // Links           // $("#bodyContent a").unbind("click").click(function (evt) { // evt.preventDefault; // evt.stopPropagation; // });           var extLinkHeadings = $("h2:contains('xternal link')");            extLinkHeadings.hide.nextAll("ul").hide;            if (extLinkHeadings) {                $(".toctext:contains('xternal link')").parent.hide;            }            var furtherHeadings = $("h2:contains('urther readin')");            furtherHeadings.hide.nextAll("ul").hide;            if (furtherHeadings) {                $(".toctext:contains('urther readin')").parent.hide;            }            var notesHeadings = $("h2:contains('Notes')");            notesHeadings.hide.nextAll("ul").hide;            if (notesHeadings) {                $(".toctext:contains('Notes')").parent.hide;            }            var refHeadings  = $("h2:contains('eference')");            refHeadings .hide.nextAll("ul").hide;            if (refHeadings ) {                $(".toctext:contains('eference')").parent.hide; }           var bibHeadings = $("h2:contains('Bibliography')"); bibHeadings.hide.nextAll("ul").hide; if (bibHeadings) { $(".toctext:contains('Bibliography')").parent.hide; }          var citHeadings = $("h2:contains('Citations')"); citHeadings.hide.nextAll("ul").hide; if (citHeadings) { $(".toctext:contains('Citations')").parent.hide; }          var souHeadings = $("h2:contains('Sources')"); souHeadings.hide.nextAll("ul").hide; if (souHeadings) { $(".toctext:contains('Sources')").parent.hide; }

// WikiMiniAtlas wma_settings = {enabled: false}; // Stylesheets only need to be applied once. if (hideNewFangledFeatures.stylesAdded) return; hideNewFangledFeatures.stylesAdded = true; // Links mw.util.addCSS("#bodyContent a {" +                          "background: transparent !important;" +                           "color: inherit; padding-right: 0 !important;" +                           "text-decoration: inherit;" +                           "}"); // Abbreviations mw.util.addCSS("#bodyContent abbr, #bodyContent acronym," +                          "#bodyContent .explain {" +                           "border-bottom: none;" +                           "}"); // Software-powered features mw.util.addCSS("#mw-articlefeedback, #catlinks, .mw-editsection," +                          ".magnify, .toctoggle {display: none;}"); // Cite extension mw.util.addCSS(".reference, .reflist {display: none;}"); // Template-powered features mw.util.addCSS("#coordinates, img[alt='play'], .navbox, .stub" +                           "{display: none;}"); }       /**         * Inserts the contents of the previous article above the original one. */       function insertPreviousArticle(title, html) { // Stuff the main article’s title inside its body element. $("#bodyContent").prepend($("#firstHeading")); $("#firstHeading").css({               "font-size": 1.25 * parseFloat($("#firstHeading").css("font-size")),            }); $("#bodyContent").prepend(" ") .prepend($(html).wrap(" ")) .prepend("" +                                     " " + title + " " +                                      " "); hideNewFangledFeatures; };       /**         * Inserts the contents of the next article above the original one. */       function insertNextArticle(title, html) { $("#bodyContent").append("" +                                    " " + title + " " +                                     " ") .append($(html).wrap(" ")) .append(" "); hideNewFangledFeatures; };       $(function  {            fetchAdjacentArticle(false, insertPreviousArticle);            fetchAdjacentArticle(true, insertNextArticle);        }); }); }