Spaces:
Running
Running
File size: 3,387 Bytes
56b3258 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | class CustomBrowser extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.currentUrl = 'https://www.google.com';
}
connectedCallback() {
this.render();
this.setupEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
position: fixed;
top: 50px;
left: 50px;
width: 800px;
height: 600px;
background: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 100;
}
.browser-header {
display: flex;
padding: 8px;
background: #f1f1f1;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
.browser-controls {
display: flex;
gap: 5px;
}
.browser-controls button {
width: 24px;
height: 24px;
border: none;
background: transparent;
cursor: pointer;
}
.browser-url {
flex-grow: 1;
margin: 0 10px;
}
.browser-url input {
width: 100%;
padding: 4px 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
iframe {
width: 100%;
height: calc(100% - 40px);
border: none;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
</style>
<div class="browser-header">
<div class="browser-controls">
<button data-action="back"><i data-feather="arrow-left"></i></button>
<button data-action="forward"><i data-feather="arrow-right"></i></button>
<button data-action="refresh"><i data-feather="refresh-ccw"></i></button>
</div>
<div class="browser-url">
<input type="text" value="${this.currentUrl}" placeholder="Введите URL">
</div>
<button data-action="close"><i data-feather="x"></i></button>
</div>
<iframe src="${this.currentUrl}" allowfullscreen></iframe>
`;
feather.replace();
}
setupEventListeners() {
const urlInput = this.shadowRoot.querySelector('.browser-url input');
urlInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.navigate(urlInput.value);
}
});
this.shadowRoot.querySelector('[data-action="back"]').addEventListener('click', () => {
this.shadowRoot.querySelector('iframe').contentWindow.history.back();
});
this.shadowRoot.querySelector('[data-action="forward"]').addEventListener('click', () => {
this.shadowRoot.querySelector('iframe').contentWindow.history.forward();
});
this.shadowRoot.querySelector('[data-action="refresh"]').addEventListener('click', () => {
this.shadowRoot.querySelector('iframe').contentWindow.location.reload();
});
this.shadowRoot.querySelector('[data-action="close"]').addEventListener('click', () => {
this.remove();
});
}
navigate(url) {
if (!url.startsWith('http')) {
url = 'https://' + url;
}
this.currentUrl = url;
this.shadowRoot.querySelector('iframe').src = url;
this.shadowRoot.querySelector('.browser-url input').value = url;
}
}
customElements.define('custom-browser', CustomBrowser); |