iRacing road only

Userscript for iRacing that hides content unrelated to road racing. This is opinionated, so YMMV.

当前为 2014-07-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name iRacing road only
  3. // @namespace drinkto.me
  4. // @description Userscript for iRacing that hides content unrelated to road racing. This is opinionated, so YMMV.
  5. // @include http://members.iracing.com/jforum/forums/list.page
  6. // @include http://members.iracing.com/membersite/member/*
  7. // @version 7
  8. // @grant none
  9. // ==/UserScript==
  10. var load,execute,loadAndExecute,executeJQuery;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})}
  11. ,executeJQuery=function(a){if(typeof jQuery=='undefined'){var jqUrl='//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js';loadAndExecute(jqUrl,a);}else{execute(a);}};
  12.  
  13. executeJQuery(function () {
  14.  
  15. // On membersite, make 'series' link always go to the road filter
  16. $("td.simpleNav ul li a[href='/membersite/member/Series.do']").attr("href", "/membersite/member/Series.do?cat=2")
  17.  
  18. // Give some indication that this is not the full list on forum home.
  19. $(".homeLink").text("Forum List (road only)")
  20.  
  21.  
  22. //-----------------------------------------------------
  23. //
  24. // Show countdown timer and number registered drivers in title (contributed by @kutu)
  25. //
  26. if ("racingpaneldata" in this && racingpaneldata.session) {
  27. var originalTitle = document.title;
  28. setInterval(function () {
  29. var numRegistered = $("#racingpanel_session_numregistered");
  30. var countdownTimer = $("#racingpanel_countdown_timer");
  31. if (numRegistered.length && countdownTimer.length) {
  32. document.title = numRegistered.text() + " " + countdownTimer.text() + " " + originalTitle;
  33. } else {
  34. document.title = originalTitle;
  35. }
  36. }, 1000);
  37. }
  38.  
  39.  
  40. //-----------------------------------------------------
  41. //
  42. // Remove ovals and ineligible series from dropdown menu (contributed by @kutu)
  43. //
  44. var seriesDrop = $("#datSeriesSelectorDropdown optgroup");
  45. if (seriesDrop.length) {
  46. // remove ovals
  47. var eligibles = seriesDrop[0].children;
  48. var isOvalSection;
  49. var toRemove = [];
  50. $.each(eligibles, function (index, value) {
  51. // search for oval section
  52. if (value.disabled) {
  53. if (/Oval$/.test(value.text)) isOvalSection = true;
  54. if (/Road$/.test(value.text)) isOvalSection = false;
  55. }
  56. if (isOvalSection || value.disabled || value.value == 0) {
  57. // if we currently in oval's section
  58. // or current option is disabled
  59. // or current option is "No matching series"
  60. toRemove.push(value);
  61. } else {
  62. // trim spaces
  63. value.text = value.text.replace(/^\s*/, "")
  64. }
  65. });
  66. // remove not needed options
  67. $.each(toRemove, function (index, value) {
  68. value.remove();
  69. });
  70.  
  71. // remove ineligible
  72. seriesDrop[1].remove();
  73. // remove root tree and select series
  74. var dropdown = seriesDrop[0].parentElement;
  75. var selectedValue = dropdown.selectedOptions[0].value;
  76. $("#datSeriesSelectorDropdown").append(eligibles);
  77. seriesDrop[0].remove();
  78. $.each(dropdown.children, function (index, value) {
  79. if (value.value == selectedValue) dropdown.selectedIndex = index;
  80. });
  81. }
  82.  
  83.  
  84. //-----------------------------------------------------
  85. //
  86. // Filter the hosted sessions by road tracks.
  87. // See the filter_tracks.js to generate the array.
  88. //
  89. if (window.location.pathname.indexOf("/HostedSessions.do") > 0) {
  90.  
  91. setInterval(function () {
  92.  
  93. while($('.hosted_sessions_table_info').length <= 0){
  94.  
  95. sleep(500)
  96. console.log('Waiting for table to show up...')
  97. }
  98.  
  99. // Change something to indicate this is filtered.
  100. $("tr th a[name='Track']").text("Track (road only)");
  101.  
  102. // Generated output
  103. var ovalTracks = [
  104. 52, // Oval - Atlanta Motor Speedway - Legends Oval
  105. 53, // Oval - Atlanta Motor Speedway - Oval
  106. 225, // Oval - Auto Club Speedway - Oval
  107. 101, // Oval - Bristol Motor Speedway -
  108. 143, // Oval - Centripetal Circuit -
  109. 39, // Oval - Charlotte Motor Speedway - Legends Oval
  110. 40, // Oval - Charlotte Motor Speedway - Oval
  111. 123, // Oval - Chicagoland Speedway -
  112. 15, // Oval - Concord Speedway -
  113. 115, // Oval - Darlington Raceway -
  114. 191, // Oval - Daytona International Speedway - Oval
  115. 27, // Oval - Daytona circa 2007 - Oval
  116. 162, // Oval - Dover International Speedway -
  117. 20, // Oval - Homestead Miami Speedway - Miami Speedway
  118. 133, // Oval - Indianapolis Motor Speedway - Oval
  119. 178, // Oval - Indianapolis Motor Speedway - IndyCar Oval
  120. 169, // Oval - Iowa Speedway - Oval
  121. 171, // Oval - Iowa Speedway - Legends
  122. 172, // Oval - Iowa Speedway - Infield Legends
  123. 19, // Oval - Irwindale Speedway - Inner
  124. 23, // Oval - Irwindale Speedway - Outer
  125. 30, // Oval - Irwindale Speedway - Outer - Inner
  126. 214, // Oval - Kansas Speedway - Oval
  127. 189, // Oval - Kentucky Speedway - Legends
  128. 188, // Oval - Kentucky Speedway - Oval
  129. 201, // Oval - Langley Speedway -
  130. 17, // Oval - Lanier National Speedway -
  131. 113, // Oval - Las Vegas Motor Speedway - Infield Legends Oval
  132. 103, // Oval - Las Vegas Motor Speedway - Oval
  133. 110, // Oval - Las Vegas Motor Speedway - Legends Oval
  134. 33, // Oval - Martinsville Speedway -
  135. 124, // Oval - Michigan International Speedway -
  136. 156, // Oval - Mid-Ohio Sports Car Course - Oval
  137. 157, // Oval - Mid-Ohio Sports Car Course - Alt Oval
  138. 131, // Oval - New Hampshire Motor Speedway - Oval
  139. 222, // Oval - New Hampshire Motor Speedway - Legends
  140. 190, // Oval - New Smyrna Speedway -
  141. 12, // Oval - Oxford Plains Speedway -
  142. 104, // Oval - Phoenix International Raceway - Oval
  143. 136, // Oval - Pocono Raceway - Oval
  144. 31, // Oval - Richmond International Raceway -
  145. 203, // Oval - Rockingham Speedway - Oval
  146. 14, // Oval - South Boston Speedway -
  147. 11, // Oval - Stafford Motor Speedway - Full Course
  148. 116, // Oval - Talladega Superspeedway -
  149. 120, // Oval - Texas Motor Speedway - Legends Oval
  150. 121, // Oval - Texas Motor Speedway - Oval
  151. 94, // Oval - The Milwaukee Mile -
  152. 161, // Oval - Thompson International Speedway -
  153. 198, // Oval - Twin Ring Motegi - Oval
  154. 16 // Oval - USA International Speedway -
  155. ];
  156.  
  157. function getURLParameter(url, name) {
  158. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [, ""])[1].replace(/\+/g, '%20')) || null;
  159. }
  160.  
  161. // Iterate over each td that contains a link to a track, compare to known roadTracks and remove if not listed above.
  162. // /membersite/member/TrackDetail.do?trkid=107
  163. $("table tr td div div a[href*='/membersite/member/TrackDetail.do?trkid']").each(function (index) {
  164. var href = $(this).attr('href');
  165. var trackID = parseInt(getURLParameter(href, 'trkid'));
  166. var text = $(this).text();
  167. var isOval = (-1 != $.inArray(trackID, ovalTracks));
  168. var isUnwantedRow = (text == 'Track Info' || text == '')
  169. //console.log("track["+ trackID + "]: " + isOval + " - " + $(this).text())
  170.  
  171. if (isOval && !isUnwantedRow) {
  172. tr = $(this).parent().parent().parent().parent();
  173. //console.log(tr);
  174. console.log("Removing track[" + trackID + "]: " + isOval + " - " + text)
  175. tr.remove();
  176. }
  177. });
  178. }, 1000);
  179. }
  180.  
  181.  
  182. //-----------------------------------------------------
  183. //
  184. // Only execute the following if we are on the forum list page
  185. //
  186. if (window.location.pathname.indexOf("/list.page") <= 0)
  187. return;
  188. else
  189. console.log("Skipping forum list pruning.");
  190.  
  191. function toggleForumRowByText(forums) {
  192.  
  193. $.each(forums, function (index, value) {
  194. e = $("td:contains('" + value + "')");
  195. e.parent().toggle();
  196. console.log("Removed: " + value);
  197. });
  198. }
  199.  
  200. function toggleForumRowByPage(forums) {
  201.  
  202. $.each(forums, function (index, value) {
  203. e = $("td a[href*='/" + value + ".page']");
  204. text = e.text();
  205. e.parent().parent().toggle();
  206. console.log("Removed: " + value + ".page - " + text);
  207. });
  208. }
  209.  
  210. /**
  211. * Remove oval
  212. */
  213. var ovalPages = [
  214. "619",
  215. "620",
  216. "635",
  217. "621",
  218. "3713",
  219. "624",
  220. "2911",
  221. "629",
  222. "637",
  223. "623",
  224. "631",
  225. "632",
  226. "5511",
  227. "6312",
  228. "8711"
  229. ];
  230.  
  231. var ovalHeaders = ["Oval Racing"];
  232.  
  233. toggleForumRowByPage(ovalPages);
  234. toggleForumRowByText(ovalHeaders);
  235.  
  236.  
  237. /******************************************************
  238. * OPINIONATED removal below here, just oval is above
  239. */
  240.  
  241. /**
  242. * Remove club
  243. */
  244. // club general discussion
  245. $("td:contains('Club Discussion Area')").parent().next().remove()
  246. var clubHeaders = [
  247. "Club Discussion Area",
  248. "Club News",
  249. "Club Stats",
  250. "Setup Garage"
  251. ];
  252. toggleForumRowByText(clubHeaders);
  253.  
  254. /**
  255. * Racing and championships (selected ones only)
  256. */
  257. var racingAndChampionshipsPages = [
  258. "644", // world champ
  259. "645", // pro
  260. "647", // licenses, ratings and scoring
  261. "648", // racing your latest race
  262. "649", // video and screenshot showcase
  263. "643" // world cup of iracing
  264. ];
  265. toggleForumRowByPage(racingAndChampionshipsPages);
  266.  
  267. /**
  268. * Club and Regional
  269. */
  270. var regionalHeaders = ["Regional Competitions Discussion"];
  271. var regionalPages = ["4111"];
  272.  
  273. toggleForumRowByText(regionalHeaders);
  274. toggleForumRowByPage(regionalPages);
  275.  
  276. /**
  277. * Paint
  278. */
  279. // var paintHeaders = ["The Paint Booth"];
  280. // var paintPages = ["639", "640"];
  281. // toggleForumRowByText(paintHeaders);
  282. // toggleForumRowByPage(paintPages);
  283.  
  284. /**
  285. * Technical and Help
  286. */
  287. var techPages = [
  288. "618", // tech - other
  289. "617" // camera files
  290. ];
  291. toggleForumRowByPage(techPages);
  292. });