PageSourceSearch

https://www.jbjs.org/components/ads/ads.js?v=8e1ba80c0c

js jbjs.org collected 2026-10-02 04:08:20 UTC 5,482 bytes, 190 lines download raw bytes

1const grapeshotAPIEndpoint = 'https://wolterskluwer.gscontxt.net/main/channels-json.cgi?url=';
2const gptAdsInfo = [
3		{
4			sizeMap: [
5				{ viewport: [ 0, 0 ], size: leaderboardSlotMobile.size || [300, 50] },
6				{ viewport: [ 980, 540 ], size: leaderboardSlotDesktop.size || [ 728, 90 ] }
7			],
8			slots: {
9				'gpt-ad-leaderboard-desktop': {
10					path: leaderboardSlotDesktop.path,
11					size: leaderboardSlotDesktop.size,
12					defaultSize: [ 728, 90 ]
13				},
14				'gpt-ad-leaderboard-mobile': {
15					path: leaderboardSlotMobile.path,
16					size: leaderboardSlotMobile.size,
17					defaultSize: [300, 50]
18				},
19				'gpt-ad-windowshade-desktop': {
20					path: '/15726702761/Mobile/jbjshub',
21					size: [ 728, 90 ]
22				},
23				'gpt-ad-windowshade-mobile': {
24					path: '/15726702761/Mobile/jbjshub',
25					size: [ 300, 50 ]
26				}
27			}
28		},
29		{
30			sizeMap: [ { viewport: [ 0, 0 ], size: skyscraperSlotDesktop.size || [ 160, 600 ] } ],
31			slots: {
32				'gpt-ad-skyscraper': {
33					path: skyscraperSlotDesktop.path,
34					size: skyscraperSlotDesktop.size,
35					defaultSize: [ 160, 600 ]
36				}
37			}
38		},
39		{
40			sizeMap: [ { viewport: [ 0, 0 ], size: [ 240, 200 ] }, { viewport: [ 1200, 0 ], size: [ 300, 250 ] } ],
41			slots: {
42				'gpt-ad-square-desktop': {
43					path: '/15726702761/Mobile/jbjshub',
44					size: [ [ 240, 200 ], [ 300, 250 ] ]
45				}
46			}
47		},
48		{
49			sizeMap: [ { viewport: [ 0, 0 ], size: [ 300, 250 ] } ],
50			slots: {
51				'gpt-ad-square-mobile': {
52					path: '/15726702761/Mobile/jbjshub',
53					size: [ 300, 250 ]
54				}
55			}
56		}
57	];
58
59var gptAdsLoading = false;
60
61function setAdvertisements() {
62	if (!$('.advertisement').children().length) {
63		setAds();
64	}
65}
66
67// Google Publisher Tag
68function setAds(replayId) {
69	// Check if googletag functions are defined
70	adNotBlocked = (typeof(googletag.destroySlots) === "function" && typeof(googletag.pubads) === "function" && typeof(googletag.enableServices) === "function");
71
72	if (!adNotBlocked) {
73		console.error("Ad error: googletag functions not defined.");
74
75		return;
76	}
77
78	var categories = [];
79	$.ajax({
80		url: grapeshotAPIEndpoint + window.location.href,
81		type: 'get',
82	}).done(function (response) {
83		try {
84			//response = '{"channels":[{"name":"gs_science"},{"name":"gs_science_misc"},{"name":"gv_safe"}]}';
85			data = JSON.parse(response);
86			if(data) {
87				gsChannels = data['channels'];
88				if(gsChannels) {
89					$.each(gsChannels, function (i, item) {
90						var category = item.name;
91						if (category) {
92							if (category.match(/^gx_/i)) {
93								console.warn('Grapeshot has returned an unexpected information code. Code: ' + category);
94							}
95							categories.push(category);
96						}
97					});
98				}
99			}
100		} catch (err) {
101		}
102	}).always(function () {
103		addPageTargeting(replayId, categories);
104	});
105}
106
107function addPageTargeting(replayId, categories) {
108	var ads = $((replayId ? '#' + replayId : '') + '.advertisement');
109	if (ads.length && !gptAdsLoading && adNotBlocked) {
110		gptAdsLoading = true;
111
112		var customSize = false;
113
114		googletag.cmd.push(function () {
115			for (var i = 0, l = gptAdsInfo.length; i < l; i++) {
116				var info = gptAdsInfo[i];
117
118				var mapping = googletag.sizeMapping();
119				for (var j = 0, k = info.sizeMap.length; j < k; j++) mapping = mapping.addSize(info.sizeMap[j].viewport, info.sizeMap[j].size)
120				mapping = mapping.build();
121
122				for (var id in info.slots) {
123					const slot = info.slots[id];
124					if (id === replayId) {
125						googletag.destroySlots([ slot.ref ]);
126						slot.ref = null;
127					}
128
129					if (!document.getElementById(id) || slot.ref) continue;
130
131					slot.ref = googletag.defineSlot(slot.path, slot.size || slot.defaultSize, id);
132
133					if (slot.size != null) {
134						customSize = true;
135						document.getElementById(id).parentNode.style.height = slot.size[1] + "px";
136					}
137					slot.ref.defineSizeMapping(mapping).addService(googletag.companionAds()).addService(googletag.pubads());
138				}
139			}
140
141			googletag.pubads().enableSingleRequest();
142			googletag.pubads().setTargeting("UrlSegments", getUrlSegments());
143			googletag.pubads().setTargeting("gs_cat", categories);
144			googletag.pubads().enableVideoAds();
145			googletag.companionAds().setRefreshUnfilledSlots(true);
146			googletag.enableServices();
147		});
148
149
150		ads.each(function (i, item) {
151			googletag.cmd.push(function () { googletag.display(item.id); });
152
153			const parent = $(item).parent();
154
155			if (customSize) {
156				_updateExpandableLayoutBlock(item.id);
157			}
158
159			if (!parent.find('> .advertisement-blocked').length)
160				setTimeout(function (parent) {
161					parent.append(
162						`<div class="advertisement-blocked">
163							<span>Advertisement blocked</span>
164						</div>`
165					);
166				}, 1500, parent);
167		});
168
169		setTimeout(function () { gptAdsLoading = false; }, 1000);
170	}
171}
172
173var getUrlSegments = function (urlWithQueryString) {
174	//chars not allowed in values in DFP ---> " ' = ! + # * ~ ; ^ () < > [ ] , &
175	urlWithQueryString = urlWithQueryString || window.location.href;
176	var url = urlWithQueryString;
177	var segmentsString;
178	var dfpInvalidCharsRegex = /['=!#~;<>&\+\*\^\(\)\[\]\,\"]/g;
179	var urlCharsRegex = /[:/?&=]/g;
180	var spaceCharsRegex = /[ |\s]+/g;
181	//separate segments
182	segmentsString = url.replace(urlCharsRegex, " ");
183	//sanitize the string. remove characters that are not allowed in DFP
184	segmentsString = segmentsString.replace(dfpInvalidCharsRegex, " ");
185	//replace multiple spaces with a single space
186	segmentsString = segmentsString.replace(spaceCharsRegex, " ");
187	return segmentsString;
188}
189
190// End Google Publisher Tag

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.