User:Blupo/wikia.js

(function ($, mw) { "use strict";    var config = mw.config.get([ "wgUserName" ]);   var loadFontPref = function  {        var load = mw.util.wikiScript('load'),            params = {            mode: 'articles',            only: 'styles',            debug: 'true',            // don't encode anything in the username here, $.get does it anyway            // otherwise stuff gets encoded twice and no results are returned            articles: 'User:' + config.wgUserName.replace(/ /g, '_') + '/fontpref.css'        };        $.get(load, params).done(function (data) { if (!data) { // just in case there was an error in the api request mw.log(this); }           console.log(data); });   };  /*	this.api.post({ action: 'edit', title: 'User:' + config.wgUserName.replace(/ /g, '_') + '/fontpref.css', text: "Helvetica", token: mw.user.tokens.get('editToken'), summary: 'Updating font preference', minor: true, bot: true }); */  var pageContent = document.getElementById("WikiaMainContent");  var pageRail = document.getElementById("WikiaRail");  var fontPickerAlreadyExists = document.getElementById("page-font");  if (fontPickerAlreadyExists) { return true }  var pickerLabel = document.createElement("label");  pickerLabel.setAttribute("for", "page-font");  var pickerLabelText = document.createTextNode("Select a font: ");  pickerLabel.appendChild(pickerLabelText);  var picker = document.createElement("select");  picker.setAttribute("id", "page-font");  var defaultFont = "Helvetica";  var options = {    "Helvetica" : "Helvetica",    "Rubik" : "Rubik",    "Zekton" : "Zekton",    "Dyslexic" : "OpenDyslexic",    "NGNL (please don't)" : "NGNL",    "Levi Brush" : "Levi Brush"  };  function changeFont (fontName) {    if (pageContent) { pageContent.style["font-family"] = fontName; }    if (pageRail) { pageRail.style["font-family"] = fontName; } } for (var displayName in options) { var fontOption = document.createElement("option"); fontOption.setAttribute("value", options[displayName]); if (displayName == defaultFont) { fontOption.setAttribute("selected", "true"); changeFont(options[displayName]); } var fontOptionText = document.createTextNode(displayName); fontOption.appendChild(fontOptionText); picker.appendChild(fontOption); } var pickerSubmit = document.createElement("button"); pickerSubmit.onclick = function { changeFont(picker.value); }; var pickerSubmitText = document.createTextNode("Change font"); pickerSubmit.appendChild(pickerSubmitText); var fontPickerContainer = document.createElement("div"); fontPickerContainer.setAttribute("class", "fp-container"); fontPickerContainer.style.cssText = "margin: 10px 0;"; fontPickerContainer.appendChild(pickerLabelText); fontPickerContainer.appendChild(picker); fontPickerContainer.appendChild(pickerSubmit); var content = document.getElementsByClassName("page-header__separator")[0]; if (!content) { return true } content.insertAdjacentElement("beforebegin", fontPickerContainer); });