Skip to content

Commit 2711195

Browse files
committed
feat: show expression in window title
1 parent ee2a535 commit 2711195

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import debounce from 'lodash/debounce';
23
import Editor from './Editor';
34
import ElementInfo from './ElementInfo';
45
import Header from './Header';
@@ -30,6 +31,7 @@ function App() {
3031

3132
parsed.targets?.forEach((el) => el.classList.add('highlight'));
3233
state.save({ html, js });
34+
state.updateTitle(parsed.expression?.expression);
3335

3436
return () => {
3537
parsed.targets?.forEach((el) => el.classList.remove('highlight'));

src/lib/state.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,28 @@ function load() {
2121
.slice(1)
2222
.split('&');
2323

24-
console.log('load', { htmlCompressed, jsCompressed });
25-
2624
return {
2725
html: htmlCompressed && decompressFromEncodedURIComponent(htmlCompressed),
2826
js: jsCompressed && decompressFromEncodedURIComponent(jsCompressed),
2927
};
3028
}
3129

30+
function updateTitle(text) {
31+
const title = document.title.split(':')[0];
32+
33+
if (!text || text.length === 0) {
34+
document.title = title;
35+
return;
36+
}
37+
38+
const suffix = text.replace(/\s+/g, ' ').substring(0, 1000).trim();
39+
document.title = title + ': ' + suffix;
40+
}
41+
3242
const state = {
3343
save,
3444
load,
45+
updateTitle,
3546
};
3647

3748
export default state;

0 commit comments

Comments
 (0)