Proxer-Subs/Scans -- UserScript

Dieses Script verbessert die User-Freundlichkeit der "Meine-Projekte" Liste

目前為 2015-07-21 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Proxer-Subs/Scans -- UserScript
  3. // @namespace
  4. // @version 1.5.2
  5. // @description Dieses Script verbessert die User-Freundlichkeit der "Meine-Projekte" Liste
  6. // @author Dominik Bissinger alias Nihongasuki
  7. // @include http://proxer.me/*
  8. // @include https://proxer.me/*
  9. // @include http://www.proxer.me/*
  10. // @include https://www.proxer.me/*
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. //Run main after page load and add Eventlistener for AJAX Events
  15. document.addEventListener('DOMContentLoaded', function(event) {
  16. $(document).ajaxSuccess (function () {
  17. main();
  18. });
  19. main();
  20. });
  21.  
  22. //Main Funktion
  23. var table = [];
  24. var main = function () {
  25. //Check if correct Location to run
  26. if (window.location.href.indexOf('subs?s=my') === -1 || window.location.href.indexOf('forum') > -1) {return;};
  27. //Check if Tool already ran
  28. if (document.getElementsByClassName('scriptButton').length !== 0) {return;};
  29. //create new Style Element to set the buttons general Style
  30. var style = document.createElement('style');
  31. style.innerHTML = "\
  32. .scriptButton {\
  33. height: 20px; \
  34. border-style: solid;\
  35. border-width: 1px; \
  36. padding: 5px; \
  37. border-radius: 10px;\
  38. }\
  39. ";
  40. document.head.appendChild(style);
  41. //get importat Elements and create Variables
  42. var inner = document.getElementsByClassName('inner')[0];
  43. var div = inner.getElementsByTagName('div');
  44. table = [];
  45. var a = [];
  46. //create Wrapper (for easier programming)
  47. var wrapper = document.createElement('span');
  48. wrapper.setAttribute ("id","releaseWrapper");
  49. inner.insertBefore(wrapper,div[0]);
  50. //loop through all Entries
  51. for (var i = 0; i < div.length; i++) {
  52. //move div into wrapper
  53. wrapper.appendChild(div[i]);
  54. //give div ID
  55. div[i].setAttribute("id","divID"+i)
  56. //get Links InnerHTML
  57. a[i] = div[i].getElementsByTagName('a')[0].innerHTML;
  58. //Remove Table
  59. table[i] = div[i].getElementsByTagName('table')[0];
  60. table[i].style.display = "none";
  61. //Create Button and Image
  62. var hr = div[i].getElementsByTagName('hr')[0];
  63. var br = document.createElement('br');
  64. var newSpan = document.createElement('span');
  65. var img = document.createElement('img');
  66. //Set Image Attributes
  67. img.setAttribute ("class","scriptButton");
  68. img.setAttribute ("id","showState"+i);
  69. img.setAttribute ("style","display: inline; position: relative; top: 10px; left: 15px;");
  70. if (div[i].getElementsByClassName('nextState').length !== 0 || div[i].getElementsByClassName('prevState').length !== 0) {
  71. img.src = "/images/misc/offlineicon.png";
  72. }else{
  73. img.src = "/images/misc/onlineicon.png";
  74. };
  75. //set Button Attributes
  76. newSpan.setAttribute ("class","scriptButton");
  77. newSpan.setAttribute ("id","hideButton"+i);
  78. newSpan.setAttribute ("style","cursor: pointer; display: inline; position: relative; left: 10px;");
  79. newSpan.innerHTML = "Tabelle anzeigen";
  80. //add Button and Image to Page
  81. div[i].insertBefore(newSpan,hr);
  82. div[i].insertBefore(img,hr);
  83. div[i].appendChild(br);
  84. //addEventListeners
  85. document.getElementById('hideButton'+i).addEventListener("click",function () {
  86. showHide(this.id);
  87. })
  88. };
  89. //Create Groups by Project
  90. var projects = [];
  91. var z = 0;
  92. inner.getElementsByTagName('h3')[0].innerHTML = "Projekte";
  93. for (var i = 0; i < a.length; i++) {
  94. a[i] = a[i].substring(0,a[i].length-2);
  95. if (projects.length === 0) {
  96. projects[z] = a[i];
  97. z++;
  98. }else{
  99. var x = 0;
  100. for (var j = 0; j < projects.length; j++) {
  101. if (a[i] !== projects[j]) {
  102. x++;
  103. };
  104. if (x === projects.length) {
  105. projects[z] = a[i];
  106. z++;
  107. };
  108. };
  109. };
  110. };
  111. for (var i = 0; i < projects.length; i++) {
  112. var br = document.createElement('br');
  113. var hr = document.createElement('hr');
  114. var pButton = document.createElement('span');
  115. var img = document.createElement('img');
  116. //Set Image Attributes
  117. img.setAttribute ("class","scriptButton");
  118. img.setAttribute ("id","showProjectState"+i);
  119. img.setAttribute ("style","display: inline; position: relative; top: 10px; left: 5px;");
  120. pButton.setAttribute ("class","scriptButton");
  121. pButton.setAttribute ("id","projectButton"+i);
  122. pButton.setAttribute ("style","cursor: pointer; display: inline;");
  123. pButton.innerHTML = projects[i].substring(0,projects[i].length-16);
  124. wrapper.appendChild(pButton);
  125. wrapper.appendChild(img);
  126. wrapper.appendChild(hr);
  127. wrapper.appendChild(br);
  128. var x = 0;
  129. for (var j = 0; j < div.length; j++) {
  130. var newDiv = document.getElementById('divID'+j);
  131. var a = newDiv.getElementsByTagName('a')[0].innerHTML;
  132. a = a.substring(0,a.length-2);
  133. if (a === projects[i]) {
  134. if (newDiv.getElementsByClassName('nextState').length !== 0 || newDiv.getElementsByClassName('prevState').length !== 0) {
  135. x = 1;
  136. };
  137. newDiv.style.display = "none";
  138. newDiv.setAttribute("class","project"+i);
  139. wrapper.insertBefore(newDiv,pButton);
  140. };
  141. };
  142. if (x === 1) {
  143. img.src = "/images/misc/offlineicon.png";
  144. }else{
  145. img.src = "/images/misc/onlineicon.png";
  146. };
  147. document.getElementById('projectButton'+i).addEventListener("click",function () {
  148. showHideProject(this.id);
  149. })
  150. };
  151. //setStyle of Buttons
  152. var color = "";
  153. var setStyle = function () {
  154. for (var i = 0; i < 4; i++) {
  155. if (color === "gray") {
  156. var buttons = document.getElementsByClassName('scriptButton');
  157. for (var j = 0; j < buttons.length; j++) {
  158. buttons[j].style.backgroundColor = "#5E5E5E";
  159. buttons[j].style.borderColor = "#FFF";
  160. };
  161. }else if (color === "black") {
  162. var buttons = document.getElementsByClassName('scriptButton');
  163. for (var j = 0; j < buttons.length; j++) {
  164. buttons[j].style.backgroundColor = "#000";
  165. buttons[j].style.borderColor = "#FFF";
  166. };
  167. }else if (color === "old_blue") {
  168. var buttons = document.getElementsByClassName('scriptButton');
  169. for (var j = 0; j < buttons.length; j++) {
  170. buttons[j].style.backgroundColor = "#F3FBFF";
  171. buttons[j].style.borderColor = "#000";
  172. };
  173. }else{
  174. var buttons = document.getElementsByClassName('scriptButton');
  175. for (var j = 0; j < buttons.length; j++) {
  176. buttons[j].style.backgroundColor = "#F3FBFF";
  177. buttons[j].style.borderColor = "#000";
  178. };
  179. };
  180. };
  181. };
  182. //Read Cookie
  183. var name = "style=";
  184. var cookieCheck = function () {
  185. var ca = document.cookie.split(';');
  186. for (var i = 0; i < ca.length; i++) {
  187. var c = ca[i];
  188. while (c.charAt(0) === " ") {
  189. c = c.substring(1);
  190. };
  191. if (c.indexOf(name) == 0) {
  192. color = c.substring(name.length,c.length);
  193. setStyle();
  194. };
  195. };
  196. if (color === "") {
  197. cookieCheck();
  198. };
  199. };
  200. cookieCheck();
  201. };
  202.  
  203. //Zeige/Verstecke eine Tabelle
  204. var showHide = function (id) {
  205. var i = id.substring(10);
  206. if (table[i].style.display === "none") {
  207. table[i].style.display = "inline";
  208. document.getElementById(id).innerHTML = "Tabelle ausblenden";
  209. document.getElementById(id).style.left = "0px";
  210. document.getElementById("showState"+i).style.display = "none";
  211. }else{
  212. table[i].style.display = "none";
  213. document.getElementById(id).innerHTML = "Tabelle anzeigen";
  214. document.getElementById(id).style.left = "10px";
  215. document.getElementById("showState"+i).style.display = "inline";
  216. };
  217. };
  218.  
  219. //Zeige/Verstecke gruppierte Projekte
  220. var showHideProject = function (id) {
  221. var i = id.substring(13);
  222. var wrapper = document.getElementById('releaseWrapper');
  223. var contents = wrapper.getElementsByClassName('project'+i);
  224. for (var j = 0; j < contents.length; j++) {
  225. if (contents[j].style.display === "none") {
  226. contents[j].style.display = "block";
  227. document.getElementById('projectButton'+i).style.borderWidth = "3px";
  228. }else{
  229. contents[j].style.display = "none";
  230. document.getElementById('projectButton'+i).style.borderWidth = "1px";
  231. };
  232. };
  233. };