Starlog Manager

Starlog addon

  1. // ==UserScript==
  2. // @name Starlog Manager
  3. // @namespace Odahviing
  4. // @author Odahviing
  5. // @include http://www.war-facts.com/starlog.php*
  6. // @include http://www.war-facts.com/player.php
  7. // @version 2.2
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @description Starlog addon
  11. // ==/UserScript==
  12.  
  13. // Version 1.0 - Inital Script - Player filter + Real Time
  14. // Version 1.1 - Minor Changes on menus
  15. // Version 1.11 - Bug fix - not showing "hour"
  16. // Version 2.0 - Major upgrade: Remove starlog text with + button, rewrite the script
  17. // Version 2.1 - Bug fix - not showing all player messages
  18. // Version 2.11+ - Updates on Greasy Fork
  19.  
  20. // Features So Far
  21. // --- Ability to filter with "player" messages only
  22. // --- Show/Hide stargroup long tezxt
  23. // --- Ability to filter with "starlog" messages only
  24.  
  25.  
  26. main();
  27.  
  28. function main()
  29. {
  30. // Loading Groups Data
  31. if (document.URL.indexOf("player.php") != -1)
  32. {
  33. saveGroups();
  34. }
  35. addingButtons(); // Make the new menu
  36. //addStarlogGroupsBoxs(); // Add buttons to filter by each group
  37.  
  38. var index = document.URL.indexOf("?");
  39. if (index != -1)
  40. {
  41. var requestType = document.URL.substring(index + 1);
  42. requestType = requestType.replace("offset=100", "");
  43. if (requestType == "type=2") // Show Stargroup Option
  44. {
  45. removeSinglePlayerMessages();
  46. }
  47. else if (requestType == "type=2&extra=1") // Show Player Option
  48. {
  49. showOnlyPlayerMessages();
  50. }
  51. // Not Active Option
  52. else if (requestType == ""){}
  53. else if (requestType.indexOf("#") == -1)
  54. {
  55. // removeSinglePlayerMessages();
  56. // keepOnlyGroup(getType.substring(getType.indexOf("#") +1));
  57. }
  58. }
  59. else
  60. {
  61. removeStarlogText();
  62. var allExplore = document.getElementsByClassName('fullwidth dark tbborder starlog_explore');
  63. for (let index = 0 ; index < allExplore.length; index++)
  64. allExplore[index].style.display = "none";
  65. }
  66. addRealDates(); // Add real time dates to messages
  67. }
  68.  
  69. /* Load Functions */
  70.  
  71. function saveGroups()
  72. {
  73. var groupsNames = document.getElementsByName('editstarloggroupname');
  74. var groupsId = document.getElementsByName('editstarloggroup');
  75. var arrayList = [];
  76. for (var index = 0 ; index < groupsNames.length; index ++)
  77. {
  78. var newItem = [groupsId[index].value, groupsNames[index].value];
  79. arrayList.push(newItem);
  80. }
  81. GM_setValue("stargroupNames", arrayList);
  82. }
  83.  
  84. function addingButtons()
  85. {
  86. // Make Player button
  87. var newLink = document.createElement('a');
  88. newLink.setAttribute('class', "darkbutton smalltext");
  89. newLink.innerHTML = "Player";
  90. newLink.addEventListener("click", loadOnlyPlayer);
  91. // Add it
  92. var linksObject = document.getElementsByClassName('left starlog_right box dark padding5 minheight60')[0];
  93. linksObject.insertBefore(newLink, linksObject.firstChild);
  94.  
  95. var outbox = linksObject.children[3];
  96. linksObject.insertBefore(outbox, null);
  97. outbox = linksObject.children[3];
  98. linksObject.insertBefore(outbox, null);
  99.  
  100. linksObject.children[1].innerHTML = "Stargroup";
  101. }
  102.  
  103. // Based of guardian21 script
  104. function addRealDates()
  105. {
  106. //Set Time zone Difference
  107. var currentdate = new Date();
  108. var timeZoneDiff = currentdate.getTimezoneOffset() / 60; // Difference between user time and UTC time in hours
  109. timeZoneDiff = -timeZoneDiff; // I want to know user compared to utc, not utc compared to user
  110. timeZoneDiff += 5; //Difference between UTC and EST (server is in EST)
  111. var divs = document.getElementById("midcolumn").getElementsByTagName("div")[0].getElementsByTagName("div");
  112. var i, current_div, realTimeEST,timetext,timeDateSpan,temp;
  113.  
  114. //For each starlog entry
  115. for (i = 3; i < divs.length; i+=3)
  116. { //i=3 because first are headers
  117.  
  118. current_div = divs[i].children[0];
  119.  
  120. timeDateSpan = current_div.getElementsByTagName("span")[0];
  121. if (timeDateSpan === undefined)
  122. {
  123. if (i + 1 < divs.length)
  124. {
  125. i = i + 1;
  126. current_div = divs[i].children[0];
  127. timeDateSpan = current_div.getElementsByTagName("span")[0];
  128. }
  129. else
  130. {
  131. break;
  132. }
  133. }
  134.  
  135. realTimeEST = timeDateSpan.title;
  136.  
  137. //Process real time. Add the timezone diffrence, change Date if needed
  138. var thehours = parseInt(realTimeEST.substr(0,2));
  139. var dateString = realTimeEST.substr(9,2);
  140. thedate = parseInt(dateString);
  141. thehours += timeZoneDiff;
  142.  
  143. if (thehours >= 24)
  144. {
  145. thehours -= 24; thedate ++ ;
  146. dateString = thedate.toString();
  147. if (thedate < 10) { dateString = "0" + dateString;}
  148. }
  149.  
  150. var hoursString = thehours.toString();
  151. if (thehours < 10) { hoursString = "0" + hoursString;}
  152.  
  153. var myTimeDate = dateString + realTimeEST.substring(11,19) + " " + hoursString + realTimeEST.substring(2,8);
  154. var myp = document.createElement("p");
  155. myp.style.color = "yellow";
  156. myp.innerHTML = myTimeDate;
  157. current_div.appendChild(myp);
  158. }
  159. }
  160.  
  161. function removeStarlogText()
  162. {
  163. var allMessages = document.getElementsByClassName('fullwidth dark tbborder');
  164. var count = 1;
  165. for (var index = 0; index < allMessages.length; index ++)
  166. {
  167. var theGroup = allMessages[index].getElementsByClassName('groupmessageheader');
  168. if (theGroup.length == 1) makeShowHideGroup(theGroup[0], ++count);
  169. }
  170. }
  171.  
  172.  
  173. /* Button Functions */
  174.  
  175. function loadOnlyPlayer()
  176. {
  177. window.location.replace("http://www.war-facts.com/starlog.php?type=2&extra=1");
  178. }
  179.  
  180.  
  181. function removeSinglePlayerMessages()
  182. {
  183. var allMessages = document.getElementsByClassName('fullwidth dark tbborder');
  184. var removeList = [];
  185. var count = 1;
  186. for (var index = 0; index < allMessages.length; index ++)
  187. {
  188. var isGroup = allMessages[index].getElementsByClassName('groupmessageheader');
  189. if (isGroup.length == 0) removeList.push(allMessages[index]);
  190. else makeShowHideGroup(isGroup[0], ++count);
  191. }
  192. for (index = 0; index < removeList.length; index++) removeList[index].remove();
  193. }
  194.  
  195. function makeShowHideGroup(elem, count)
  196. {
  197. count = padCount(count);
  198. var workingText = elem.innerHTML;
  199. var newText = workingText.substring(workingText.indexOf('(') + 1, workingText.indexOf('</a>') + 4);
  200. var groupId = workingText.substring(workingText.indexOf('syncGroup') + 10, workingText.indexOf("\">") - 1);
  201. elem.innerHTML = "<label id='label" + count + groupId + "'>+</label>" + workingText.substring(0,workingText.indexOf('('));
  202. elem.outerHTML += "<label id='hiddentext" + count + groupId + "' class='groupmessageheader' style='display:none'>" + newText + "</label>";
  203. var text = document.getElementById('label' + count + groupId);
  204. text.addEventListener("click", changeTextView, true);
  205. }
  206.  
  207. function padCount(count)
  208. {
  209. if (count < 10) return "00" + count;
  210. if (count <100) return "0" + count;
  211. return count;
  212. }
  213.  
  214. function changeTextView(e)
  215. {
  216. var id = e.target.id.substring(5);
  217. var currentObject = document.getElementById('hiddentext' + id);
  218. if (currentObject.style.display == "block")
  219. currentObject.style.display = "none";
  220. else
  221. currentObject.style.display = "block";
  222.  
  223. }
  224.  
  225. function showOnlyPlayerMessages()
  226. {
  227. var allLines = document.getElementsByClassName('shadow');
  228. var groups = ["fleet", "explore", "colony", "empire", "science"];
  229. xhttp = new XMLHttpRequest();
  230. xhttp.open("GET", "http://www.war-facts.com/starlog.php?offset=100&type=2", false);
  231. xhttp.send();
  232. var div = document.createElement('div');
  233. div.innerHTML = xhttp.responseText;
  234. var moreValues = div.getElementsByClassName('fullwidth dark tbborder');
  235. for (index = 0; index < moreValues.length; index++) allLines[1].appendChild(moreValues[index]);
  236. var removeList = [];
  237. for (var groupsIndex = 0; groupsIndex < groups.length; groupsIndex ++)
  238. {
  239. var lines = allLines[1].getElementsByClassName('fullwidth dark tbborder starlog_' + groups[groupsIndex]);
  240. for (var index = 0; index < lines.length; index++) removeList.push(lines[index]);
  241. }
  242. for (index = 0; index < removeList.length; index++) removeList[index].remove();
  243. var left = document.getElementsByClassName('fullwidth dark tbborder');
  244. for (index = 0; index < left.length; index++)
  245. {
  246. var isGroup = left[index].getElementsByClassName('groupmessageheader');
  247. if (isGroup.length == 1) removeList.push(left[index]);
  248. }
  249. for (index = 0; index < removeList.length; index++) removeList[index].remove();
  250. }
  251.  
  252. function changeStatus(name, status)
  253. {
  254. if (status == true) return;
  255. var allMessages = document.getElementsByClassName('fullwidth dark tbborder');
  256. var removeList = [];
  257. for (var index = 0; index < allMessages.length; index ++)
  258. {
  259. var innerText = allMessages[index].getElementsByClassName('groupmessageheader');
  260. alert(innerText[0].innerHTML);
  261. alert(name);
  262. var index = innerText[0].innerHTML.indexOf("syncGroup" + name);
  263. alert("index is: " + index );
  264. if (index != -1) removeList.push(allMessages[index]);
  265. }
  266. for (index = 0; index < removeList.length; index++) removeList[index].remove();
  267. }
  268.  
  269. /* Private Stargroup Functions */
  270.  
  271. function addCheckBoxs()
  272. {
  273. var allMessages = document.getElementsByClassName('left starlog_right box dark padding5 minheight60');
  274. var arrayList = GM_getValue("stargroupNames");
  275. if (arrayList == undefined) return;
  276. var addText = "<div class='left starlog_left box light padding10 hide_mobile'></div><div class='left starlog_right box dark padding5 minheight60'>";
  277. for (var index = 0; index < arrayList.length; index++)
  278. {
  279. var newText = "<a class='darkbutton smalltext' id='text" + arrayList[index][0] + "'>" + arrayList[index][1] + "</a>";
  280. addText += newText;
  281. }
  282. addText += "</div>";
  283. allMessages[0].outerHTML = allMessages[0].outerHTML + addText;
  284. for (index = 0; index < arrayList.length; index++)
  285. {
  286. var label = document.getElementById('text' + arrayList[index][0]);
  287. label.addEventListener("click", function(){alert('1');loadStarGroup(arrayList[index][0]);alert('1');}, false);
  288. }
  289. }
  290.  
  291. function loadStarGroup(groupNumber)
  292. {
  293. window.location.replace("http://www.war-facts.com/starlog.php?#" + groupNumber);
  294. }
  295.  
  296. function keepOnlyGroup(groupKey)
  297. {
  298. var allMessages = document.getElementsByClassName('fullwidth dark tbborder');
  299. var removeList = [];
  300. for (var index = 0; index < allMessages.length; index ++)
  301. {
  302. var isGroup = allMessages[index].getElementsByClassName('groupmessageheader');
  303. if (isGroup.length != 0)
  304. {
  305. var value = isGroup[0].getElementsByTagName("a")[0].href;
  306. var group = value.substring(value.indexOf('(') + 1, ')' - 1);
  307. if (group != groupKey) removeList.push(allMessages[index]);
  308.  
  309. }
  310. }
  311. for (index = 0; index < removeList.length; index++) removeList[index].remove();
  312. }
  313.  
  314.  
  315.  
  316.  
  317.  
  318.