import { Component, OnInit } from '@angular/core';
import { Injectable, Inject, PLATFORM_ID } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { isPlatformBrowser } from '@angular/common';


@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.css']
})
export class IndexComponent implements OnInit {


  ngOnInit(): void {
    this.injectTags()
  }

  private filePath = '/src/extrascripts.html'; // Adjust the path as needed

  constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) {}




  injectTags(): void {
    if (isPlatformBrowser(this.platformId)) {
      this.http.get(this.filePath, { responseType: 'text' }).subscribe(data => {
        const head = document.head || document.getElementsByTagName('head')[0];
        const tempDiv = document.createElement('div');
        tempDiv.innerHTML = data;
        
        Array.from(tempDiv.childNodes).forEach(child => head.appendChild(child));
      });
    }
  }
}
