|
595 | 595 | color: #8080a0;
|
596 | 596 | padding-left: 20px;
|
597 | 597 | }
|
| 598 | + .console-has-been-used .live-console-hint { |
| 599 | + display: none; |
| 600 | + } |
598 | 601 |
|
599 | 602 | .hint:before {
|
600 | 603 | content: '\25b2';
|
|
817 | 820 | return html.replace(/&/, "&").replace(/</g, "<");
|
818 | 821 | }
|
819 | 822 |
|
| 823 | + function hasConsoleBeenUsedPreviously() { |
| 824 | + return !!document.cookie.split('; ').find(function(cookie) { |
| 825 | + return cookie.startsWith('BetterErrors-has-used-console='); |
| 826 | + }); |
| 827 | + } |
| 828 | + |
| 829 | + var consoleHasBeenUsed = hasConsoleBeenUsedPreviously(); |
| 830 | + |
| 831 | + function consoleWasJustUsed() { |
| 832 | + if (consoleHasBeenUsed) { |
| 833 | + return; |
| 834 | + } |
| 835 | + |
| 836 | + hideConsoleHint(); |
| 837 | + consoleHasBeenUsed = true; |
| 838 | + document.cookie = "BetterErrors-has-used-console=true;path=/;max-age=31536000;samesite" |
| 839 | + } |
| 840 | + |
| 841 | + function hideConsoleHint() { |
| 842 | + document.querySelector('body').className += " console-has-been-used"; |
| 843 | + } |
| 844 | + |
820 | 845 | function REPL(index) {
|
821 | 846 | this.index = index;
|
822 | 847 |
|
|
838 | 863 | this.inputElement = this.container.querySelector("input");
|
839 | 864 | this.outputElement = this.container.querySelector("pre");
|
840 | 865 |
|
841 |
| - this.hasUsedConsole = document.cookie.split('; ').find(function(cookie) { |
842 |
| - return cookie.startsWith('BetterErrors-has-used-console='); |
843 |
| - }); |
844 |
| - if (this.hasUsedConsole) { |
845 |
| - this.hideConsoleHint(); |
| 866 | + if (consoleHasBeenUsed) { |
| 867 | + hideConsoleHint(); |
846 | 868 | }
|
847 | 869 |
|
848 | 870 | var self = this;
|
849 | 871 | this.inputElement.onkeydown = function(ev) {
|
850 | 872 | self.onKeyDown(ev);
|
851 |
| - if (!self.hasUsedConsole) { |
852 |
| - self.hideConsoleHint(); |
853 |
| - self.hasUsedConsole = true; |
854 |
| - document.cookie = "BetterErrors-has-used-console=true;path=/;max-age=31536000;samesite" |
855 |
| - } |
| 873 | + consoleWasJustUsed(); |
856 | 874 | };
|
857 | 875 |
|
858 | 876 | this.setPrompt(">>");
|
859 | 877 |
|
860 | 878 | REPL.all[this.index] = this;
|
861 | 879 | };
|
862 | 880 |
|
863 |
| - REPL.prototype.hideConsoleHint = function() { |
864 |
| - document.querySelector('#live-shell-hint').style["display"] = "none"; |
865 |
| - }; |
866 |
| - |
867 | 881 | REPL.prototype.focus = function() {
|
868 | 882 | this.inputElement.focus();
|
869 | 883 | };
|
|
0 commit comments