PageSourceSearch

https://8speed.net/static/dinoportal/js/newsfeed.js?260929023659

js 8speed.net collected 2026-10-10 00:46:47 UTC 17,801 bytes, 548 lines download raw bytes

1$(function(){
2	
3	function _dbg(msg) {
4		($('#dbg')[0] ? $('#dbg') : $('<div id="dbg"></div>').css({position:'fixed',bottom:0,right:0,background:'rgba(0,0,0,.5)',color:'white',zIndex:32767,padding:'10px'}).appendTo('body'))
5			.text(msg);
6	}
7	
8	/* newsfeed append */
9	
10	var RATIO_TARGETS = [
11		'.content-body img[height][width]:visible',
12		'.content-body img[data-ratio]:visible',
13		'.content-body iframe[height][width]',
14		'.content-body iframe[data-ratio]',
15		'.content-body video[height][width]',
16		'.content-body video[data-ratio]',
17		'.content-body-leading img[height][width]:visible',
18		'.content-body-leading img[data-ratio]:visible',
19		'.content-body-leading iframe[height][width]',
20		'.content-body-leading iframe[data-ratio]',
21		'.content-body-leading video[height][width]',
22		'.content-body-leading video[data-ratio]'
23	].join(',');
24	
25	function adjustRatio() {
26		$(RATIO_TARGETS).filter(':not(.ratio-wrapped)').ratiobox().addClass('ratio-wrapped').closest('.ratio-wrap').css('width','100%');
27	}
28	
29	adjustRatio();
30	
31	function checkLimitedContents(){
32		
33		// ログイン時のみチェック
34		var is_logined = $('body').is('.ptluser-logined');
35		if (!is_logined) { return; }
36		
37		var $check_limited_contents = 
38				$('.wfcontent[data-content][data-limited="unknown"], .widget-content[data-content][data-limited="unknown"]')
39					.attr('data-limited', 'checking'),
40			content_limited_ids = 
41				$check_limited_contents.map(function(){
42						return $(this).attr('data-content');
43					}).toArray().join(',');
44		
45		$.ajax({
46			url:'/_psr/_api/content/are_readable',
47			type:'post',
48			data:{content_ids:content_limited_ids},
49			dataType:'json',
50		})
51		.then(function(res){
52			if (res.result != 'ok') {
53				return;
54			}
55			var unlocked = res.data.unlocked_content_ids.reduce(function(p,c,i,a){ p[c] = true; return p}, {})
56			$check_limited_contents
57				.each(function(){
58					$(this).attr(
59							'data-limited',
60							unlocked[$(this).attr('data-content')] ? 'unlocked' : 'locked'
61						)
62				});
63		})
64		.fail(function(){
65			$check_limited_contents.attr('data-limited', 'failed')
66		});
67	}
68	checkLimitedContents();
69	$(document).on('autopaged', checkLimitedContents);
70	setInterval(function(){
71		if ($('.wfcontent[data-content][data-limited="failed"]').attr('data-limited', 'unknown')[0]) {
72			checkLimitedContents();
73		}
74	}, 10000);
75	
76	var referrer = location.href;
77	
78	function appendNext() {
79		console.log('appendNext()');
80		var $place = $('a#newsfeed-next'),
81			_d = $place.data('_d');
82		if (_d) {
83			return _d;
84		}
85		if ($place[0]) {
86			var href = location.pathname,
87				do_post = !!($place.attr('data-dopost')),
88				data = (function(s,D,r){
89					s.replace(/([^?=&]+)(?:=([^&]*))?/g, function(a,k,v){r[D(k)]=D(v)});
90					return r;
91				})($place[0].search, decodeURIComponent, {});
92			$place.addClass('loading');
93			var ret = $.ajax({
94					type:(do_post ? 'post' : 'get'),
95					data:data,
96					url:href,
97				})
98			.always(function(){
99				$place.removeClass('loading');
100			})
101			.then(function(res){
102				
103				// piwik virtual pageup
104				var additional;
105				var title = document.title;
106				window._piwik && window._piwik.pageview && window._piwik.pageview(href, title, referrer);
107				
108				var $res = $(res);
109				
110				if ($res.children('html')[0]) {
111					console.error('invalid response html:', href, res);
112					return;
113				}
114				
115				// ページング重複除去
116				$res = $res.filter(function(){
117					var $content = $(this), ret = true;
118					if ($content.is('.wfcontent[data-content]')) {
119						var content_id = $content.attr('data-content');
120						if ($place.prevAll('.wfcontent[data-content="'+content_id+'"]')[0]){
121							console.log('remove duplicated content:' + content_id);
122							ret = false;
123						}
124					}
125					return ret;
126				});
127				
128				// mark
129				$res.first().attr('data-href', href);
130				
131				$place.replaceWith($res);
132				adjustRatio();
133				
134				if (window._acs_pvup_when_appended) {
135					// virtual pageview
136					if (window._use_acs_feed_dummy) {
137						$('#ifr-dummy-acs').remove();
138						var $ifr = $('<iframe id="ifr-dummy-acs"></iframe>').css({
139							position:'fixed',
140							top:'-1px',
141							left:'-1px',
142							width:'1px',
143							height:'1px',
144							opacity:0,
145							'-moz-opacity':0,
146							border:'none',
147							outline:0,
148							padding:0,
149							margin:0
150						})
151						.attr({
152							src:href.split('?')[0] + '?acs='+ encodeURIComponent(referrer) + (additional ? '&' + additional : '') + '&_ts=' + (new Date()).getTime()
153						})
154						.appendTo('body');
155					}
156				} else {
157					if (window.ga) {
158						try {
159							ga('send', 'event', 'dno_old_pageview', 'append', href);
160						} catch (ex) {
161							console.error(ex);
162						}
163					}
164				}
165				
166				referrer = href;
167				
168				$(document).trigger('autopaged', [referrer, $res]);
169				$(document).trigger('virtualpv', [
170					// フルURL化
171					$('<a>').attr('href', referrer).prop('href'),
172					$('<a>').attr('href', this.url).prop('href'),
173					'feedpaging']);
174			}).fail(function(){
175				$place.replaceWith('<div class="network-error"><span></span></div>');
176			});
177			$place.data('_d', ret);
178			return ret;
179		} else {
180			var _d = $.Deferred();
181			_d.resolve();
182			return _d;
183		}
184	}
185	
186	$(document).on('click', '#newsfeed-next', function(ev){
187		ev.preventDefault();
188		appendNext();
189	});
190	
191	$(document)
192		.on('autopaging', function(){
193			appendNext()
194				.then(function(){
195					if ($('#newsfeed-next')[0]) {
196						// console.error('#newsfeed-next:found');
197						$(document).trigger('startautopaging', ['#newsfeed-next']);
198					}
199				});
200			})
201		.trigger('startautopaging', ['#newsfeed-next']);
202	
203	if ($('.prevent-autopaging')[0]) {
204		$('#newsfeed > .newsfeed-container > #newsfeed-next').filter(':only-child').trigger('click');
205	}
206	
207	if (!window._acs_pvup_when_appended) {
208		function iframeFakePageviewUp(referrer, additional){
209			if (window._use_acs_feed_dummy) {
210				$('#ifr-dummy-acs').remove();
211				var $ifr = $('<iframe id="ifr-dummy-acs"></iframe>').css({
212					position:'fixed',
213					top:'-1px',
214					left:'-1px',
215					width:'1px',
216					height:'1px',
217					opacity:0,
218					'-moz-opacity':0,
219					border:'none',
220					outline:0,
221					padding:0,
222					margin:0
223				})
224				.attr({
225					src:location.href.split('?')[0] 
226						+ '?acs='+ encodeURIComponent(referrer)
227						+ (window._is_preview_custom ? '&_for_preview_custom=1' : '')
228						+ (additional ? '&' + additional : '')
229						+ '&_ts=' + (new Date()).getTime()
230				})
231				.appendTo('body');
232			}
233		}
234		var autopaged = 0;
235		$(document)
236			.on('autopaged', function(ev, referrer, $appended){
237				// virtual pageview
238				iframeFakePageviewUp(referrer, 'appended=' + (autopaged++))
239			})
240			.on('changehref', function(ev, referrer, additional){
241				// virtual pageview
242				iframeFakePageviewUp(referrer, additional);
243			});
244	}
245	
246	// for ad
247	if ($('#newsfeed').is('.newsfeed-all-display-type-card')) {
248		// var $adstyle = $();
249		/*
250		$(window).on('resize.forad', function(){
251			$.setStyle('.wfcontent-container { height: ' + $('.wfcontent:first-child .wfcontent-container').outerHeight() + 'px; }', 'styles-wfcontent-container');
252		}).trigger('resize.forad');
253		*/
254	}
255	function nativeAdVisible(){
256		$('.wfcontent.is-nativead').not(':visible').each(function(){
257			var $t = $(this);
258			$t.prev('.wfcontent:not(.is-nativead):visible').before($t);
259			console.log('native ad visualized');
260		});
261	}
262	nativeAdVisible();
263	
264	// carousel
265	$('.newsfeed-block.newsfeed-all-display-type-carousel .carousel').each(function(){
266		// /_news 決め打ち
267		$(this).find('.carousel-content').last().append(
268			$('<label class="carousel-next carousel-more"><a href="/_news"></a></label>')
269		);
270	});
271	
272	// search focus
273	$('body.page-freeq #free_q-heading input[name="q"]').trigger('focus');
274	
275	// marble
276	(function(){
277		
278		if (!window._customized.newsfeed_marble) { return; }
279		
280		var $marblebars = $('#main-contents-container > .widgets > span.marblebar[data-marblebar-insert]'),
281				$marbles = $('#main-contents-container > .widgets > div.marble[data-marble-insert]');
282		console.info('marbles found', $marblebars, $marbles);
283		
284		if (!$marblebars[0] && !$marbles[0]) { return; }
285		
286		var _t = setInterval(function(){
287			$('link[href^="/static/dinoportal/css/newsfeed-flex.css"]').each(function(){
288				$(this).attr('href', $(this).attr('href').replace('/newsfeed-flex.css', '/newsfeed-flex-new.css'));
289				clearInterval(_t);
290				console.info('marble:newsfeed-flex.css replaced', this);
291			});
292		}, 100);
293		
294		var MARBLEBARS_POS_DEF = {
295				'#newsfeed.newsfeed-all-display-type-flex':[1,3,11,16,22], 
296				'body:not(.custom-feed-card-mobile-2cols) #newsfeed.newsfeed-all-display-type-photo':[3,6,9,12,15],
297				'body:not(.custom-feed-card-mobile-2cols) #newsfeed.newsfeed-all-display-type-card':[3,6,9,12,15],
298				'body.custom-feed-card-mobile-2cols #newsfeed.newsfeed-all-display-type-photo':[3,9,15,21,27],
299				'body.custom-feed-card-mobile-2cols #newsfeed.newsfeed-all-display-type-card':[3,9,15,21,27],
300			},
301			marblebar_pos = [1, 3, 11, 16, 22];
302		
303		Object.keys(MARBLEBARS_POS_DEF).some(function(key){
304			if ($(key)[0]) {
305				marblebar_pos = MARBLEBARS_POS_DEF[key];
306				console.info('marblebar:type:' + key, marblebar_pos);
307				return true;
308			}
309		});
310		
311		function insertMarbleBars(){
312			// marble bar pos = 1:2, 3:4, 11:12, 16:17, 22:23
313			$('#main-contents-container > .widgets > span.marblebar[data-marblebar-insert]')
314				.sort(function(a, b){
315					a = parseInt($(a).attr('data-marblebar-insert'), 10);
316					b = parseInt($(b).attr('data-marblebar-insert'), 10);
317					return a < b ? -1 : 1;
318				})
319				.each(function(){
320					var $contents = $('#newsfeed > .newsfeed-container > .wfcontent'),
321							$marblebar = $(this),
322							pos = marblebar_pos[parseInt($marblebar.attr('data-marblebar-insert'), 10) - 1];
323					if ($contents.length > pos) {
324						$($contents[pos]).before($marblebar.addClass('marblebar-inserted'));
325						console.info('marblebar:inserted', $marblebar);
326					}
327				});
328		}
329		
330		function insertMarbles(){
331			$('#main-contents-container > .widgets > div.marble[data-marble-insert]')
332				.sort(function(a, b){
333					a = parseInt($(a).attr('data-marble-insert'), 10);
334					b = parseInt($(b).attr('data-marble-insert'), 10);
335					return a < b ? -1 : 1;
336				})
337				.each(function(){
338					var $contents = $('#newsfeed > .newsfeed-container > .wfcontent'),
339							$marble = $(this),
340							pos = parseInt($marble.attr('data-marble-insert'), 10);
341					if ($contents.length > pos-1) {
342						$($contents[pos-1]).before($marble.addClass('wfcontent').addClass('marble-inserted'));
343						console.info('marble:inserted', $marble);
344					}
345				});
346		}
347		insertMarbles();
348		insertMarbleBars();
349		$(document).on('autopaging.marble', function(){
350			insertMarbles();
351			insertMarbleBars();
352		});
353	})();
354	
355	// infeed nativead
356	(function(){
357		if (window.USE_SERVERSIDE_NATIVEAD_INFEED || $('body').is('.page-stags')) { return; }
358		var $nativead_first_placed = $('.wfcontent[data-content].is-nativead:visible'),
359			has_nativead_first_placed = !!($nativead_first_placed[0]),
360			$target_menufeed_blocks = $('.newsfeed-block').filter(function(){
361				// 先頭固定が台紙になく、2つ以上記事があるブロックのみ対象
362				var block_type = $(this).attr('data-newsfeed-block-type');
363				var $contents = $(this).find('.newsfeed-block-contents-container > .wfcontent:visible');
364				return ["contents-news","contents-tag"].indexOf(block_type) >= 0
365					&& !$(this).is('.newsfeed-all-display-type-carousel')
366					&& !($contents.first().is('.is-nativead'))
367					&& $contents.length >= 2;
368			}),
369			$newsfeed = $('#newsfeed .newsfeed-container'),
370			nativead_required_count =
371				$target_menufeed_blocks.length // メニューフィードではブロック数
372				|| ($newsfeed.children('.wfcontent:visible').length > 10) ? 2 : 1; // 少なければ1、それ以外は2
373		
374		if ($target_menufeed_blocks[0]) {
375			console.info('nativead:$target_menufeed_blocks', $target_menufeed_blocks.toArray());
376		}
377		
378		function shuffle(array){
379			for (var i=array.length-1;i>0;i--){
380				var r = Math.floor(Math.random()*(i+1));
381				array[r] = [array[i], array[i]=array[r]][0];
382			}
383			return array;
384		}
385		
386		function insert_nativeads($target_newsfeed_contents, require_first_place) {
387			
388			/* 固定コンテンツ一覧、検索結果にはnativeadを入れない */
389			if (window.USE_SERVERSIDE_NATIVEAD_INFEED
390					|| $('body').is('.page-stags')
391					|| $('body').is('.page-freeq')) {
392				return;
393			}
394			
395			if (require_first_place && !has_nativead_first_placed) {
396				console.error('insert_nativeads: first placed not found in HTML');
397				require_first_place = false;
398			}
399			var data = {
400					total_count:nativead_required_count,
401					impl_url:location.href,
402				};
403			if (require_first_place) {
404				data.newsfeed_first_place = 1;
405			}
406			if ($target_menufeed_blocks[0]) {
407				data.for_menufeed = 1;
408				data.total_count = $target_menufeed_blocks.length;
409			}
410			if ($('body').is('.page-newsfeed')) {
411				data.for_newsfeed = 1;
412			}
413			var tag = $('body').attr('data-page-tag'),
414				tag_id = $('body').attr('data-page-tagid');
415			if (tag_id) {
416				data.for_tag = tag_id;
417			}
418			
419			console.info('insert_nativead:require', data, $target_newsfeed_contents.toArray());
420			$.ajax({
421				url:'/_api/v1/dinoportal/nativead/get_contents_for_listing',
422				type:'get',
423				dataType:'json',
424				data:data,
425			}).then(function(res){
426				console.info('insert_nativead:get', res);
427				if (res && res.result == 'ok') {
428					
429					// 先頭固定はHTML出力済み : チェックだけしておく
430					if (res.data.newsfeed_first_place_content) {
431						if (!has_nativead_first_placed) {
432							// ここには来ないはず
433							console.error('insert_nativead: nativead firstplaced not found.')
434						} else if ($nativead_first_placed.attr('data-content') != ''+res.data.newsfeed_first_place_content.id){
435							// 台紙にあるADとAPIが返してきたものが違う
436							console.error('insert_nativead: nativead firstplaced is different', $nativead_first_placed, res.data.newsfeed_first_place_content);
437						}
438					}
439					
440					if (res.data.html.contents) {
441						// ランダム挿入
442						console.info('insert_nativead:will insert ' + res.data.contents.length + ' contents');
443						
444						var insert_contents = $(res.data.html.contents).filter('.wfcontent.is-nativead[data-content]').toArray();
445						
446						if (!insert_contents[0]) { return; }
447						
448						if ($target_menufeed_blocks[0]) {
449							$target_menufeed_blocks.each(function(){
450								var $contents = $(this).find('.newsfeed-block-contents-container > .wfcontent:visible');
451								// menufeed で先頭固定がない場合に2番目に必ず入れる
452								console.info('insert_nativead:insert', insert_contents[0]);
453								$contents.eq(0).after(insert_contents.shift());
454								if (!insert_contents[0]) {
455									return false; // break;
456								}
457							});
458						} else {
459							var targets = $target_newsfeed_contents.toArray();
460							console.info('insert_nativead:targets', targets);
461							
462							if (!require_first_place) {
463								// 先頭固定がなければ2番目には必ず入れる
464								console.info('insert_nativead:insert at 2nd - no first placed', insert_contents[0]);
465								$target_newsfeed_contents.eq(0).after(insert_contents.shift());
466								targets.shift();targets.shift();
467								
468								// marble 再調整
469								$target_newsfeed_contents.eq(0)
470									.nextAll('.marblebar-inserted, .widget-wrap')
471										.each(function(){
472											$(this).insertBefore($(this).prev());
473										})
474										.end()
475									.nextAll('.marble-inserted')
476										.each(function(){
477											$(this).insertBefore($(this).prevAll('.wfcontent').eq(0));
478										})
479										.end();
480								
481							} else {
482								targets.shift();
483							}
484							if (insert_contents[0]) {
485								// 残りの位置のランダムな場所に入れる
486								shuffle(targets).splice(0, insert_contents.length).forEach(function(v, i){
487									console.info('insert_nativead\n', insert_contents[0], '\nbefore', v);
488									$(v).before(insert_contents.shift());
489									
490									// marble 再調整
491									$(v)
492										.nextAll('.marblebar-inserted, .widget-wrap')
493											.each(function(){
494												$(this).insertBefore($(this).prev());
495											})
496											.end()
497										.nextAll('.marble-inserted')
498											.each(function(){
499												$(this).insertBefore($(this).prevAll('.wfcontent').eq(0));
500											})
501											.end();
502									
503								});
504								
505								if (insert_contents[0]) {
506									console.error('insert_nativead:NOT INSERTED CONTENTS', insert_contents);
507								}
508							}
509						}
510						
511						// すべて入り表示されているか自己チェック
512						if (res.data.newsfeed_first_place_content) {
513							var content_id = res.data.newsfeed_first_place_content.id;
514								$inserted = $('.wfcontent[data-content="'+content_id+'"].is-nativead:visible');
515								if (!$inserted[0]){
516									console.error('insert_nativead:NOT INSERTED!', content_id);
517								}
518						}
519						if (res.data.contents) {
520							res.data.contents.forEach(function(content){
521								var content_id = content.id,
522									$inserted = $('.wfcontent[data-content="'+content_id+'"].is-nativead:visible');
523								if (!$inserted[0]){
524									console.error('insert_nativead:NOT INSERTED!', content_id);
525								}
526							});
527						}
528					}
529				}
530			});
531		}
532		
533		var $target_newsfeed_contents = $newsfeed.children('.wfcontent[data-content]:visible');
534		insert_nativeads($target_newsfeed_contents, has_nativead_first_placed);
535		
536		$(document).on('autopaged', function(ev, referrer, $appended){
537			insert_nativeads($appended.filter('.wfcontent'), false);
538		});
539		
540	})();
541	
542	$(document).on('autopaged', function(){
543		$(document).trigger('updatebookmarks');
544	});
545	
546});
547
548

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.