script.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. class IndexPage {
  2. constructor() {
  3. const editorHeaderName = '\t\t______ _ _ _ ___ _____ ______ \n\t\t| _ \\ (_) | | |_ / ___| | _ \\ \n\t\t| | | |___ ___ _____| | | __ _ | \\ `--. | | | |___ ___ ___ \n\t\t| | | / _ \\ / __|_ / | | |/ _` | | |`--. \\ | | | / _ \\ / __/ __|\n\t\t| |/ / (_) | (__ / /| | | | (_| | /\\__/ /\\__/ / | |/ / (_) | (__\\__ \\\n\t\t|___/ \\___/ \\___/___|_|_|_|\\__,_| \\____/\\____/ |___/ \\___/ \\___|___/\n';
  4. const version = `\t\t\t\t\t\t\t\t\tVersion: ${App.Version}\n\n`;
  5. this.editorHeaderLogo = ' ************************************** \n ****************************************** \n ********************************************* \n ************************************************ \n ************************************************** \n **************************************************** \n ***************************************************** \n ************************* ************ \n *********************** *************** \n ********************** ****************** \n ******************** ******************** \n ****************** ********************** \n ************************** ************************* \n ************************ **************************** \n ********************** ***************************** \n ********************* ****************************** \n ******************* ************************* \n ***************** *************************** \n *************** ***************************** \n ************* ****************************** \n ********************** ******************************* \n ******************** ********************************* \n ******************* *********************************** \n ****************** *********************************** \n ***************** ************************************* \n **************** ************************************** \n *************** *************************************** \n ************** *************************************** \n ************* **************************************** \n ************ **************************************** \n **************************************************** \n ************************************************** \n ************************************************ \n ********************************************* \n ****************************************** \n ************************************** ';
  6. this.editorHeader = `${editorHeaderName}${version}`;
  7. }
  8. start() {
  9. this.codeMirrorEditor = CodeMirror(DOM.get('#editor').get(), {
  10. value: this.editorHeader,
  11. theme: 'darcula',
  12. readOnly: true,
  13. lineNumbers: true,
  14. scrollbarStyle: 'null'
  15. }).customOnBlur((cm, e) => {}).customHasFocus(() => true).customEnsureCursorVisible((cm) => {});
  16. this.codeMirrorEditor.focus();
  17. return this;
  18. }
  19. drawMatrix(matrixLine, indentation, speed, callback) {
  20. const editor = this.codeMirrorEditor;
  21. const matrix = matrixLine.split('\n');
  22. const emptyMatrix = matrix.map((line) => CDUtils.repeat(' ', line.length));
  23. const tabs = CDUtils.repeat('\t', indentation);
  24. const lineCount = editor.lineCount();
  25. const firstLine = lineCount;
  26. let matrixSymbols = [];
  27. for(let i = 0; i < matrix.length; i++)
  28. for(let j = 0; j < matrix[i].length; j++)
  29. matrixSymbols.push({ line: firstLine + i, ch: j + indentation, symbol: matrix[i].charAt(j) });
  30. matrixSymbols = CDUtils.arrayShuffle(matrixSymbols);
  31. editor.setValue(editor.getValue() + '\n' + tabs + emptyMatrix.join('\n'+tabs));
  32. //editor.execCommand("goDocEnd");
  33. let index = 0;
  34. const drawingInterval = setInterval(() => {
  35. if(index < matrixSymbols.length) {
  36. const symbol = matrixSymbols[index];
  37. index++;
  38. editor.replaceRange(symbol.symbol, { line: symbol.line, ch: symbol.ch }, { line: symbol.line, ch: symbol.ch+1 });
  39. } else {
  40. if(callback)
  41. callback();
  42. clearInterval(drawingInterval);
  43. }
  44. }, speed);
  45. return this;
  46. }
  47. simulateKeyboardInput(text, lt, ht, callback) {
  48. let index = 0;
  49. const editor = this.codeMirrorEditor;
  50. const typeCharacter = () => {
  51. if (index < text.length) {
  52. const char = text.charAt(index);
  53. index++;
  54. editor.setValue(editor.getValue() + char);
  55. editor.setCursor({line: editor.lineCount()-1, ch: editor.getLine(editor.lineCount()-1).length}, { scroll: false });
  56. const nextCharDelay = CDUtils.randInt(lt, ht);
  57. setTimeout(typeCharacter, nextCharDelay);
  58. } else {
  59. if(callback)
  60. callback();
  61. }
  62. };
  63. typeCharacter();
  64. return this;
  65. }
  66. }
  67. window_.on('load', (e) => {
  68. const scheduledUpdateDate = new Date();
  69. scheduledUpdateDate.setUTCHours(0, 0, 0, 0);
  70. scheduledUpdateDate.setUTCDate(scheduledUpdateDate.getUTCDate() + 1);
  71. const separator = '\n\t\t\t\t';
  72. const lastUpdateText = `Last sources update:\t\t${CDUtils.dateFormatUTC(LastUpdateTime, 3, 'Y-M-D H:I:S')}`;
  73. const nextScheduledUpdateText = `Next scheduled update:\t\t${CDUtils.dateFormatUTC(scheduledUpdateDate, 3, 'Y-M-D H:I:S')}`;
  74. const sourcesAuthorsText = `Sources authors:\t\t\tDoczilla Team`;
  75. const dzJsDocsAuthor = `'Doczilla JS Docs' author:\tOleg Karataev (CrazyDoctor)`;
  76. const infoMessage = `\n${separator}${lastUpdateText}${separator}${nextScheduledUpdateText}${separator}${sourcesAuthorsText}${separator}${dzJsDocsAuthor}`;
  77. const page = window.page = new IndexPage().start();
  78. page.drawMatrix(page.editorHeaderLogo, 3, 0);
  79. page.simulateKeyboardInput(infoMessage, 40, 50);
  80. });