DC - Date fixed

Display DC's date on top of the screen, or on your deck!

  1. // ==UserScript==
  2. // @name DC - Date fixed
  3. // @author Ianouf, Ladoria, Nasty
  4. // @version 0.9.1
  5. // @grant none
  6. // @description Display DC's date on top of the screen, or on your deck!
  7. // @match https://www.dreadcast.net/Main
  8. // @copyright 2015+, Ianouf & Ladoria
  9. // @namespace InGame
  10. // @license DBAD Don't be a dick Public license : https://raw.githubusercontent.com/philsturgeon/dbad/master/translations/LICENSE-fr.md
  11. // ==/UserScript==
  12. var server_date = undefined;
  13. var old_server_date = undefined;
  14. var handled_seconds = 0;
  15. var first_sync = true;
  16. var cumputing_skill_need = 40;
  17. var debugDeck = true;
  18. $(document).ready( function() {
  19. //Affichage de la date
  20. $('#bandeau ul.menus').eq(0)
  21. .prepend('<li id="affichageDateDC" class="couleur5" ></li>'
  22. +'<li class="separator"></li>'
  23. +'<li id="affichageDate" class="couleur5" ></li>'
  24. +'<li class="separator"></li>');
  25. $('head').append('<style>/*DC time updated stylesheet*/.custom_command.important_data { font-weight: bold;}.custom_command.red_info { color: red;}.custom_command.green_info { color: green;}.custom_command.orange_info { color: orange;}</style>');
  26. // Display DC's server date
  27. function handle_DC_date() {
  28. if(undefined === server_date)
  29. return;
  30. // server_date's refreshing all 3s, need to handle seconds between refreshs.
  31. if(server_date.getTime() != old_server_date.getTime()) {
  32. old_server_date = server_date;
  33. handled_seconds = 0;
  34. }
  35. else
  36. handled_seconds++;
  37. var server_seconds = server_date.getSeconds() + handled_seconds;
  38. // seconds handled.
  39. // display hour & DC's date
  40. date_to_display = new Date(server_date.getTime());
  41. date_to_display.setSeconds(server_seconds);
  42. $('#affichageDate').html(date_to_display.toLocaleString());
  43. $('#affichageDateDC').html(get_DC_date(server_date));
  44. }
  45. // input : Date
  46. function get_DC_date(date) {
  47. var server_day = date.getDate();
  48. var server_month = date.getMonth() + 1; // 0-11
  49. var server_year = date.getYear() - 100;
  50. var dc_hep = Math.floor(server_day / 7) + 1; //heptade
  51. var dc_day = (server_day % 7); //jour de l'heptade
  52. var dc_year = 70 + (server_year * 12) + server_month; //année, basé sur le fait que janvier 2000 est l'an 70 de DC.
  53. //le jour 0 est plutot le dernier jour de l'heptade précédente!
  54. if (dc_day === 0) {
  55. dc_hep--;
  56. dc_day=7;
  57. }
  58. return dc_day+'/'+dc_year+'.'+dc_hep;
  59. }
  60. // input format : ddmmyyyy
  61. // throw dummy exception
  62. function cast_date(text) {
  63. var day = text.substring(0,2);
  64. var month = text.substring(2,4) - 1; // 0-11
  65. var year = text.substring(4);
  66. if(isNaN(day) || isNaN(month) || isNaN(year)
  67. || day > 31 || month > 11 || year.length != 4)
  68. throw true;
  69. return new Date(year, month, day, 0, 0, 0, 0);
  70. }
  71. // input format : x/xxx.x whatever those x can mean
  72. // throw dummy exception
  73. function get_date_form_DC(date) {
  74. if(/^[0-9]{1}\/[0-9]{3}\.[0-9]{1}$/.test(date)) {
  75. var dc_day = date.substring(0,1);
  76. var dc_year = date.substring(2, 5);
  77. var dc_hep = date.substring(6);
  78. if(!isNaN(dc_day) && dc_day > 0 && dc_day < 8
  79. && !isNaN(dc_year) && dc_year >= 0 && dc_year < 1000
  80. && !isNaN(dc_hep) && dc_year > 0 && dc_hep < 6) {
  81. dc_day = parseInt(dc_day);
  82. dc_year = parseInt(dc_year);
  83. dc_hep = parseInt(dc_hep);
  84. var day =( (dc_hep-1)*7 ) + dc_day;
  85. var month = ( dc_year%12 ) +2;
  86. var year = Math.floor(dc_year / 12)+1994;
  87. if(month>12){
  88. month = month%12;
  89. year++;
  90. }
  91. day = ('0' + day).slice(-2);
  92. month = ('0' + month).slice(-2);
  93. year = ('000' + year).slice(-4);
  94. return day + month + year;
  95. }
  96. }
  97. throw true;
  98. }
  99. // Date command line 'Object'
  100. var CommandLine_DC_time = function (command_line) {
  101. this.command_line = command_line;
  102. this.argument = '';
  103. this.parameter = '';
  104. if(/\-/gi.test(command_line)) { // argument given
  105. this.argument = command_line.trim().split("-")[1];
  106. if(/ /gi.test(this.argument)) { // parameter given
  107. this.argument = command_line.trim().split("-")[1].split(" ")[0];
  108. this.parameter = command_line.trim().split("-")[1].split(" ")[1];
  109. }
  110. }
  111. this.enabledArguments = ['h', // display all date's and secondes.
  112. 'd', // display converted standard date to DC's date
  113. 't', // display converted DC's date to standard date
  114. 'a']; // display the manual
  115. // processing the command
  116. // input : Deck object
  117. this.execute = function(deck) {
  118. var deckLines = new Array();
  119. if(false === CommandLine_DC_time.check_character_skill()) {
  120. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command", "Votre niveau en informatique est trop faible pour réussir cette commande"]));
  121. return;
  122. }
  123. else switch (this.argument) {
  124. case '' : // display DC's server date
  125. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command", get_DC_date(server_date)]));
  126. break;
  127. case 'h' : // display all date's and secondes.
  128. // put separators
  129. var deckLine = $('#affichageDateDC').html()+' '+$('#affichageDate').html();
  130. deckLine = deckLine.replace(/ /g, ' | ');
  131. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command", deckLine]));
  132. break;
  133. case 'd' : // display converted standard date to DC's date
  134. var date;
  135. try {
  136. date = get_DC_date(cast_date(this.parameter));
  137. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command", date]));
  138. }
  139. catch (e) {
  140. deckLines.push(Deck.getHTMLElementLineTab(
  141. ["span", "custom_command", "Date ancienne invalide ("],
  142. ["span", "custom_command red_info", "jj"],
  143. ["span", "custom_command green_info", "mm"],
  144. ["span", "custom_command orange_info", "aaaa"],
  145. ["span", "custom_command", ")"]));
  146. deckLines.push(Deck.getHTMLElementLineTab(
  147. ["span", "custom_command", "- "],
  148. ["span", "custom_command red_info", "jj"],
  149. ["span", "custom_command"," : 00 -> 31, "],
  150. ["span", "custom_command red_info", "Jour"]));
  151. deckLines.push(Deck.getHTMLElementLineTab(
  152. ["span", "custom_command", "- "],
  153. ["span", "custom_command green_info", "mm"],
  154. ["span", "custom_command"," : 00 -> 12, "],
  155. ["span", "custom_command green_info", "Mois"]));
  156. deckLines.push(Deck.getHTMLElementLineTab(
  157. ["span", "custom_command", "- "],
  158. ["span", "custom_command orange_info", "aaaa"],
  159. ["span", "custom_command"," : 0000 -> 9999, "],
  160. ["span", "custom_command orange_info", "Année"]));
  161. }
  162. break;
  163. case 't' : // display converted DC's date to standard date
  164. var date;
  165. try {
  166. date = get_date_form_DC(this.parameter);
  167. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command", date]));
  168. }
  169. catch(e) {
  170. deckLines.push(Deck.getHTMLElementLineTab(
  171. ["span", "custom_command", "Point Temporel Impérial invalide ("],
  172. ["span", "custom_command red_info", "x"],
  173. ["span", "custom_command green_info", "/xxx"],
  174. ["span", "custom_command orange_info", ".x"],
  175. ["span", "custom_command", ")"]));
  176. deckLines.push(Deck.getHTMLElementLineTab(
  177. ["span", "custom_command", "- "],
  178. ["span", "custom_command red_info", "x"],
  179. ["span", "custom_command"," : 1 -> 7, "],
  180. ["span", "custom_command red_info", "Jour"]));
  181. deckLines.push(Deck.getHTMLElementLineTab(
  182. ["span", "custom_command", "- "],
  183. ["span", "custom_command green_info", "/xxx"],
  184. ["span", "custom_command"," : 000 -> 999, "],
  185. ["span", "custom_command green_info", "Année"]));
  186. deckLines.push(Deck.getHTMLElementLineTab(
  187. ["span", "custom_command", "- "],
  188. ["span", "custom_command orange_info", ".x"],
  189. ["span", "custom_command"," : 1 -> 5, "],
  190. ["span", "custom_command orange_info", "Heptade"]));
  191. }
  192. break;
  193. default : // display the manual ("a" argument)
  194. deckLines = CommandLine_DC_time.getManualLines();
  195. break;
  196. }
  197. deck.putResultsLines(deckLines);
  198. };
  199. };
  200. CommandLine_DC_time.cumputing_skill_need = cumputing_skill_need;
  201. CommandLine_DC_time.check_character_skill = function() {
  202. if (CommandLine_DC_time.cumputing_skill_need <= $('.stat_6_entier').first().html())
  203. return true;
  204. return false;
  205. };
  206. CommandLine_DC_time.getManualLines = function() {
  207. manualLines = new Array();
  208. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  209. ["span", "custom_command couleur_jaune important_data","date: "]);
  210. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  211. ["span", "custom_command","Affiche la date ou en convertit les différents formats"]);
  212. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  213. ["span", "custom_command","Arguments facultatifs : "]);
  214. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  215. ["span", "custom_command", "- "],
  216. ["span", "custom_command couleur_jaune", "d "],
  217. ["span", "custom_command red_info", "jj"],
  218. ["span", "custom_command green_info", "mm"],
  219. ["span", "custom_command orange_info", "aaaa"],
  220. ["span", "custom_command", " : Convertir une "],
  221. ["span", "custom_command couleur_jaune", "d"],
  222. ["span", "custom_command", "-ate ancienne"]);
  223. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  224. ["span", "custom_command", "- "],
  225. ["span", "custom_command couleur_jaune", "t "],
  226. ["span", "custom_command red_info", "x"],
  227. ["span", "custom_command green_info", "/xxx"],
  228. ["span", "custom_command orange_info", ".x"],
  229. ["span", "custom_command", " : Convertir un Point "],
  230. ["span", "custom_command couleur_jaune", "T"],
  231. ["span", "custom_command", "-emporel Impérial"]);
  232. manualLines[manualLines.length] = Deck.getHTMLElementLineTab(
  233. ["span", "custom_command", "- "],
  234. ["span", "custom_command couleur_jaune", "h "],
  235. ["span", "custom_command", " : Affiche tous les formats de date, ainsi que l'"],
  236. ["span", "custom_command couleur_jaune", "h"],
  237. ["span", "custom_command", "-eure courante"]);
  238. return manualLines;
  239. };
  240. // Help date command line 'Object'
  241. var CommandLine_DC_time_help = function () {
  242. // processing the command
  243. // input : Deck object
  244. this.execute = function(deck) {
  245. deck.putResultsLines(CommandLine_DC_time.getManualLines());
  246. };
  247. };
  248. // Help date command line 'Object'
  249. var CommandLine_help_updated = function () {
  250. // processing the command
  251. // input : Deck object
  252. this.execute = function(deck) {
  253. var deckLines = new Array();
  254. deckLines.push(Deck.getHTMLElementLineTab(["span", "custom_command important_data", "date"]));
  255. deck.putResultsLines(deckLines, 'toOldResults');
  256. };
  257. };
  258. // Deck 'Object'
  259. var Deck = function (id) {
  260. this.id = id;
  261. // Use it with result of Deck.getHTMLElementLineTab() (see below)
  262. // input : lines[], 'mode'
  263. // optional : mode. Whatever's given, append to old results line.
  264. this.putResultsLines = function (lines, mode) {
  265. mode = (undefined === mode) ? 'zone_ecrit' : 'ligne_resultat_fixed';
  266. for(var i = 0; i < lines.length; i++) {
  267. var resultsDiv = document.createElement('div');
  268. resultsDiv.className = "ligne_resultat_fixed";
  269. for(var j = 0; j < lines[i].length; j++) {
  270. var domElement = document.createElement(lines[i][j].type);
  271. domElement.className = lines[i][j]['class'];
  272. domElement.appendChild(document.createTextNode(lines[i][j].text));
  273. resultsDiv.appendChild(domElement);
  274. }
  275. $("#" + this.id + " ." + mode).append(resultsDiv);
  276. }
  277. };
  278. };
  279. // Start to fuck the DOM
  280. // DO NOT USE, NEVER, I WARNED YOU FOOL
  281. Deck.getHtmlElementTab = function(type, elementClass, text) {
  282. var anElement = new Array();
  283. anElement.type = type;
  284. anElement["class"] = elementClass;
  285. anElement.text = text;
  286. return anElement;
  287. };
  288. // input : [ [type_of_dom_element, class, text_node], ... ]
  289. Deck.getHTMLElementLineTab = function() {
  290. var lineTab = new Array();
  291. for(var i = 0; i < arguments.length; i++) {
  292. lineTab[lineTab.length] = Deck.getHtmlElementTab(arguments[i][0],arguments[i][1],arguments[i][2]);
  293. }
  294. return lineTab;
  295. };
  296. // Dom fucked
  297. $(document).ajaxComplete( function(a,b,c) {
  298. // Get and store the server date
  299. server_date = new Date(b.getResponseHeader('Date'));
  300. if(first_sync)
  301. old_server_date = server_date;
  302. first_sync = false;
  303. // Handle custom deck command
  304. if(/Command/.test(c.url)) {
  305. var deckId = 'db_deck_' + c.data.match(/[0-9]*$/)[0];
  306. var commandLine_text = $('#' + deckId + ' .ligne_ecrite_fixed').last().find('input').val();
  307. var deck = new Deck(deckId);
  308. var commandLine;
  309. // Handle Date command
  310. if(/^date/gi.test(commandLine_text)) {
  311. // Bind Command and Deck objects
  312. commandLine = new CommandLine_DC_time(commandLine_text);
  313. commandLine.execute(deck);
  314. }
  315. // Handle help Date command
  316. else if(/^help date/gi.test(commandLine_text)) {
  317. // Bind Command and Deck objects
  318. commandLine = new CommandLine_DC_time_help();
  319. commandLine.execute(deck);
  320. }
  321. // Handle help Date command
  322. else if(/^help$/gi.test(commandLine_text)) {
  323. // Bind Command and Deck objects
  324. commandLine = new CommandLine_help_updated();
  325. commandLine.execute(deck);
  326. }
  327. }
  328. });
  329. handle_DC_date();
  330. setInterval(function() { handle_DC_date(); }, 1000);
  331. });
  332. console.log('DC - Time Updated started');

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址