script.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. [App.CodeMirrorProperties.Value]: this.editorHeader,
  11. [App.CodeMirrorProperties.Theme]: 'darcula',
  12. [App.CodeMirrorProperties.Readonly]: true,
  13. [App.CodeMirrorProperties.LineNumbers]: true,
  14. [App.CodeMirrorProperties.ScrollbarStyle]: 'null'
  15. }).customOnBlur((cm, e) => {}).customHasFocus(() => true).customEnsureCursorVisible((cm) => {});
  16. this.codeMirrorEditor.cmFocus();
  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.cmLineCount();
  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.cmSetValue(editor.cmGetValue() + '\n' + tabs + emptyMatrix.join('\n'+tabs));
  32. let index = 0;
  33. const drawingInterval = setInterval(() => {
  34. if(index < matrixSymbols.length) {
  35. const symbol = matrixSymbols[index];
  36. index++;
  37. editor.replaceRange(symbol.symbol, { line: symbol.line, ch: symbol.ch }, { line: symbol.line, ch: symbol.ch+1 });
  38. } else {
  39. if(callback)
  40. callback();
  41. clearInterval(drawingInterval);
  42. }
  43. }, speed);
  44. return this;
  45. }
  46. simulateKeyboardInput(text, lt, ht, callback) {
  47. let index = 0;
  48. const editor = this.codeMirrorEditor;
  49. const typeCharacter = () => {
  50. if (index < text.length) {
  51. const char = text.charAt(index);
  52. index++;
  53. editor.cmSetValue(editor.cmGetValue() + char);
  54. editor.setCursor({ line: editor.cmLineCount() - 1, ch: editor.cmGetLine(editor.cmLineCount() - 1).length }, { scroll: false });
  55. const nextCharDelay = CDUtils.randInt(lt, ht);
  56. setTimeout(typeCharacter, nextCharDelay);
  57. } else {
  58. if(callback)
  59. callback();
  60. }
  61. };
  62. typeCharacter();
  63. return this;
  64. }
  65. }
  66. window_.on('load', (e) => {
  67. const scheduledUpdateDate = new Date();
  68. scheduledUpdateDate.setUTCHours(0, 0, 0, 0);
  69. scheduledUpdateDate.setUTCDate(scheduledUpdateDate.getUTCDate() + 1);
  70. const separator = '\n\t\t\t\t';
  71. const lastUpdateText = `Last sources update:\t\t${CDUtils.dateFormatUTC(LastUpdateTime, 3, 'Y-M-D H:I:S')}`;
  72. const nextScheduledUpdateText = `Next scheduled update:\t\t${CDUtils.dateFormatUTC(scheduledUpdateDate, 3, 'Y-M-D H:I:S')}`;
  73. const sourcesAuthorsText = `Sources authors:\t\t\tDoczilla Team`;
  74. const dzJsDocsAuthor = `'Doczilla JS Docs' author:\tOleg Karataev (CrazyDoctor)`;
  75. const infoMessage = `\n${separator}${lastUpdateText}${separator}${nextScheduledUpdateText}${separator}${sourcesAuthorsText}${separator}${dzJsDocsAuthor}`;
  76. const page = window.page = new IndexPage().start();
  77. page.drawMatrix(page.editorHeaderLogo, 3, 0);
  78. page.simulateKeyboardInput(infoMessage, 40, 50);
  79. });