Homeunstuck

adds homestuck navigation and pages remaining

当前为 2016-04-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Homeunstuck
  3. // @namespace abrad45
  4. // @description adds homestuck navigation and pages remaining
  5. // @include http://www.mspaintadventures.com/*
  6. // @include http://mspaintadventures.com/*
  7. // @require https://code.jquery.com/jquery-2.2.3.min.js
  8. // @require https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.1/js.cookie.js
  9. // @version 1.3.0
  10. // @grant none
  11. // @history 1.0 20121125 - Initial Release
  12. // @history 1.0.1 20121202 - Modified `endings` to include page 7411, End of A6I4
  13. // @history 1.0.2 20121204 - Changed erroneous ending page number of A6I4 from 7441 to 7411
  14. // @history 1.0.3 20130113 - Modified `endings` to include page 7613, End of A6A5A1
  15. // @history 1.0.4 20130414 - Modified `endings` to remove page 7613, and add 7826 and 8135
  16. // @history 1.1 20130415 - Formatting Changes; Enabled Keyboard Navigation with Left/Right Arrows
  17. // @history 1.2 20130421 - Includes "You've not saved since comic ##" notification
  18. // @history 1.3 20160416 - We're back! Formatting, final update to `endings`, jquery version bump and switch from jquery-cookie to js-cookie.
  19.  
  20. // ==/UserScript==
  21.  
  22. $(function () {
  23. if (/s=6/.test(window.location.search)) {
  24. var URL = window.location.search;
  25. var root = URL.substr(0,URL.length-4);
  26. var comic = +URL.substr(-4);
  27. var firstPage = 1901;
  28. var lastPage = 10028;
  29.  
  30. if (!comic) {
  31. root = "?s=6&p=00";
  32. comic = 1901;
  33. }
  34.  
  35. var nextURL = '/' + root + (+comic+1);
  36. var prevURL = '/' + root + (+comic-1);
  37.  
  38. // starting from the top so I can display nothing if there is no end to the current act
  39. var endings = [
  40. 2147, // End of Act I
  41. 2658, // End of Act II
  42. 3053, // End of Act III
  43. 3257, // End of Intermission 1
  44. 3888, // End of Act IV
  45. 4525, // End of Act V Act I
  46. 6010, // End of Act V
  47. 6012, // End of Intermission 2
  48. 6184, // End of Act VI Act I
  49. 6290, // End of Act VI Intermission 1
  50. 6566, // End of Act VI Act II
  51. 6716, // End of Act VI Intermission 2
  52. 7162, // End of Act VI Act III
  53. 7337, // End of Act VI Intermission 3
  54. 7339, // End of Act VI Act IV
  55. 7411, // End of Act VI Intermission 4
  56. 7826, // End of Act VI Act V
  57. 8135, // End of Act VI Intermission 5
  58. 8177, // End of Act VI Act VI Act I
  59. 8374, // End of Act VI Act VI Intermission 1
  60. 8430, // End of Act VI Act VI Act II
  61. 8752, // End of Act VI Act VI Intermission 2
  62. 8801, // End of Act VI Act VI Act III
  63. 8820, // End of Act VI Act VI Intermission 3
  64. 8843, // End of Act VI Act VI Act IV
  65. 9308, // End of Act VI Act VI Intermission 4
  66. 9348, // End of Act VI Act VI Act V
  67. 9986, // End of Act VI Act VI Intermission 5
  68. 10026, // End of Act VI Act VI Act VI
  69. 10028 // End of Act VI
  70. ];
  71.  
  72. // Find out which part of the story we're in
  73. var currentStorySection = endings.length;
  74. while(comic < endings[--currentStorySection]) {}
  75. // We've gone too far. Course correct!
  76. currentStorySection++;
  77.  
  78. $('table[width=600]')
  79. .first()
  80. .parent()
  81. .css('position', 'relative')
  82. .prepend(
  83. $('<div />', {
  84. 'id': 'homeunstuck',
  85. 'css': {
  86. 'position': 'absolute',
  87. 'left': '35px',
  88. 'width': '100px',
  89. }
  90. })
  91. );
  92.  
  93. $('#homeunstuck')
  94. .append(
  95. $('<a />', {
  96. 'id': 'homeunstuck-prev',
  97. 'href': prevURL,
  98. 'html': '&#8592;',
  99. 'css': { 'margin-right': '10px' }
  100. })
  101. ).append(
  102. $('<a />', {
  103. 'id': 'homeunstuck-next',
  104. 'href': nextURL,
  105. 'html': '&#8594;',
  106. })
  107. );
  108.  
  109. if (comic === firstPage) {
  110. $('#homeunstuck-prev').remove();
  111. } else if(comic === lastPage) {
  112. $('#homeunstuck-next').remove();
  113. }
  114.  
  115. if (!isNaN(endings[currentStorySection] - comic)) {
  116. $('#homeunstuck')
  117. .append($('<div />', {
  118. 'text': endings[currentStorySection] - comic + ' left',
  119. 'id': 'homeunstuck_pages_left'
  120. })
  121. );
  122. }
  123.  
  124. var story = Cookies.get('s_cookie');
  125. var page = Cookies.get('p_cookie');
  126.  
  127. if (
  128. !!story &&
  129. !!page &&
  130. Number(story) === 6 &&
  131. (comic - page.substr(-4) > 24)
  132. ) {
  133. $('#homeunstuck').append(
  134. $('<div />',
  135. {
  136. 'text': "You've not saved since comic " + Cookies.get('p_cookie').substr(-4),
  137. 'css': {
  138. 'color': '#900',
  139. 'font-weight': 'bold'
  140. }
  141. }
  142. )
  143. );
  144. }
  145.  
  146. $(window).keyup(function (e) {
  147. if (e.which === 37) {
  148. window.location = prevURL;
  149. } else if (e.which === 39) {
  150. window.location = nextURL;
  151. }
  152. });
  153. }
  154. });