Spaces:
Running
Running
Download components/browser.js from Amamia/grademaster-pro: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/spaces/Amamia/grademaster-pro/resolve/main/components/browser.js
- Command line
-
hf download hf://spaces/Amamia/grademaster-pro/components/browser.js
-
curl -L -o browser.js https://huggingface.co/spaces/Amamia/grademaster-pro/resolve/main/components/browser.js
3.39 kB
| 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); |