Starlog Manager

Starlog addon

目前为 2018-08-04 提交的版本,查看 最新版本

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