mozillaZine Forums Menu

By LouCypher Last update Jul 29, 2011 — Installed 2,128 times.

There are 5 previous versions of this script.

// ==UserScript==
// @name            mozillaZine Forums Menu
// @namespace       http://mozilla.status.net/loucypher
// @description     Navigation menu for mozillaZine Forums
// @icon            http://i.imgur.com/01UZS.png
// @version         2.2
// @author          LouCypher
// @license         MPL 1.1
// @include         http://forums.mozillazine.org/*
// ==/UserScript==

/*
    Changelog:
      * 2011-07-21:
        + Added links to official forums for Firefox/Thunderbird/mobile
        * Cosmetic changes
      * 2011-07-19:
        + Added link to this user script at userscripts.org
        x Cosmetic changes
      * 2011-07-18: Version 2.0
      * 2006-07-31: Updated to new layout
      * 2006-06-20: Added new forum and new forum category
      * 2006-06-12: Rearrange
      * 2005-08-13: Rearrange
      * 2005-08-08:
        - Fixed menu positions
        - Added index to insertMenu function
        - Added User Links menu
*/

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original mozillaZine Forums Menu user script.
 *
 * The Initial Developer of the Original Code is LouCypher.
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s)
 * - LouCypher <http://twitter.com/zoolcar9>
 *
 * ***** END LICENSE BLOCK ***** */

let linklist = document.querySelector("#page-header .linklist");
if (!linklist) return;

const htmlns = "http://www.w3.org/1999/xhtml";

let style = document.head.appendChild(document.createElement("style"));
style.type = "text/css";
style.textContent = "\
  #page-header .linklist .icon-home, .menu .submenu {\
    display: none;\
  }\
  .menu { padding: 1px .5em 0 17px; }\
  .menu .submenu {\
    border: 1px solid #027ab7;\
    /*border-top-width: 0;*/\
    background-color: rgb(202, 220, 235);\
    padding: 0 0 .5em .5em;\
    margin-left: -2em;\
    position: absolute;\
    z-index: 3;\
  }\
  .menu.icon-subscribe {\
    background-position: .5em 50%;\
    background-color: white;\
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, .5);\
    padding-left: 2em;\
  }\
  .menu .submenu, .menu:hover {\
    box-shadow: 3px 3px 3px rgba(0, 0, 0, .5);\
  }\
  .menu:hover .submenu, .submenu li a { display: block; }\
  .menu:hover, .submenu li:hover { background-color: #027ab7; }\
  .menu a:hover { text-decoration: none; }\
  .menu:hover, .menu:hover > strong > a, \
  .submenu li:hover a, .submenu a:hover { color: white; }\
  .submenu li { float: none !important; padding-right: .5em; }\
  .menu a:-moz-focusring { outline: none; }\
  .submenu a { padding: 0 .5em; }\
  .submenu li.external { border-top: 2px groove rgba(202, 220, 235, .5); }\
";

let forums = [
  { name: "Firefox", id: "49",
    subs: [
      { name: "Firefox Support",                        id: "38" },
      { name: "Firefox General",                        id:  "7" },
      { name: "Firefox Builds",                         id: "23" },
      { name: "Firefox Features",                       id:  "8" },
      { name: "Firefox Bugs",                           id:  "9" },
      { name: "Official Forum",                         id:  "!",
        url:  "https://support.mozilla.com/"                     }
    ]
  },
  { name: "Thunderbird", id: "50",
    subs: [
      { name: "Thunderbird Support",                    id: "39" },
      { name: "Thunderbird General",                    id: "28" },
      { name: "Thunderbird Builds",                     id: "29" },
      { name: "Thunderbird Features",                   id: "30" },
      { name: "Thunderbird Bugs",                       id: "31" },
      { name: "Official Forum",                         id: "!",
        url:  "http://support.mozillamessaging.com/"             }
    ]
   },
  { name: "SeaMonkey", id: "51",
    subs: [
      { name: "SeaMonkey Support",                      id: "40" },
      { name: "SeaMonkey General",                      id:  "3" },
      { name: "SeaMonkey Builds",                       id:  "6" },
      { name: "SeaMonkey Features",                     id:  "4" },
      { name: "SeaMonkey Bugs",                         id:  "5" }
    ]
  },
  { name: "Others", id: "52",
    subs: [
      { name: "Camino",                                 id: "12" },
      { name: "Calendar",                               id: "46" },
      { name: "Mobile",                                 id: "47" },
      { name: "Miscellaneous Support",                  id: "32" },
      { name: "Other Applications and Distributions",   id: "34" },
      { name: "Official Mobile Forum",                  id:  "!",
        url:  "https://support.mozilla.com/mobile"               }
    ]
  },
  { name: "Add-ons", id: "53",
    subs: [
      { name: "Extension/Theme Releases",               id: "48" },
      { name: "Extension Development",                  id: "19" },
      { name: "Theme Development",                      id: "18" },
      { name: "Mozilla Add-ons Forum",                  id:  "!",
        url:  "https://forums.mozilla.org/addons/"               }
    ]
  },
  { name: "Development", id: "54",
    subs: [
      { name: "Mozilla Development",                    id: "27" },
      { name: "Web Development / Standards Evangelism", id: "25" },
      { name: "Third Party/Unofficial Builds",          id: "42" }
    ]
  },
  { name: "mozillaZine", id: "55",
    subs: [
      { name: "MozillaZine Site Discussion",            id: "11" },
      { name: "MozillaZine Tech",                       id: "37" },
      { name: "MozillaZine AfterDark",                  id: "22" },
      { name: "Locked Posts",                           id: "26" },
      { name: "About This User Script",                 id:  "?",
        url:  "http://userscripts.org/scripts/show/1455"         }
    ]
  }
]

for (let i = 0; i < forums.length; i++) {
  let sibling = linklist.querySelector(".rightside");
  let menu = addMenu(forums[i].name, forums[i].id, sibling);
  for (let j = 0; j < forums[i].subs.length; j++) {
    let submenu = menu.querySelector(".submenu");
    addSubMenu(forums[i].subs[j].name, forums[i].subs[j].id,
               submenu, forums[i].subs[j].url);
  }
}

function addMenu(aText, aId, aSibling) {
  let icon = setIconFromCurrent(".icon-home > strong > strong + a", aId);
  let menu = <li xmlns={htmlns} class={"icon-" + icon + " menu"}>
               <strong>
                 <a href={"/viewforum.php?f=" + aId}>{aText}</a>
               </strong>
               <ul class="submenu"></ul>
             </li>;
  return aSibling.parentNode.insertBefore(makeXML(menu), aSibling);
}

function addSubMenu(aText, aId, aParent, aExternal) {
  let external = (aExternal != null)
  let icon = setIconFromCurrent(".icon-home > strong > a:last-child", aId);
  let menu = <li xmlns={htmlns}
                 class={"icon-" + icon + (external ? " external" : "")}>
               <strong>
                 <a href={
                   external ? aExternal : ("/viewforum.php?f=" + aId)
                 }>{aText}</a>
               </strong>
             </li>;
  aParent.appendChild(makeXML(menu));
}

function setIconFromCurrent(aSelector, aId) {
  let icon = "";
  switch (aId) {
    case "!": icon = "logout"; break;
    case "?": icon = "faq"; break;
    default:  icon = "bump";
  }
  let current = document.querySelector(aSelector);
  if (current) {
    if (current.href.match(/\d+/) == aId) {
      icon = "subscribe";
    }
  }
  return icon;
}

function makeXML(aXML) {
  return (new DOMParser).parseFromString(new XML(aXML).toXMLString(),
                                         "application/xml")
                        .documentElement;
}