Advertisement
thetenfold

USO-Admin-menu_JoeSimmons-edits

Jul 7th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          USO Admin Menu
  3. // @namespace     erosman
  4. // @description   Adds Edit Metadata & Edit Code to the Script Menu
  5. // @updateURL     https://userscripts.org/scripts/source/172351.meta.js
  6. // @downloadURL   https://userscripts.org/scripts/source/172351.user.js
  7. // @include       http://userscripts.org/scripts/*
  8. // @include       https://userscripts.org/scripts/*
  9. // @grant         none
  10. // @author        erosman
  11. // @version       1.0
  12. // ==/UserScript==
  13.  
  14. /* --------- Note ---------
  15.   This script adds Edit Metadata & Edit Code to the Script Menu
  16.  
  17.  
  18.  
  19.   --------- History ---------
  20.  
  21.  
  22.   1.0 Initial release
  23.  
  24. */
  25.  
  26.  
  27.  
  28. (function name() { // anonymous function wrapper, used for error checking to end execution
  29.  
  30. "use strict";
  31.  
  32. if(window.self !== window.top) return; // end execution if in a frame
  33.  
  34. var nav = document.evaluate("//ul[@id='script-nav']/li/a[.='Admin']/../..", document.body, null, 9, null).singleNodeValue, // grab the #script-nav while checking for the Admin link to be existing
  35.     tmpNav = document.createDocumentFragment(), // create a temporary document fragment
  36.     scriptID = (document.location.href.match(/\/(\d+)/) || ["",""])[1], // grab script ID with RegExp
  37.     extra, i, li;
  38.  
  39. // quit if Admin link not found or script ID not found in url
  40. if(!nav || !scriptID) return;
  41.  
  42. // set which links to be added here
  43. extra = {
  44.   'Edit Code' : '/scripts/edit_src/',
  45.   'Edit Metadata' : '/scripts/edit/'
  46. };
  47.  
  48. // loop through the to-be-added-links and add them to the temporary document fragment
  49. for (i in extra) {
  50.  
  51.     // create a list element with an anchor node
  52.     li = document.createElement('li');
  53.     li.className = 'menu';
  54.     li.innerHTML = '<a href="'+ extra[i] + scriptID + '" class="admin">' + i + '</a>';
  55.  
  56.     // add the link to the document fragment
  57.     tmpNav.appendChild(li);
  58.  
  59. }
  60.  
  61. // add the document fragment to the page
  62. nav.insertBefore(tmpNav, nav.children[1]);
  63.  
  64.  
  65. })(); // end of anonymous function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement