You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GiteaOriginUrl.js 862B

12345678910111213141516171819
  1. import '@webcomponents/custom-elements'; // automatically adds custom elements for older browsers that don't support it
  2. // this is a Gitea's private HTML component, it converts an absolute or relative URL to an absolute URL with the current origin
  3. window.customElements.define('gitea-origin-url', class extends HTMLElement {
  4. connectedCallback() {
  5. const urlStr = this.getAttribute('data-url');
  6. try {
  7. // only process absolute HTTP/HTTPS URL or relative URLs ('/xxx' or '//host/xxx')
  8. if (urlStr.startsWith('http://') || urlStr.startsWith('https://') || urlStr.startsWith('/')) {
  9. const url = new URL(urlStr, window.origin);
  10. url.protocol = window.location.protocol;
  11. url.host = window.location.host;
  12. this.textContent = url.toString();
  13. return;
  14. }
  15. } catch {}
  16. this.textContent = urlStr;
  17. }
  18. });