Proxer-Subs/Scans -- UserScript

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

  1. // ==UserScript==
  2. // @name Proxer-Subs/Scans -- UserScript
  3. // @namespace
  4. // @version 1.5.4
  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. buildGroups(inner,a,wrapper,div);
  91. //setStyle of Buttons
  92. var color = "";
  93. var setStyle = function () {
  94. for (var i = 0; i < 4; i++) {
  95. if (color === "gray") {
  96. var buttons = document.getElementsByClassName('scriptButton');
  97. for (var j = 0; j < buttons.length; j++) {
  98. buttons[j].style.backgroundColor = "#5E5E5E";
  99. buttons[j].style.borderColor = "#FFF";
  100. };
  101. }else if (color === "black") {
  102. var buttons = document.getElementsByClassName('scriptButton');
  103. for (var j = 0; j < buttons.length; j++) {
  104. buttons[j].style.backgroundColor = "#000";
  105. buttons[j].style.borderColor = "#FFF";
  106. };
  107. }else if (color === "old_blue") {
  108. var buttons = document.getElementsByClassName('scriptButton');
  109. for (var j = 0; j < buttons.length; j++) {
  110. buttons[j].style.backgroundColor = "#F3FBFF";
  111. buttons[j].style.borderColor = "#000";
  112. };
  113. }else{
  114. var buttons = document.getElementsByClassName('scriptButton');
  115. for (var j = 0; j < buttons.length; j++) {
  116. buttons[j].style.backgroundColor = "#F3FBFF";
  117. buttons[j].style.borderColor = "#000";
  118. };
  119. };
  120. };
  121. };
  122. //Read Cookie
  123. var name = "style=";
  124. var cookieCheck = function () {
  125. var ca = document.cookie.split(';');
  126. for (var i = 0; i < ca.length; i++) {
  127. var c = ca[i];
  128. while (c.charAt(0) === " ") {
  129. c = c.substring(1);
  130. };
  131. if (c.indexOf(name) == 0) {
  132. color = c.substring(name.length,c.length);
  133. setStyle();
  134. };
  135. };
  136. if (color === "") {
  137. cookieCheck();
  138. };
  139. };
  140. cookieCheck();
  141. };
  142.  
  143. //Gruppiere Einträge
  144. var buildGroups = function (inner,a,wrapper,div) {
  145. var projects = [];
  146. var z = 0;
  147. inner.getElementsByTagName('h3')[0].innerHTML = "Projekte";
  148. for (var i = 0; i < a.length; i++) {
  149. var num = a[i].match(/\d+/g);
  150. var int = num[num.length-1];
  151. if (int > 99) {
  152. int = 2;
  153. } else if (int > 9) {
  154. int = 1;
  155. } else {
  156. int = 0;
  157. };
  158. a[i] = a[i].substring(0,a[i].length-2-int);
  159. if (projects.length === 0) {
  160. projects[z] = a[i];
  161. z++;
  162. }else{
  163. var x = 0;
  164. for (var j = 0; j < projects.length; j++) {
  165. if (a[i] !== projects[j]) {
  166. x++;
  167. };
  168. if (x === projects.length) {
  169. projects[z] = a[i];
  170. z++;
  171. };
  172. };
  173. };
  174. };
  175. for (var i = 0; i < projects.length; i++) {
  176. var br = document.createElement('br');
  177. var hr = document.createElement('hr');
  178. var pButton = document.createElement('span');
  179. var img = document.createElement('img');
  180. //Set Image Attributes
  181. img.setAttribute ("class","scriptButton");
  182. img.setAttribute ("id","showProjectState"+i);
  183. img.setAttribute ("style","display: inline; position: relative; top: 10px; left: 5px;");
  184. pButton.setAttribute ("class","scriptButton");
  185. pButton.setAttribute ("id","projectButton"+i);
  186. pButton.setAttribute ("style","cursor: pointer; display: inline;");
  187. pButton.innerHTML = projects[i].substring(0,projects[i].length-16);
  188. wrapper.appendChild(pButton);
  189. wrapper.appendChild(img);
  190. wrapper.appendChild(hr);
  191. wrapper.appendChild(br);
  192. var x = 0;
  193. for (var j = 0; j < div.length; j++) {
  194. var newDiv = document.getElementById('divID'+j);
  195. var a = newDiv.getElementsByTagName('a')[0].innerHTML;
  196. var num = a.match(/\d+/g);
  197. var int = num[num.length-1];
  198. if (int > 99) {
  199. int = 2;
  200. } else if (int > 9) {
  201. int = 1;
  202. } else {
  203. int = 0;
  204. };
  205. a = a.substring(0,a.length-2-int);
  206. if (a === projects[i]) {
  207. if (newDiv.getElementsByClassName('nextState').length !== 0 || newDiv.getElementsByClassName('prevState').length !== 0) {
  208. x = 1;
  209. };
  210. newDiv.style.display = "none";
  211. newDiv.setAttribute("class","project"+i);
  212. wrapper.insertBefore(newDiv,pButton);
  213. };
  214. };
  215. if (x === 1) {
  216. img.src = "/images/misc/offlineicon.png";
  217. }else{
  218. img.src = "/images/misc/onlineicon.png";
  219. };
  220. document.getElementById('projectButton'+i).addEventListener("click",function () {
  221. showHideProject(this.id);
  222. })
  223. };
  224. };
  225.  
  226. //Zeige/Verstecke eine Tabelle
  227. var showHide = function (id) {
  228. var i = id.substring(10);
  229. var button = document.getElementById(id);
  230. if (table[i].style.display === "none") {
  231. table[i].style.display = "inline";
  232. var br = document.createElement('br');
  233. button.innerHTML = "Tabelle ausblenden";
  234. button.style.left = "0px";
  235. button.parentNode.insertBefore(br,button)
  236. document.getElementById("showState"+i).style.display = "none";
  237. }else{
  238. table[i].style.display = "none";
  239. var parent = button.parentNode;
  240. var br = parent.getElementsByTagName('br');
  241. br = br[br.length-2];
  242. button.innerHTML = "Tabelle anzeigen";
  243. button.style.left = "10px";
  244. parent.removeChild(br);
  245. document.getElementById("showState"+i).style.display = "inline";
  246. };
  247. };
  248.  
  249. //Zeige/Verstecke gruppierte Projekte
  250. var showHideProject = function (id) {
  251. var i = id.substring(13);
  252. var wrapper = document.getElementById('releaseWrapper');
  253. var contents = wrapper.getElementsByClassName('project'+i);
  254. for (var j = 0; j < contents.length; j++) {
  255. if (contents[j].style.display === "none") {
  256. contents[j].style.display = "block";
  257. document.getElementById('projectButton'+i).style.borderWidth = "3px";
  258. }else{
  259. contents[j].style.display = "none";
  260. document.getElementById('projectButton'+i).style.borderWidth = "1px";
  261. };
  262. };
  263. };