403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.216
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/repo/plugins/tsai-plugin/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/plugins/tsai-plugin/assets/js/tsai-ratings.js
(function () {
  'use strict';

  if (typeof window.TsaiRatings === 'undefined') {
    return;
  }

  const cfg = window.TsaiRatings;

  function send(path, method) {
    return fetch(cfg.restUrl + path, {
      method: method,
      credentials: 'same-origin',
      headers: {
        'Content-Type': 'application/json',
        'X-WP-Nonce': cfg.nonce,
      },
      body: method === 'POST' ? JSON.stringify(arguments[2] || {}) : undefined,
    }).then((res) => {
      if (!res.ok) throw new Error('HTTP ' + res.status);
      return res.json();
    });
  }

  // ----- Article stars -----

  function paintStars(widget, mine) {
    const stars = widget.querySelectorAll('.tsai-rating-star');
    stars.forEach((btn, i) => {
      const filled = mine != null && i < mine;
      btn.classList.toggle('is-filled', filled);
      btn.innerHTML = filled ? '★' : '☆';
    });
    widget.dataset.mine = mine == null ? '' : String(mine);
  }

  function updateStarSummary(widget, agg) {
    const sum = widget.querySelector('.tsai-rating-summary');
    if (!sum) return;
    if (agg.count > 0) {
      sum.textContent = agg.average.toFixed(1) + ' (' + agg.count + ')';
    } else {
      sum.textContent = 'No ratings yet';
    }
  }

  document.querySelectorAll('.tsai-rating').forEach((widget) => {
    const postId = widget.dataset.postId;
    widget.querySelectorAll('.tsai-rating-star').forEach((btn) => {
      btn.addEventListener('click', () => {
        const stars = parseInt(btn.dataset.stars, 10);
        const current = widget.dataset.mine ? parseInt(widget.dataset.mine, 10) : null;

        if (current === stars) {
          send('article/' + postId, 'DELETE')
            .then((agg) => {
              paintStars(widget, null);
              updateStarSummary(widget, agg);
            })
            .catch((err) => console.error('tsai-ratings:', err));
        } else {
          send('article/' + postId, 'POST', { stars: stars })
            .then((agg) => {
              paintStars(widget, agg.mine);
              updateStarSummary(widget, agg);
            })
            .catch((err) => console.error('tsai-ratings:', err));
        }
      });
    });
  });

  // ----- Comment thumbs -----

  document.querySelectorAll('.tsai-thumbs').forEach((widget) => {
    const commentId = widget.dataset.commentId;
    const btn = widget.querySelector('.tsai-thumbs-btn');
    const countEl = widget.querySelector('.tsai-thumbs-count');
    if (!btn) return;

    btn.addEventListener('click', () => {
      send('comment/' + commentId, 'POST')
        .then((res) => {
          btn.classList.toggle('is-active', !!res.mine);
          btn.setAttribute('aria-pressed', res.mine ? 'true' : 'false');
          widget.dataset.mine = res.mine ? '1' : '0';
          if (countEl) countEl.textContent = String(res.count);
        })
        .catch((err) => console.error('tsai-ratings:', err));
    });
  });
})();

Youez - 2016 - github.com/yon3zu
LinuXploit