MediaWiki:Common.js: Difference between revisions

From Erakh Codex
Jump to navigation Jump to search
Juoh (talk | contribs)
No edit summary
Juoh (talk | contribs)
header style sync with erakh.com
Line 1: Line 1:
(function () {
(function () {
  /* --- Google Fonts 강제 로드 --- */
   var fontLink = document.createElement("link");
   var fontLink = document.createElement("link");
   fontLink.rel = "stylesheet";
   fontLink.rel = "stylesheet";
Line 6: Line 5:
   document.head.insertBefore(fontLink, document.head.firstChild);
   document.head.insertBefore(fontLink, document.head.firstChild);


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


  /* --- 유저 정보 파싱 --- */
   var user = null;
   var user = null;
   try {
   try {
Line 19: Line 16:
   } catch (e) {}
   } catch (e) {}


  /* --- 인라인 스타일 헬퍼 (important) --- */
   function sp(el, prop, val) {
   function sp(el, prop, val) {
     el.style.setProperty(prop, val, "important");
     el.style.setProperty(prop, val, "important");
   }
   }


  /* --- 헤더 --- */
   var header = document.createElement("header");
   var header = document.createElement("header");
   sp(header, "position", "fixed");
   sp(header, "position", "fixed");
Line 41: Line 36:
   sp(header, "box-sizing", "border-box");
   sp(header, "box-sizing", "border-box");


  /* --- 좌측 --- */
   var left = document.createElement("div");
   var left = document.createElement("div");
   sp(left, "display", "flex");
   sp(left, "display", "flex");
Line 50: Line 44:
   logo.href = "https://erakh.com";
   logo.href = "https://erakh.com";
   logo.textContent = "Erakh Archive";
   logo.textContent = "Erakh Archive";
   sp(logo, "font-family", "'Inter', sans-serif");
   sp(logo, "font-family", "Inter, sans-serif");
   sp(logo, "font-size", "1.125rem");
   sp(logo, "font-size", "1.125rem");
   sp(logo, "font-weight", "500");
   sp(logo, "font-weight", "500");
   sp(logo, "color", "#2a2218");
   sp(logo, "color", "#2a2218");
   sp(logo, "text-decoration", "none");
   sp(logo, "text-decoration", "none");
   sp(logo, "letter-spacing", "-0.01em");
   sp(logo, "letter-spacing", "0.05em");
   sp(logo, "text-transform", "none");
   sp(logo, "text-transform", "none");
   sp(logo, "font-variant", "normal");
   sp(logo, "font-variant", "normal");
Line 69: Line 63:
   codexLink.href = "https://codex.erakh.com";
   codexLink.href = "https://codex.erakh.com";
   codexLink.textContent = "Codex";
   codexLink.textContent = "Codex";
   sp(codexLink, "font-family", "'Inter', sans-serif");
   sp(codexLink, "font-family", "Inter, sans-serif");
   sp(codexLink, "font-size", "1rem");
   sp(codexLink, "font-size", "1rem");
   sp(codexLink, "color", "#6b5e4e");
   sp(codexLink, "color", "#6b5e4e");
Line 83: Line 77:
   left.appendChild(nav);
   left.appendChild(nav);


  /* --- 우측 --- */
   var right = document.createElement("div");
   var right = document.createElement("div");
   sp(right, "display", "flex");
   sp(right, "display", "flex");
Line 89: Line 82:


   if (user && user.email) {
   if (user && user.email) {
    /* 로그인 — 아바타 + 드롭다운 */
     var profile = document.createElement("div");
     var profile = document.createElement("div");
     sp(profile, "position", "relative");
     sp(profile, "position", "relative");
Line 104: Line 96:
     sp(avatar, "justify-content", "center");
     sp(avatar, "justify-content", "center");
     sp(avatar, "cursor", "pointer");
     sp(avatar, "cursor", "pointer");
     sp(avatar, "font-family", "'Inter', sans-serif");
     sp(avatar, "font-family", "Inter, sans-serif");
     sp(avatar, "font-size", "0.75rem");
     sp(avatar, "font-size", "0.75rem");
     sp(avatar, "font-weight", "500");
     sp(avatar, "font-weight", "500");
     sp(avatar, "color", "#2a2218");
     sp(avatar, "color", "#2a2218");
     sp(avatar, "box-sizing", "border-box");
     sp(avatar, "box-sizing", "border-box");
    avatar.addEventListener("mouseover", function() { this.style.setProperty("border-color", "#c8a060", "important"); });
    avatar.addEventListener("mouseout",  function() { this.style.setProperty("border-color", "#c8b99a", "important"); });


     var dropdown = document.createElement("div");
     var dropdown = document.createElement("div");
Line 126: Line 120:
     emailDiv.textContent = user.email;
     emailDiv.textContent = user.email;
     sp(emailDiv, "padding", "0.5rem 1rem 0.75rem");
     sp(emailDiv, "padding", "0.5rem 1rem 0.75rem");
     sp(emailDiv, "font-family", "'Inter', sans-serif");
     sp(emailDiv, "font-family", "Inter, sans-serif");
     sp(emailDiv, "font-size", "0.8125rem");
     sp(emailDiv, "font-size", "0.875rem");
    sp(emailDiv, "font-style", "italic");
     sp(emailDiv, "color", "#6b5e4e");
     sp(emailDiv, "color", "#6b5e4e");
     sp(emailDiv, "border-bottom", "1px solid #e2d9c8");
     sp(emailDiv, "border-bottom", "1px solid #e2d9c8");
Line 139: Line 134:
     sp(profileLink, "width", "100%");
     sp(profileLink, "width", "100%");
     sp(profileLink, "padding", "0.5rem 1rem");
     sp(profileLink, "padding", "0.5rem 1rem");
     sp(profileLink, "font-family", "'Inter', sans-serif");
     sp(profileLink, "font-family", "Inter, sans-serif");
     sp(profileLink, "font-size", "0.8125rem");
     sp(profileLink, "font-size", "0.8125rem");
     sp(profileLink, "color", "#2a2218");
     sp(profileLink, "color", "#2a2218");
     sp(profileLink, "text-decoration", "none");
     sp(profileLink, "text-decoration", "none");
     sp(profileLink, "box-sizing", "border-box");
     sp(profileLink, "box-sizing", "border-box");
    profileLink.addEventListener("mouseover", function() { this.style.setProperty("background", "#f0ebe0", "important"); });
    profileLink.addEventListener("mouseout",  function() { this.style.setProperty("background", "transparent", "important"); });


     var signOutBtn = document.createElement("button");
     var signOutBtn = document.createElement("button");
Line 150: Line 147:
     sp(signOutBtn, "width", "100%");
     sp(signOutBtn, "width", "100%");
     sp(signOutBtn, "padding", "0.5rem 1rem");
     sp(signOutBtn, "padding", "0.5rem 1rem");
     sp(signOutBtn, "font-family", "'Inter', sans-serif");
     sp(signOutBtn, "font-family", "Inter, sans-serif");
     sp(signOutBtn, "font-size", "0.8125rem");
     sp(signOutBtn, "font-size", "0.8125rem");
     sp(signOutBtn, "color", "#a04040");
     sp(signOutBtn, "color", "#a04040");
Line 158: Line 155:
     sp(signOutBtn, "cursor", "pointer");
     sp(signOutBtn, "cursor", "pointer");
     sp(signOutBtn, "box-sizing", "border-box");
     sp(signOutBtn, "box-sizing", "border-box");
    signOutBtn.addEventListener("mouseover", function() { this.style.setProperty("background", "#f0ebe0", "important"); });
    signOutBtn.addEventListener("mouseout",  function() { this.style.setProperty("background", "transparent", "important"); });


     signOutBtn.addEventListener("click", function () {
     signOutBtn.addEventListener("click", function () {
Line 169: Line 168:


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


Line 180: Line 181:


   } else {
   } else {
    /* 비로그인 — 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.textContent = "Sign in";
     loginBtn.textContent = "Sign in";
     sp(loginBtn, "font-family", "'Inter', sans-serif");
     sp(loginBtn, "font-family", "Inter, sans-serif");
     sp(loginBtn, "font-size", "0.8125rem");
     sp(loginBtn, "font-size", "0.8125rem");
     sp(loginBtn, "font-weight", "500");
     sp(loginBtn, "font-weight", "500");

Revision as of 17:46, 11 April 2026

(function () {
  var fontLink = document.createElement("link");
  fontLink.rel = "stylesheet";
  fontLink.href = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&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 sp(el, prop, val) {
    el.style.setProperty(prop, val, "important");
  }

  var header = document.createElement("header");
  sp(header, "position", "fixed");
  sp(header, "top", "0");
  sp(header, "left", "0");
  sp(header, "right", "0");
  sp(header, "z-index", "9999");
  sp(header, "width", "100%");
  sp(header, "background", "#f9f6f0");
  sp(header, "border-bottom", "1px solid #e2d9c8");
  sp(header, "display", "flex");
  sp(header, "align-items", "center");
  sp(header, "justify-content", "space-between");
  sp(header, "padding", "0 2rem");
  sp(header, "height", "56px");
  sp(header, "box-sizing", "border-box");

  var left = document.createElement("div");
  sp(left, "display", "flex");
  sp(left, "align-items", "center");
  sp(left, "gap", "1.75rem");

  var logo = document.createElement("a");
  logo.href = "https://erakh.com";
  logo.textContent = "Erakh Archive";
  sp(logo, "font-family", "Inter, sans-serif");
  sp(logo, "font-size", "1.125rem");
  sp(logo, "font-weight", "500");
  sp(logo, "color", "#2a2218");
  sp(logo, "text-decoration", "none");
  sp(logo, "letter-spacing", "0.05em");
  sp(logo, "text-transform", "none");
  sp(logo, "font-variant", "normal");
  sp(logo, "font-variant-caps", "normal");
  sp(logo, "line-height", "1");

  var nav = document.createElement("nav");
  sp(nav, "display", "flex");
  sp(nav, "align-items", "center");
  sp(nav, "gap", "1.5rem");

  var codexLink = document.createElement("a");
  codexLink.href = "https://codex.erakh.com";
  codexLink.textContent = "Codex";
  sp(codexLink, "font-family", "Inter, sans-serif");
  sp(codexLink, "font-size", "1rem");
  sp(codexLink, "color", "#6b5e4e");
  sp(codexLink, "text-decoration", "none");
  sp(codexLink, "text-transform", "none");
  sp(codexLink, "font-variant", "normal");
  sp(codexLink, "line-height", "1");
  codexLink.addEventListener("mouseover", function() { this.style.setProperty("color", "#2a2218", "important"); });
  codexLink.addEventListener("mouseout",  function() { this.style.setProperty("color", "#6b5e4e", "important"); });

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

  var right = document.createElement("div");
  sp(right, "display", "flex");
  sp(right, "align-items", "center");

  if (user && user.email) {
    var profile = document.createElement("div");
    sp(profile, "position", "relative");

    var avatar = document.createElement("div");
    avatar.textContent = user.email.slice(0, 1).toUpperCase();
    sp(avatar, "width", "32px");
    sp(avatar, "height", "32px");
    sp(avatar, "border-radius", "50%");
    sp(avatar, "background", "#e2d9c8");
    sp(avatar, "border", "1px solid #c8b99a");
    sp(avatar, "display", "flex");
    sp(avatar, "align-items", "center");
    sp(avatar, "justify-content", "center");
    sp(avatar, "cursor", "pointer");
    sp(avatar, "font-family", "Inter, sans-serif");
    sp(avatar, "font-size", "0.75rem");
    sp(avatar, "font-weight", "500");
    sp(avatar, "color", "#2a2218");
    sp(avatar, "box-sizing", "border-box");
    avatar.addEventListener("mouseover", function() { this.style.setProperty("border-color", "#c8a060", "important"); });
    avatar.addEventListener("mouseout",  function() { this.style.setProperty("border-color", "#c8b99a", "important"); });

    var dropdown = document.createElement("div");
    sp(dropdown, "display", "none");
    sp(dropdown, "position", "absolute");
    sp(dropdown, "top", "calc(100% + 8px)");
    sp(dropdown, "right", "0");
    sp(dropdown, "background", "#f9f6f0");
    sp(dropdown, "border", "1px solid #e2d9c8");
    sp(dropdown, "min-width", "180px");
    sp(dropdown, "padding", "0.5rem 0");
    sp(dropdown, "box-shadow", "0 4px 16px rgba(0,0,0,0.06)");
    sp(dropdown, "z-index", "10000");
    sp(dropdown, "box-sizing", "border-box");

    var emailDiv = document.createElement("div");
    emailDiv.textContent = user.email;
    sp(emailDiv, "padding", "0.5rem 1rem 0.75rem");
    sp(emailDiv, "font-family", "Inter, sans-serif");
    sp(emailDiv, "font-size", "0.875rem");
    sp(emailDiv, "font-style", "italic");
    sp(emailDiv, "color", "#6b5e4e");
    sp(emailDiv, "border-bottom", "1px solid #e2d9c8");
    sp(emailDiv, "margin-bottom", "0.25rem");
    sp(emailDiv, "word-break", "break-all");

    var profileLink = document.createElement("a");
    profileLink.href = "https://erakh.com/profile";
    profileLink.textContent = "Profile";
    sp(profileLink, "display", "block");
    sp(profileLink, "width", "100%");
    sp(profileLink, "padding", "0.5rem 1rem");
    sp(profileLink, "font-family", "Inter, sans-serif");
    sp(profileLink, "font-size", "0.8125rem");
    sp(profileLink, "color", "#2a2218");
    sp(profileLink, "text-decoration", "none");
    sp(profileLink, "box-sizing", "border-box");
    profileLink.addEventListener("mouseover", function() { this.style.setProperty("background", "#f0ebe0", "important"); });
    profileLink.addEventListener("mouseout",  function() { this.style.setProperty("background", "transparent", "important"); });

    var signOutBtn = document.createElement("button");
    signOutBtn.textContent = "Sign out";
    sp(signOutBtn, "display", "block");
    sp(signOutBtn, "width", "100%");
    sp(signOutBtn, "padding", "0.5rem 1rem");
    sp(signOutBtn, "font-family", "Inter, sans-serif");
    sp(signOutBtn, "font-size", "0.8125rem");
    sp(signOutBtn, "color", "#a04040");
    sp(signOutBtn, "text-align", "left");
    sp(signOutBtn, "background", "transparent");
    sp(signOutBtn, "border", "none");
    sp(signOutBtn, "cursor", "pointer");
    sp(signOutBtn, "box-sizing", "border-box");
    signOutBtn.addEventListener("mouseover", function() { this.style.setProperty("background", "#f0ebe0", "important"); });
    signOutBtn.addEventListener("mouseout",  function() { this.style.setProperty("background", "transparent", "important"); });

    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 () {
      var isOpen = dropdown.style.display === "none";
      dropdown.style.display = isOpen ? "block" : "none";
    });
    document.addEventListener("click", function (e) {
      var inside = profile.contains(e.target);
      if (inside === false) dropdown.style.display = "none";
    });

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

  } else {
    var loginBtn = document.createElement("a");
    loginBtn.href = "https://erakh.com/login?redirect=" + encodeURIComponent(window.location.href);
    loginBtn.textContent = "Sign in";
    sp(loginBtn, "font-family", "Inter, sans-serif");
    sp(loginBtn, "font-size", "0.8125rem");
    sp(loginBtn, "font-weight", "500");
    sp(loginBtn, "color", "#2a2218");
    sp(loginBtn, "text-decoration", "none");
    sp(loginBtn, "padding", "0.4rem 1rem");
    sp(loginBtn, "border", "1px solid #c8b99a");
    sp(loginBtn, "background", "transparent");
    sp(loginBtn, "cursor", "pointer");
    sp(loginBtn, "box-sizing", "border-box");
    sp(loginBtn, "line-height", "1");
    loginBtn.addEventListener("mouseover", function() {
      this.style.setProperty("border-color", "#c8a060", "important");
      this.style.setProperty("background", "#f0ebe0", "important");
    });
    loginBtn.addEventListener("mouseout", function() {
      this.style.setProperty("border-color", "#c8b99a", "important");
      this.style.setProperty("background", "transparent", "important");
    });
    right.appendChild(loginBtn);
  }

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