PageSourceSearch

https://www.sony.jp/share5/js/related-item-cookie.js

js sony.jp collected 2026-10-01 08:45:57 UTC 2,437 bytes, 98 lines download raw bytes

1document.addEventListener( 'DOMContentLoaded', function () {
2
3	// # 買い回りCookie 保存用
4	//
5	// 特定商品をカートに入れた際、Cookieに関連商品IDを保存して、
6	// 購入ページでそれらを表示する準備のためのライブラリ
7
8	'use strict';
9
10	var ONE_SECOND = 1000;
11	var ONE_MINUTE = 60 * ONE_SECOND;
12	var HALF_HOUR  = 30 * ONE_MINUTE;
13	var ATTR_IDS_MAX_LENGTH = 3; // カンマ区切りで登録できるrelated-item-idsの上限数
14	var ATTR_IDS   = 'data-s5-storeInfo-related-item-ids';
15	var ATTR_URL   = 'data-s5-storeInfo-related-currenturl';
16	var ATTR_TITLE = 'data-s5-storeInfo-related-currenttitle';
17
18	var $body = document.body;
19
20	$body.addEventListener( 'click', function ( event ) {
21
22		var selector = '[' + ATTR_IDS + ']';
23		var delegateTarget = closest( event.target, selector );
24
25		if ( !! delegateTarget ) {
26
27			var pg_id = delegateTarget.getAttribute( ATTR_IDS ).replace( /\s/g, '' ).split( ',' );
28			var url   = delegateTarget.getAttribute( ATTR_URL );
29			var title = delegateTarget.getAttribute( ATTR_TITLE );
30
31			// pg_idの指定が空の場合、cookieは作らない。
32			if ( ! pg_id[ 0 ] ) return;
33
34			if ( pg_id.length >= ATTR_IDS_MAX_LENGTH ) pg_id.length = ATTR_IDS_MAX_LENGTH;
35
36			var cookieValue = {
37				pg_id: pg_id,
38				url  : url,
39				title: title
40			};
41
42			var now = Date.now();
43			var expirationDate = new Date( now + HALF_HOUR );
44
45			var sKey    = 'frp',
46			    sValue  = JSON.stringify( cookieValue ),
47			    vEnd    = expirationDate.toGMTString(),
48			    sPath   = '/',
49			    sDomain = '.sony.jp',
50			    bSecure = location.protocol === 'https:';
51
52			s5.docCookies.setItem( sKey, sValue, vEnd, sPath, sDomain, bSecure );
53
54		}
55
56	} );
57
58	function closest ( element, selector ) {
59
60		var DOCUMENT_NODE_TYPE = 9;
61
62		while ( element && element.nodeType !== DOCUMENT_NODE_TYPE ) {
63
64			if ( elementMatches( element, selector ) ) {
65
66				return element;
67
68			}
69
70			element = element.parentNode;
71
72		}
73
74	}
75
76	function elementMatches ( element, selector ) {
77
78		if ( !! Element.prototype.matches ) {
79
80			return element.matches( selector );
81
82		}
83
84		if ( !! Element.prototype.msMatchesSelector ) {
85
86			return element.msMatchesSelector( selector );
87
88		}
89
90		if ( !! Element.prototype.webkitMatchesSelector ) {
91
92			return element.webkitMatchesSelector( selector );
93
94		}
95
96	}
97
98} );

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.