User:Xenwolf/vector.js

From Xenharmonic Wiki
Revision as of 21:35, 31 May 2020 by Xenwolf (talk | contribs) (testing conditional addition)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
function format_words(title, numWords){
  return title+" ("+numWords+" words)";
}

function conditional_text(condition, text) {
  if (condition){
    return text;
  }
  return "";
}

$(document).ready(function(){
  const numWords = $("#mw-content-text > div").text().split(" ").length;
  const header = $("#firstHeading").text();
  const isEditing = $("#toolbar").length !== 0;
  console.log("isEditing:"+isEditing);
  $("#firstHeading").text(format_words(header, numWords)+conditional_text(isEditing, " 🙂 😉 🙁"));
  $("#toolbar").add("🙂");
});