tftvfl

Minor tf.tv layout configurator

当前为 2015-01-13 提交的版本,查看 最新版本

  1. /*
  2. tftvfl
  3. Minor tf.tv layout configurator
  4. Copyright 2013 Alexander "Wareya" Nadeau <wareya@gmail.com>
  5. This software is provided 'as-is', without any express or implied
  6. warranty. In no event will the authors be held liable for any damages
  7. arising from the use of this software.
  8. Permission is granted to anyone to use this software and/or its source
  9. code for any purpose, including commercial applications, and to alter
  10. it and/or distribute it freely, subject to the following conditions:
  11. 1. The origin of the software must not be misrepresented.
  12. 1a. Modified versions of the software or its source code must
  13. not be misrepesented as the original version.
  14. 1b. Acknowledgment of use or modification of the software
  15. or its source code is appreciated but not required.
  16. 2. This notice may not be removed from, or altered in, any source
  17. distribution of the software.
  18. 2a. This notice is not required to be included in any compiled
  19. distribution of the software, as long as said distribution
  20. does not constitute a source distribution.
  21. */
  22.  
  23. // ==UserScript==
  24. // @name tftvfl
  25. // @version 0.01
  26. // @namespace wareya
  27. // @description Minor tf.tv layout configurator
  28. // @include http://teamfortress.tv/*
  29. // @grant none
  30. // ==/UserScript==
  31.  
  32.  
  33. /* change these values between true or false to enable/disable individual features of the plugin */
  34.  
  35. // whether the sidebar is toggle-able off of the main page
  36. var togglebar_enabled = true;
  37. // whether the global "Threads" link is enabled
  38. var globalallthreads_enabled = true;
  39.  
  40. // whether to move a given left bar entry to the right bar
  41. var move_news = false;
  42. var move_schedule = false;
  43. var move_activity = true;
  44.  
  45.  
  46. /* bulk of the script (don't modify this unless you know what you're doing */
  47.  
  48. // helper function (why javascript why don't NodeLists act like arrays)
  49. function map(nodes, func)
  50. {
  51. for (var i = 0; i < nodes.length; ++i)
  52. func(nodes[i]);
  53. }
  54. function setopenspan()
  55. {
  56. localStorage.setItem("tftvbar/closed", "false");
  57. var barstuff = document.getElementById("col-left");
  58. var colstuff = document.getElementById("col-center");
  59. colstuff.style.marginLeft = "0";
  60. colstuff.style.width = "700px";
  61. barstuff.style.display = "";
  62. if(document.getElementById("closer") != null)
  63. document.getElementById("closer").parentNode.removeChild(document.getElementById("closer"));
  64. // make temp element to get things from it
  65. var content = document.getElementById("content");
  66. content.innerHTML = "\
  67. \<span id='closer' onclick='setclosedspan();' style='font-family:arial; float:right; position: absolute; top: 5px; left: 20px; z-index: 2;'>\
  68. [<]\
  69. </span>"
  70. + content.innerHTML;
  71. }
  72. function setclosedspan()
  73. {
  74. localStorage.setItem("tftvbar/closed", "true");
  75. var barstuff = document.getElementById("col-left");
  76. var colstuff = document.getElementById("col-center");
  77. colstuff.style.marginLeft = "-185px";
  78. colstuff.style.width = "885px";
  79. barstuff.style.display = "none";
  80. if(document.getElementById("closer") != null)
  81. document.getElementById("closer").parentNode.removeChild(document.getElementById("closer"));
  82. // make temp element to get things from it
  83. var content = document.getElementById("content");
  84. content.innerHTML = "\
  85. \<span id='closer' onclick='setopenspan();' style='font-family:arial; float:right; position: absolute; top: 5px; left: 20px; z-index: 2;'>\
  86. [>]\
  87. </span>"
  88. + content.innerHTML;
  89. }
  90.  
  91. if(togglebar_enabled)
  92. {
  93. var script = document.body.appendChild(document.createElement("script"));
  94. script.type = "text/javascript";
  95. script.id = "userscript funcs / wareya";
  96. script.innerHTML = map.toString() + setopenspan.toString() + "\n" + setclosedspan.toString() + "\n" + "\n";
  97. if (localStorage.getItem("tftvbar/closed") != "true")
  98. setopenspan();
  99. else
  100. setclosedspan();
  101. }
  102.  
  103.  
  104.  
  105. if(globalallthreads_enabled)
  106. {
  107. // "nav" center <nav> Forums
  108. document.getElementById("nav").children[0].children[0].children[1].outerHTML += '\
  109. <div class="nav-item-wrapper distinct noselect">\
  110. <a href="/active" class="bbox nav-item ">\
  111. All Threads\
  112. </a>\
  113. </div>';
  114. }
  115.  
  116. // In reverse order so that appending is trivial
  117. if(move_activity)
  118. {
  119. document.getElementById("col-left").children[2].style.marginTop = "2px";
  120. document.getElementById("col-right").children[2].outerHTML +=
  121. document.getElementById("col-left").children[2].outerHTML;
  122. document.getElementById("col-left").children[2].outerHTML = "";
  123. }
  124. if(move_schedule)
  125. {
  126. document.getElementById("col-left").children[1].style.marginTop = "2px";
  127. document.getElementById("col-right").children[2].outerHTML +=
  128. document.getElementById("col-left").children[1].outerHTML;
  129. document.getElementById("col-left").children[1].outerHTML = "";
  130. }
  131. if(move_news)
  132. {
  133. document.getElementById("col-left").children[0].style.marginTop = "2px";
  134. document.getElementById("col-right").children[2].outerHTML +=
  135. document.getElementById("col-left").children[0].outerHTML;
  136. document.getElementById("col-left").children[0].outerHTML = "";
  137. }