MediaWiki:Common.js: Difference between revisions

From Erakh Codex
Jump to navigation Jump to search
Juoh (talk | contribs)
No edit summary
Juoh (talk | contribs)
No edit summary
Line 1: Line 1:
/* =============================================
(function () {
  ERAKH HEADER — MediaWiki:Common.js
  /* --- Google Fonts 강제 로드 --- */
  erakh.com Header.tsx와 동일한 디자인/역할
  var fontLink = document.createElement("link");
  ============================================= */
  fontLink.rel = "stylesheet";
  fontLink.href = "https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600&family=EB+Garamond:ital,wght@0,400;0,500;1,400&family=Inter:wght@400;500&display=swap";
  document.head.insertBefore(fontLink, document.head.firstChild);


(function () {
   /* --- 쿠키 읽기 --- */
   /* --- 쿠키 읽기 --- */
   function getCookie(name) {
   function getCookie(name) {
Line 18: Line 19:
   } catch (e) {}
   } catch (e) {}


   /* --- CSS 주입 --- */
   /* --- 인라인 스타일 헬퍼 --- */
   var style = document.createElement("style");
   function s(el, styles) {
  style.textContent = `
     Object.keys(styles).forEach(function(k) { el.style[k] = styles[k]; });
    .erakh-header {
  }
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      z-index: 9999;
      width: 100%;
      background: var(--bg, #f9f6f0);
      border-bottom: 1px solid var(--beige-2, #e2d9c8);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 2rem;
      height: 56px;
    }
    .erakh-header-left {
      display: flex;
      align-items: center;
      gap: 1.75rem;
    }
    .erakh-logo {
      font-family: 'Cinzel', serif;
      font-size: 1.125rem;
      font-weight: 500;
      color: var(--ink, #2a2218);
      text-decoration: none;
      letter-spacing: 0.05em;
    }
    .erakh-nav a {
      font-family: 'EB Garamond', serif;
      font-size: 1rem;
      color: var(--ink-soft, #6b5e4e);
      text-decoration: none;
      transition: color 0.15s;
    }
    .erakh-nav a:hover {
      color: var(--ink, #2a2218);
    }
    .erakh-nav a.active {
      color: var(--ink, #2a2218);
    }
    .erakh-login-btn {
      font-family: 'Inter', sans-serif;
      font-size: 0.8125rem;
      font-weight: 500;
      color: var(--ink, #2a2218);
      text-decoration: none;
      padding: 0.4rem 1rem;
      border: 1px solid var(--beige-3, #c8b99a);
      background: transparent;
      transition: border-color 0.15s, background 0.15s;
      cursor: pointer;
    }
    .erakh-login-btn:hover {
      border-color: var(--gold, #c8a060);
      background: var(--beige-1, #f0ebe0);
    }
    .erakh-profile {
      position: relative;
    }
    .erakh-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      background: var(--beige-2, #e2d9c8);
      border: 1px solid var(--beige-3, #c8b99a);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-family: 'Cinzel', serif;
      font-size: 0.75rem;
      color: var(--ink, #2a2218);
      transition: border-color 0.15s;
    }
     .erakh-avatar:hover {
      border-color: var(--gold, #c8a060);
    }
    .erakh-dropdown {
      position: absolute;
      top: calc(100% + 8px);
      right: 0;
      background: var(--bg, #f9f6f0);
      border: 1px solid var(--beige-2, #e2d9c8);
      min-width: 180px;
      padding: 0.5rem 0;
      box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    }
    .erakh-dropdown-email {
      padding: 0.5rem 1rem 0.75rem;
      font-family: 'EB Garamond', serif;
      font-size: 0.875rem;
      color: var(--ink-soft, #6b5e4e);
      border-bottom: 1px solid var(--beige-2, #e2d9c8);
      margin-bottom: 0.25rem;
      font-style: italic;
      word-break: break-all;
    }
    .erakh-dropdown-item {
      display: block;
      width: 100%;
      padding: 0.5rem 1rem;
      font-family: 'Inter', sans-serif;
      font-size: 0.8125rem;
      color: var(--ink, #2a2218);
      text-align: left;
      background: transparent;
      border: none;
      cursor: pointer;
      text-decoration: none;
      transition: background 0.1s;
      box-sizing: border-box;
    }
    .erakh-dropdown-item:hover {
      background: var(--beige-1, #f0ebe0);
    }
    .erakh-dropdown-item.danger {
      color: #a04040;
    }
  `;
  document.head.appendChild(style);


   /* --- 헤더 HTML 생성 --- */
   /* --- 헤더 --- */
   var header = document.createElement("header");
   var header = document.createElement("header");
   header.className = "erakh-header";
   s(header, {
    position: "fixed",
    top: "0",
    left: "0",
    right: "0",
    zIndex: "9999",
    width: "100%",
    background: "#f9f6f0",
    borderBottom: "1px solid #e2d9c8",
    display: "flex",
    alignItems: "center",
    justifyContent: "space-between",
    padding: "0 2rem",
    height: "56px",
    boxSizing: "border-box"
  });


   /* 좌측 */
   /* --- 좌측 --- */
   var left = document.createElement("div");
   var left = document.createElement("div");
   left.className = "erakh-header-left";
   s(left, {
    display: "flex",
    alignItems: "center",
    gap: "1.75rem"
  });


   var logo = document.createElement("a");
   var logo = document.createElement("a");
    logo.href = "https://erakh.com";
  logo.href = "https://erakh.com";
    logo.className = "erakh-logo";
  logo.textContent = "Erakh Archive";
    logo.textContent = "Erakh Archive";
  s(logo, {
     logo.style.cssText = "font-family:'Cinzel',serif !important;font-size:1.125rem !important;font-weight:500 !important;color:#2a2218 !important;text-decoration:none !important;letter-spacing:0.05em !important;text-transform:none !important;font-variant:normal !important;font-variant-caps:normal !important;";
     fontFamily: "'Cinzel', serif",
    fontSize: "1.125rem",
    fontWeight: "500",
    color: "#2a2218",
    textDecoration: "none",
    letterSpacing: "0.05em",
    textTransform: "none",
    fontVariant: "normal",
    fontVariantCaps: "normal",
    lineHeight: "1"
  });


   var nav = document.createElement("nav");
   var nav = document.createElement("nav");
   nav.className = "erakh-nav";
   s(nav, { display: "flex", alignItems: "center", gap: "1.5rem" });
 
   var codexLink = document.createElement("a");
   var codexLink = document.createElement("a");
   codexLink.href = "https://codex.erakh.com";
   codexLink.href = "https://codex.erakh.com";
   codexLink.textContent = "Codex";
   codexLink.textContent = "Codex";
   codexLink.className = "active";
   s(codexLink, {
    fontFamily: "'EB Garamond', serif",
    fontSize: "1rem",
    color: "#6b5e4e",
    textDecoration: "none",
    textTransform: "none",
    fontVariant: "normal",
    lineHeight: "1"
  });
  codexLink.addEventListener("mouseover", function() { this.style.color = "#2a2218"; });
  codexLink.addEventListener("mouseout",  function() { this.style.color = "#6b5e4e"; });
 
   nav.appendChild(codexLink);
   nav.appendChild(codexLink);
   left.appendChild(logo);
   left.appendChild(logo);
   left.appendChild(nav);
   left.appendChild(nav);


   /* 우측 */
   /* --- 우측 --- */
   var right = document.createElement("div");
   var right = document.createElement("div");
  s(right, { display: "flex", alignItems: "center" });


   if (user && user.email) {
   if (user && user.email) {
     /* 로그인 상태 — 아바타 + 드롭다운 */
     /* 로그인 — 아바타 + 드롭다운 */
     var profile = document.createElement("div");
     var profile = document.createElement("div");
     profile.className = "erakh-profile";
     s(profile, { position: "relative" });


     var avatar = document.createElement("div");
     var avatar = document.createElement("div");
    avatar.className = "erakh-avatar";
     avatar.textContent = user.email.slice(0, 1).toUpperCase();
     avatar.textContent = user.email.slice(0, 1).toUpperCase();
    s(avatar, {
      width: "32px",
      height: "32px",
      borderRadius: "50%",
      background: "#e2d9c8",
      border: "1px solid #c8b99a",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      cursor: "pointer",
      fontFamily: "'Cinzel', serif",
      fontSize: "0.75rem",
      color: "#2a2218",
      boxSizing: "border-box",
      fontVariant: "normal",
      textTransform: "none"
    });


     var dropdown = document.createElement("div");
     var dropdown = document.createElement("div");
     dropdown.className = "erakh-dropdown";
     s(dropdown, {
    dropdown.style.display = "none";
      display: "none",
      position: "absolute",
      top: "calc(100% + 8px)",
      right: "0",
      background: "#f9f6f0",
      border: "1px solid #e2d9c8",
      minWidth: "180px",
      padding: "0.5rem 0",
      boxShadow: "0 4px 16px rgba(0,0,0,0.06)",
      zIndex: "10000",
      boxSizing: "border-box"
    });


     var emailDiv = document.createElement("div");
     var emailDiv = document.createElement("div");
    emailDiv.className = "erakh-dropdown-email";
     emailDiv.textContent = user.email;
     emailDiv.textContent = user.email;
    s(emailDiv, {
      padding: "0.5rem 1rem 0.75rem",
      fontFamily: "'EB Garamond', serif",
      fontSize: "0.875rem",
      color: "#6b5e4e",
      borderBottom: "1px solid #e2d9c8",
      marginBottom: "0.25rem",
      fontStyle: "italic",
      wordBreak: "break-all"
    });


     var profileLink = document.createElement("a");
     var profileLink = document.createElement("a");
     profileLink.href = "https://erakh.com/profile";
     profileLink.href = "https://erakh.com/profile";
    profileLink.className = "erakh-dropdown-item";
     profileLink.textContent = "Profile";
     profileLink.textContent = "Profile";
    s(profileLink, {
      display: "block",
      width: "100%",
      padding: "0.5rem 1rem",
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      color: "#2a2218",
      textDecoration: "none",
      boxSizing: "border-box",
      textTransform: "none"
    });


     var signOutBtn = document.createElement("button");
     var signOutBtn = document.createElement("button");
    signOutBtn.className = "erakh-dropdown-item danger";
     signOutBtn.textContent = "Sign out";
     signOutBtn.textContent = "Sign out";
    s(signOutBtn, {
      display: "block",
      width: "100%",
      padding: "0.5rem 1rem",
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      color: "#a04040",
      textAlign: "left",
      background: "transparent",
      border: "none",
      cursor: "pointer",
      boxSizing: "border-box",
      textTransform: "none"
    });
     signOutBtn.addEventListener("click", function () {
     signOutBtn.addEventListener("click", function () {
       fetch("https://erakh.com/api/auth/logout", { method: "POST", credentials: "include" })
       fetch("https://erakh.com/api/auth/logout", { method: "POST", credentials: "include" })
         .then(function () {
         .then(function () { window.location.href = "https://erakh.com"; });
          window.location.href = "https://erakh.com";
        });
     });
     });


Line 210: Line 189:
       dropdown.style.display = dropdown.style.display === "none" ? "block" : "none";
       dropdown.style.display = dropdown.style.display === "none" ? "block" : "none";
     });
     });
     document.addEventListener("click", function (e) {
     document.addEventListener("click", function (e) {
       if (!profile.contains(e.target)) {
       if (!profile.contains(e.target)) dropdown.style.display = "none";
        dropdown.style.display = "none";
      }
     });
     });


Line 222: Line 198:


   } else {
   } else {
     /* 비로그인 상태 — Sign in 버튼 */
     /* 비로그인 — Sign in */
     var loginBtn = document.createElement("a");
     var loginBtn = document.createElement("a");
     loginBtn.href = "https://erakh.com/login?redirect=" + encodeURIComponent(window.location.href);
     loginBtn.href = "https://erakh.com/login?redirect=" + encodeURIComponent(window.location.href);
    loginBtn.className = "erakh-login-btn";
     loginBtn.textContent = "Sign in";
     loginBtn.textContent = "Sign in";
    s(loginBtn, {
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      fontWeight: "500",
      color: "#2a2218",
      textDecoration: "none",
      padding: "0.4rem 1rem",
      border: "1px solid #c8b99a",
      background: "transparent",
      cursor: "pointer",
      textTransform: "none",
      boxSizing: "border-box",
      lineHeight: "1"
    });
    loginBtn.addEventListener("mouseover", function() {
      this.style.borderColor = "#c8a060";
      this.style.background = "#f0ebe0";
    });
    loginBtn.addEventListener("mouseout", function() {
      this.style.borderColor = "#c8b99a";
      this.style.background = "transparent";
    });
     right.appendChild(loginBtn);
     right.appendChild(loginBtn);
   }
   }

Revision as of 02:34, 9 April 2026

(function () {
  /* --- Google Fonts 강제 로드 --- */
  var fontLink = document.createElement("link");
  fontLink.rel = "stylesheet";
  fontLink.href = "https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600&family=EB+Garamond:ital,wght@0,400;0,500;1,400&family=Inter:wght@400;500&display=swap";
  document.head.insertBefore(fontLink, document.head.firstChild);

  /* --- 쿠키 읽기 --- */
  function getCookie(name) {
    var match = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
    return match ? decodeURIComponent(match[1]) : null;
  }

  /* --- 유저 정보 파싱 --- */
  var user = null;
  try {
    var raw = getCookie("erakh_user");
    if (raw) user = JSON.parse(raw);
  } catch (e) {}

  /* --- 인라인 스타일 헬퍼 --- */
  function s(el, styles) {
    Object.keys(styles).forEach(function(k) { el.style[k] = styles[k]; });
  }

  /* --- 헤더 --- */
  var header = document.createElement("header");
  s(header, {
    position: "fixed",
    top: "0",
    left: "0",
    right: "0",
    zIndex: "9999",
    width: "100%",
    background: "#f9f6f0",
    borderBottom: "1px solid #e2d9c8",
    display: "flex",
    alignItems: "center",
    justifyContent: "space-between",
    padding: "0 2rem",
    height: "56px",
    boxSizing: "border-box"
  });

  /* --- 좌측 --- */
  var left = document.createElement("div");
  s(left, {
    display: "flex",
    alignItems: "center",
    gap: "1.75rem"
  });

  var logo = document.createElement("a");
  logo.href = "https://erakh.com";
  logo.textContent = "Erakh Archive";
  s(logo, {
    fontFamily: "'Cinzel', serif",
    fontSize: "1.125rem",
    fontWeight: "500",
    color: "#2a2218",
    textDecoration: "none",
    letterSpacing: "0.05em",
    textTransform: "none",
    fontVariant: "normal",
    fontVariantCaps: "normal",
    lineHeight: "1"
  });

  var nav = document.createElement("nav");
  s(nav, { display: "flex", alignItems: "center", gap: "1.5rem" });

  var codexLink = document.createElement("a");
  codexLink.href = "https://codex.erakh.com";
  codexLink.textContent = "Codex";
  s(codexLink, {
    fontFamily: "'EB Garamond', serif",
    fontSize: "1rem",
    color: "#6b5e4e",
    textDecoration: "none",
    textTransform: "none",
    fontVariant: "normal",
    lineHeight: "1"
  });
  codexLink.addEventListener("mouseover", function() { this.style.color = "#2a2218"; });
  codexLink.addEventListener("mouseout",  function() { this.style.color = "#6b5e4e"; });

  nav.appendChild(codexLink);
  left.appendChild(logo);
  left.appendChild(nav);

  /* --- 우측 --- */
  var right = document.createElement("div");
  s(right, { display: "flex", alignItems: "center" });

  if (user && user.email) {
    /* 로그인 — 아바타 + 드롭다운 */
    var profile = document.createElement("div");
    s(profile, { position: "relative" });

    var avatar = document.createElement("div");
    avatar.textContent = user.email.slice(0, 1).toUpperCase();
    s(avatar, {
      width: "32px",
      height: "32px",
      borderRadius: "50%",
      background: "#e2d9c8",
      border: "1px solid #c8b99a",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      cursor: "pointer",
      fontFamily: "'Cinzel', serif",
      fontSize: "0.75rem",
      color: "#2a2218",
      boxSizing: "border-box",
      fontVariant: "normal",
      textTransform: "none"
    });

    var dropdown = document.createElement("div");
    s(dropdown, {
      display: "none",
      position: "absolute",
      top: "calc(100% + 8px)",
      right: "0",
      background: "#f9f6f0",
      border: "1px solid #e2d9c8",
      minWidth: "180px",
      padding: "0.5rem 0",
      boxShadow: "0 4px 16px rgba(0,0,0,0.06)",
      zIndex: "10000",
      boxSizing: "border-box"
    });

    var emailDiv = document.createElement("div");
    emailDiv.textContent = user.email;
    s(emailDiv, {
      padding: "0.5rem 1rem 0.75rem",
      fontFamily: "'EB Garamond', serif",
      fontSize: "0.875rem",
      color: "#6b5e4e",
      borderBottom: "1px solid #e2d9c8",
      marginBottom: "0.25rem",
      fontStyle: "italic",
      wordBreak: "break-all"
    });

    var profileLink = document.createElement("a");
    profileLink.href = "https://erakh.com/profile";
    profileLink.textContent = "Profile";
    s(profileLink, {
      display: "block",
      width: "100%",
      padding: "0.5rem 1rem",
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      color: "#2a2218",
      textDecoration: "none",
      boxSizing: "border-box",
      textTransform: "none"
    });

    var signOutBtn = document.createElement("button");
    signOutBtn.textContent = "Sign out";
    s(signOutBtn, {
      display: "block",
      width: "100%",
      padding: "0.5rem 1rem",
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      color: "#a04040",
      textAlign: "left",
      background: "transparent",
      border: "none",
      cursor: "pointer",
      boxSizing: "border-box",
      textTransform: "none"
    });
    signOutBtn.addEventListener("click", function () {
      fetch("https://erakh.com/api/auth/logout", { method: "POST", credentials: "include" })
        .then(function () { window.location.href = "https://erakh.com"; });
    });

    dropdown.appendChild(emailDiv);
    dropdown.appendChild(profileLink);
    dropdown.appendChild(signOutBtn);

    avatar.addEventListener("click", function () {
      dropdown.style.display = dropdown.style.display === "none" ? "block" : "none";
    });
    document.addEventListener("click", function (e) {
      if (!profile.contains(e.target)) dropdown.style.display = "none";
    });

    profile.appendChild(avatar);
    profile.appendChild(dropdown);
    right.appendChild(profile);

  } else {
    /* 비로그인 — Sign in */
    var loginBtn = document.createElement("a");
    loginBtn.href = "https://erakh.com/login?redirect=" + encodeURIComponent(window.location.href);
    loginBtn.textContent = "Sign in";
    s(loginBtn, {
      fontFamily: "'Inter', sans-serif",
      fontSize: "0.8125rem",
      fontWeight: "500",
      color: "#2a2218",
      textDecoration: "none",
      padding: "0.4rem 1rem",
      border: "1px solid #c8b99a",
      background: "transparent",
      cursor: "pointer",
      textTransform: "none",
      boxSizing: "border-box",
      lineHeight: "1"
    });
    loginBtn.addEventListener("mouseover", function() {
      this.style.borderColor = "#c8a060";
      this.style.background = "#f0ebe0";
    });
    loginBtn.addEventListener("mouseout", function() {
      this.style.borderColor = "#c8b99a";
      this.style.background = "transparent";
    });
    right.appendChild(loginBtn);
  }

  header.appendChild(left);
  header.appendChild(right);
  document.body.insertBefore(header, document.body.firstChild);
})();