This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 7.88 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License
  5.  * Version 1.1 (the "License"); you may not use this file except in
  6.  * compliance with the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/1.1/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozillaZine Forums Menu user script.
  15.  *
  16.  * The Initial Developer of the Original Code is LouCypher.
  17.  * Portions created by the Initial Developer are Copyright (C) 2011
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s)
  21.  * - LouCypher <loucypher@mozillaca.com>
  22.  *
  23.  * ***** END LICENSE BLOCK ***** */
  24.  
  25. // ==UserScript==
  26. // @name            mozillaZine Forums Menu
  27. // @namespace       http://mozilla.status.net/loucypher
  28. // @description     Navigation menu for mozillaZine Forums
  29. // @icon            http://i.imgur.com/01UZS.png
  30. // @version         2.4
  31. // @author          LouCypher
  32. // @license         MPL 1.1
  33. // @include         http://forums.mozillazine.org/*
  34. // ==/UserScript==
  35.  
  36. /*
  37.     Changelog:
  38.       * 2011-07-21:
  39.         + Added links to official forums for Firefox/Thunderbird/mobile
  40.         * Cosmetic changes
  41.       * 2011-07-19:
  42.         + Added link to this user script at userscripts.org
  43.         x Cosmetic changes
  44.       * 2011-07-18: Version 2.0
  45.       * 2006-07-31: Updated to new layout
  46.       * 2006-06-20: Added new forum and new forum category
  47.       * 2006-06-12: Rearrange
  48.       * 2005-08-13: Rearrange
  49.       * 2005-08-08:
  50.         - Fixed menu positions
  51.         - Added index to insertMenu function
  52.         - Added User Links menu
  53. */
  54.  
  55. var linklist = document.querySelector("#page-header .linklist");
  56. if (!linklist) return;
  57.  
  58. const htmlns = "http://www.w3.org/1999/xhtml";
  59.  
  60. GM_addStyle("\
  61.   #page-header .linklist .icon-home, .menu .submenu {\
  62.     display: none;\
  63.   }\
  64.   .menu { padding: 1px .5em 0 17px; }\
  65.   .menu .submenu {\
  66.     border: 1px solid #027ab7;\
  67.     /*border-top-width: 0;*/\
  68.     background-color: rgb(202, 220, 235);\
  69.     padding: 0 0 .5em .5em;\
  70.     margin-left: -2em;\
  71.     position: absolute;\
  72.     z-index: 3;\
  73.   }\
  74.   .menu.icon-subscribe {\
  75.     background-position: .5em 50%;\
  76.     background-color: white;\
  77.     box-shadow: inset 1px 1px 2px rgba(0, 0, 0, .5);\
  78.     padding-left: 2em;\
  79.   }\
  80.   .menu .submenu, .menu:hover {\
  81.     box-shadow: 3px 3px 3px rgba(0, 0, 0, .5);\
  82.   }\
  83.   .menu:hover .submenu, .submenu li a { display: block; }\
  84.   .menu:hover, .submenu li:hover { background-color: #027ab7; }\
  85.   .menu a:hover { text-decoration: none; }\
  86.   .menu:hover, .menu:hover > strong > a, \
  87.   .submenu li:hover a, .submenu a:hover { color: white; }\
  88.   .submenu li { float: none !important; padding-right: .5em; }\
  89.   .menu a:-moz-focusring { outline: none; }\
  90.   .submenu a { padding: 0 .5em; }\
  91.   .submenu li.external { border-top: 2px groove rgba(202, 220, 235, .5); }\
  92. ");
  93.  
  94. var forums = [
  95.   { name: "Firefox", id: "49",
  96.     subs: [
  97.       { name: "Firefox Support",                        id: "38" },
  98.       { name: "Firefox General",                        id:  "7" },
  99.       { name: "Firefox Builds",                         id: "23" },
  100.       { name: "Firefox Features",                       id:  "8" },
  101.       { name: "Firefox Bugs",                           id:  "9" },
  102.       { name: "Official Forum",                         id:  "!",
  103.         url:  "https://support.mozilla.com/"                     }
  104.     ]
  105.   },
  106.   { name: "Thunderbird", id: "50",
  107.     subs: [
  108.       { name: "Thunderbird Support",                    id: "39" },
  109.       { name: "Thunderbird General",                    id: "28" },
  110.       { name: "Thunderbird Builds",                     id: "29" },
  111.       { name: "Thunderbird Features",                   id: "30" },
  112.       { name: "Thunderbird Bugs",                       id: "31" },
  113.       { name: "Official Forum",                         id: "!",
  114.         url:  "http://support.mozillamessaging.com/"             }
  115.     ]
  116.    },
  117.   { name: "SeaMonkey", id: "51",
  118.     subs: [
  119.       { name: "SeaMonkey Support",                      id: "40" },
  120.       { name: "SeaMonkey General",                      id:  "3" },
  121.       { name: "SeaMonkey Builds",                       id:  "6" },
  122.       { name: "SeaMonkey Features",                     id:  "4" },
  123.       { name: "SeaMonkey Bugs",                         id:  "5" }
  124.     ]
  125.   },
  126.   { name: "Others", id: "52",
  127.     subs: [
  128.       { name: "Camino",                                 id: "12" },
  129.       { name: "Calendar",                               id: "46" },
  130.       { name: "Mobile",                                 id: "47" },
  131.       { name: "Miscellaneous Support",                  id: "32" },
  132.       { name: "Other Applications and Distributions",   id: "34" },
  133.       { name: "Official Mobile Forum",                  id:  "!",
  134.         url:  "https://support.mozilla.com/mobile"               }
  135.     ]
  136.   },
  137.   { name: "Add-ons", id: "53",
  138.     subs: [
  139.       { name: "Extension/Theme Releases",               id: "48" },
  140.       { name: "Extension Development",                  id: "19" },
  141.       { name: "Theme Development",                      id: "18" },
  142.       { name: "Mozilla Add-ons Forum",                  id:  "!",
  143.         url:  "https://forums.mozilla.org/addons/"               }
  144.     ]
  145.   },
  146.   { name: "Development", id: "54",
  147.     subs: [
  148.       { name: "Mozilla Development",                    id: "27" },
  149.       { name: "Web Development / Standards Evangelism", id: "25" },
  150.       { name: "Third Party/Unofficial Builds",          id: "42" }
  151.     ]
  152.   },
  153.   { name: "mozillaZine", id: "55",
  154.     subs: [
  155.       { name: "MozillaZine Site Discussion",            id: "11" },
  156.       { name: "MozillaZine Tech",                       id: "37" },
  157.       { name: "MozillaZine AfterDark",                  id: "22" },
  158.       { name: "Locked Posts",                           id: "26" },
  159.       { name: "About This User Script",                 id:  "?",
  160.         url:  "http://userscripts.org/scripts/show/1455"         }
  161.     ]
  162.   }
  163. ]
  164.  
  165. for (var i = 0; i < forums.length; i++) {
  166.   let sibling = linklist.querySelector(".rightside");
  167.   let menu = addMenu(forums[i].name, forums[i].id, sibling);
  168.   for (var j = 0; j < forums[i].subs.length; j++) {
  169.     let submenu = menu.querySelector(".submenu");
  170.     addSubMenu(forums[i].subs[j].name, forums[i].subs[j].id,
  171.                submenu, forums[i].subs[j].url);
  172.   }
  173. }
  174.  
  175. function addMenu(aText, aId, aSibling) {
  176.   let icon = setIconFromCurrent(".icon-home > strong > strong + a", aId);
  177.   let menu = <li xmlns={htmlns} class={"icon-" + icon + " menu"}>
  178.                <strong>
  179.                  <a href={"/viewforum.php?f=" + aId}>{aText}</a>
  180.                </strong>
  181.                <ul class="submenu"></ul>
  182.              </li>;
  183.   return aSibling.parentNode.insertBefore(makeXML(menu), aSibling);
  184. }
  185.  
  186. function addSubMenu(aText, aId, aParent, aExternal) {
  187.   let external = (aExternal != null)
  188.   let icon = setIconFromCurrent(".icon-home > strong > a:last-child", aId);
  189.   let menu = <li xmlns={htmlns}
  190.                  class={"icon-" + icon + (external ? " external" : "")}>
  191.                <strong>
  192.                  <a href={
  193.                    external ? aExternal : ("/viewforum.php?f=" + aId)
  194.                  }>{aText}</a>
  195.                </strong>
  196.              </li>;
  197.   aParent.appendChild(makeXML(menu));
  198. }
  199.  
  200. function setIconFromCurrent(aSelector, aId) {
  201.   let icon = "";
  202.   switch (aId) {
  203.     case "!": icon = "logout"; break;
  204.     case "?": icon = "faq"; break;
  205.     default:  icon = "bump";
  206.   }
  207.   let current = document.querySelector(aSelector);
  208.   if (current) {
  209.     if (current.href.match(/\d+/) == aId) {
  210.       icon = "subscribe";
  211.     }
  212.   }
  213.   return icon;
  214. }
  215.  
  216. function makeXML(aXML) {
  217.   return (new DOMParser).parseFromString(new XML(aXML).toXMLString(),
  218.                                          "application/xml")
  219.                         .documentElement;
  220. }
clone this paste RAW Paste Data