USO Links

Add's shortcuts links to the login status bar.

  1. // ==UserScript==
  2. // @name USO Links
  3. // @namespace http://userscripts.org/users/tim
  4. // @description Add's shortcuts links to the login status bar.
  5. // @include http://userscripts.org/*
  6. // @include https://userscripts.org/*
  7. // @license MIT (See file header)
  8. // @copyright (c) 2011 Tim Smart
  9. // @version 0.0.1.20140425034614
  10. // ==/UserScript==
  11.  
  12. // Permission is hereby granted, free of charge, to any person obtaining a
  13. // copy of this software and associated documentation files
  14. // (the "Software"), to deal in the Software without restriction,
  15. // including without limitation the rights to use, copy, modify, merge,
  16. // publish, distribute, sublicense, and/or sell copies of the Software, and
  17. // to permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be included
  21. // in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  27. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  28. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  29. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30.  
  31. ;(function () {
  32.  
  33. var LINKS =
  34. { 'New Script' : '/scripts/new'
  35. , 'Manage Scripts' : '/home/scripts'
  36. , 'Favorites' : '/home/favorites'
  37. , 'Comments' : '/home/comments'
  38. , 'Topics' : '/home/posts'
  39. , 'Settings' : '/home/settings'
  40. }
  41.  
  42. /**
  43. * Creates a <li> with a link.
  44. *
  45. * @param {String} name
  46. * @param {String} path
  47. * @return {HtmlElement}
  48. */
  49. function createLink (name, path) {
  50. var li = document.createElement('li')
  51. , a = document.createElement('a')
  52.  
  53. a.setAttribute('style', 'font-weight: normal;')
  54. a.setAttribute('href', path)
  55. a.textContent = name
  56.  
  57. li.appendChild(a)
  58.  
  59. return li
  60. }
  61.  
  62. // Check for the /home link
  63. var home = document.evaluate(
  64. './/ul[@class="login_status"]/li/a[@href="/home"]'
  65. , document
  66. , null
  67. , XPathResult.FIRST_ORDERED_NODE_TYPE
  68. , null
  69. )
  70. .singleNodeValue
  71.  
  72. var first = true
  73. var name = null
  74. var link = null
  75.  
  76. // The user is not logged in
  77. if (!home) {
  78. return
  79. }
  80.  
  81. home = home.parentNode
  82.  
  83. // Logged in, and ready for awesome.
  84. for (name in LINKS) {
  85. link = createLink(name, LINKS[name])
  86. if (first === false) {
  87. link.style.marginLeft = '0.5em'
  88. }
  89. first = false
  90.  
  91. home.parentNode.insertBefore(link, home.nextSibling)
  92. home = link
  93. }
  94.  
  95. })();