PageSourceSearch

https://www.advertimes.com/wp-content/themes/swell_advertimes/build/js/reaction.js?ver=2026093080244

js advertimes.com collected 2026-10-02 03:05:21 UTC 2,962 bytes, 94 lines download raw bytes

1!(function () {
2  let post_id = post_data.post_id
3  // Cookieからリアクションのデータを取得する関数
4  function getReactionsFromCookie() {
5    var cookieValue = getCookie("reactions_cookie")
6    if (cookieValue) {
7      return JSON.parse(cookieValue)
8    } else {
9      return {}
10    }
11  }
12
13  // Cookieにリアクションのデータを保存する関数
14  function setReactionToCookie(postId, reaction) {
15    var reactions = getReactionsFromCookie()
16    reactions[postId] = reaction
17    var cookieValue = JSON.stringify(reactions)
18    setCookie("reactions_cookie", cookieValue, 30) // 30日間有効なCookieを設定
19  }
20
21  // Cookieから特定のpost_idのリアクションを取得する関数
22  function getReactionForPostId(postId) {
23    var reactions = getReactionsFromCookie()
24    return reactions[postId]
25  }
26
27  // Cookieを設定する関数
28  function setCookie(name, value, days) {
29    var expires = ""
30    if (days) {
31      var date = new Date()
32      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
33      expires = "; expires=" + date.toUTCString()
34    }
35    document.cookie = name + "=" + value + expires + "; path=/;"
36  }
37
38  // Cookieから値を取得する関数
39  function getCookie(name) {
40    var nameEQ = name + "="
41    var cookies = document.cookie.split(";")
42    for (var i = 0; i < cookies.length; i++) {
43      var cookie = cookies[i]
44      while (cookie.charAt(0) === " ") {
45        cookie = cookie.substring(1, cookie.length)
46      }
47      if (cookie.indexOf(nameEQ) === 0) {
48        return cookie.substring(nameEQ.length, cookie.length)
49      }
50    }
51    return null
52  }
53
54  function reactionBtnActivate(reaction = null) {
55    let current_reaction = reaction ?? getReactionForPostId(post_id)
56    if (current_reaction) {
57      $(
58        '.count-button:not([data-reaction="' + current_reaction + '"])'
59      ).addClass("inactive")
60      $('[data-reaction="' + current_reaction + '"]').addClass("active")
61    }
62  }
63
64  jQuery(document).ready(function ($) {
65    $(".count-button").on("click", function () {
66      let _this = $(this)
67      if (_this.hasClass("active") || _this.hasClass("inactive")) {
68        console.log("already send reaction...")
69        return
70      }
71
72      let reaction = _this.data("reaction")
73      reactionBtnActivate(reaction)
74      $.ajax({
75        type: "POST",
76        url: swellVars.ajaxUrl,
77        data: {
78          action: "update_count", // サーバー側での処理を識別するアクション名
79          post_id: post_id,
80          reaction: reaction,
81        },
82        success: function (response) {
83          console.log("reaction", post_id, reaction)
84          setReactionToCookie(post_id, reaction)
85          var countElement = _this.find(".p-reaction__count")
86          if (countElement.length > 0) {
87            countElement.text(response) // 新しい値を設定して表示する
88          }
89        },
90      })
91    })
92    reactionBtnActivate()
93  })
94})()

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.