PageSourceSearch

https://www.kaken.or.jp/cms/kaken/js/ga-cookie-opt-in.js

js kaken.or.jp collected 2026-10-02 06:20:38 UTC 5,199 bytes, 105 lines download raw bytes

1const GA_ID = 'UA-29779093-8';
2const GA_DOMAIN = 'www.kaken.or.jp';
3
4function setCookie(name, value, days) {
5  var expires = "";
6  if (days) {
7    var date = new Date();
8    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
9    expires = "; expires=" + date.toUTCString();
10  }
11  document.cookie = name + "=" + (value || "") + expires + "; path=/;domain=" + GA_DOMAIN;
12}
13
14function getCookie(name) {
15  var nameEQ = name + "=";
16  var ca = document.cookie.split(';');
17  for (var i = 0; i < ca.length; i++) {
18    var c = ca[i];
19    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
20    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
21  }
22  return null;
23}
24
25function eraseCookie(name) {
26  document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + GA_DOMAIN;
27}
28
29window.addEventListener('DOMContentLoaded', function () {
30
31  'use strict';
32  //localStorage から ga_cookie_opt_in の値を取得
33  const cookieOptin = getCookie('ga_cookie_opt_in');
34
35  //ga_cookie_opt_in = no なら Google Analytics を無効に
36  if (cookieOptin == 'no') {
37    console.log('ga_cookie_opt_in = no / ga-disable = true');
38    //Disable Google Analytics(UA-XXXX-Y の部分は正しいものに書き換えてください)
39    window['ga-disable-${GA_ID}'] = true;
40
41    //ga_cookie_opt_in = yes なら Google Analytics トラッキングコードを発行
42  } else if (cookieOptin == 'yes') {
43    console.log('ga_cookie_opt_in = yes');
44    //Enable Google Analytics(UA-XXXX-Y の部分は正しいものに書き換えてください)
45    window['ga-disable-${GA_ID}'] = false;
46
47    //ga_cookie_opt_in に値がない場合は一旦 Google Analytics を無効にして通知を表示
48  } else {
49    console.log('ga_cookie_opt_in = null');
50    //Disable Google Analytics(UA-XXXX-Y の部分は正しいものに書き換えてください)
51    window['ga-disable-${GA_ID}'] = true;
52
53    // ↓Google Web Fonts から Material Icons を読み込み(すでに別で読み込んでいる場合は削除可)↓
54    const iconcss = document.createElement('link');
55    iconcss.href = 'https://fonts.googleapis.com/icon?family=Material+Icons';
56    iconcss.setAttribute('rel', 'stylesheet');
57    document.head.appendChild(iconcss);
58    // ↑Google Web Fonts から Material Icons を読み込み(すでに別で読み込んでいる場合は削除可)↑
59    // 通知バーのスタイル(パスは必要に応じて変更してください)
60    const acceptcss = document.createElement('link');
61    acceptcss.href = '/cms/kaken/css/ga-cookie-opt-in.css';
62    acceptcss.setAttribute('rel', 'stylesheet');
63    document.head.appendChild(acceptcss);
64
65    //通知の表示(テキストの内容やプライバシーポリシーへのリンクは必要に応じて変更してください)
66    const accept = document.createElement('div');
67    accept.setAttribute('class', 'module-ga-cookie-accept-bar');
68    accept.setAttribute('id', 'name-ga-cookie-accept-bar');
69    accept.innerHTML = '<p><i class="material-icons" aria-hidden="true">warning</i>当社のウェブサイトは、お客様の利便性向上、ウェブサイトの改善等を目的に、Cookieを使用しております。<br>詳しくは<a href="/cookiepolicy">Cookieポリシー</a>をご覧ください。Cookieの利用に同意頂ける場合は、「同意する」ボタンを押してください。</p><p><button id="name-ga-cookie-accept-btn" class="module-ga-cookie-accept-btn"><i class="material-icons" aria-hidden="true">check</i>同意する</button> <button id="name-ga-cookie-deny-btn" class="module-ga-cookie-accept-btn module-ga-cookie-deny-btn"><i class="material-icons" aria-hidden="true">close</i>同意しない</button></p>';
70    document.body.appendChild(accept);
71  }
72
73  //各ボタンの取得
74  const acceptBtn = document.getElementById('name-ga-cookie-accept-btn');
75  const denyBtn = document.getElementById('name-ga-cookie-deny-btn');
76  const resetBtn = document.getElementById('name-ga-cookie-reset-btn');
77
78  //「同意する」ボタンのクリックでオプトイン(ga_cookie_opt_in = yes)
79  if (acceptBtn) {
80    acceptBtn.onclick = function () {
81      setCookie('ga_cookie_opt_in', 'yes', 3650);
82      document.getElementById('name-ga-cookie-accept-bar').classList.add('state-remove');
83      //CSS Animation が完了するまで待機するための力技……
84      window.setTimeout('window.location.reload(false)', 500);
85    };
86  }
87
88  //「同意しない」ボタンのクリックでオプトアウト(ga_cookie_opt_in = no)
89  if (denyBtn) {
90    denyBtn.onclick = function () {
91      setCookie('ga_cookie_opt_in', 'no');
92      document.getElementById('name-ga-cookie-accept-bar').classList.add('state-remove');
93      window.setTimeout('window.location.reload(false)', 500);
94    };
95  }
96
97  //「設定をリセット」ボタンのクリックで ga_cookie_opt_in の値を削除
98  if (resetBtn) {
99    resetBtn.onclick = function () {
100      eraseCookie('ga_cookie_opt_in');
101      location.reload();
102    };
103  }
104
105});

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.