PageSourceSearch

https://krb.nl/wp-content/plugins/krb-strandposten/assets/krb-strandposten.js?ver=1.5.0

js krb.nl collected 2026-10-03 00:17:12 UTC 2,447 bytes, 95 lines download raw bytes

1/**
2 * KRB Strandposten - bijwerken zonder pagina-herlaad.
3 *
4 * Twee taken:
5 * 1. "Live": direct na het laden de actuele gegevens ophalen. Dat is nodig
6 *    omdat de HTML van een pagina met page-cache (WP Rocket, LiteSpeed,
7 *    Cloudflare, ...) uren oud kan zijn terwijl de vlag inmiddels is gewisseld.
8 * 2. "Verversen": daarna periodiek herhalen zolang het tabblad zichtbaar is.
9 */
10( function () {
11	'use strict';
12
13	if ( typeof window.krbStrandposten === 'undefined' || ! window.fetch ) {
14		return;
15	}
16
17	var endpoint = window.krbStrandposten.endpoint;
18
19	function refresh( el ) {
20		var args = el.getAttribute( 'data-krb-args' );
21
22		if ( ! args ) {
23			return;
24		}
25
26		var url = endpoint
27			+ ( endpoint.indexOf( '?' ) === -1 ? '?' : '&' )
28			+ 'args=' + encodeURIComponent( args )
29			// Cache-buster: houdt tussenliggende caches en de browser buiten spel.
30			+ '&_=' + Date.now();
31
32		el.classList.add( 'is-refreshing' );
33
34		fetch( url, { credentials: 'same-origin', cache: 'no-store' } )
35			.then( function ( response ) {
36				return response.ok ? response.json() : Promise.reject( response.status );
37			} )
38			.then( function ( data ) {
39				if ( data && typeof data.html === 'string' ) {
40					el.innerHTML = data.html;
41					el.classList.toggle( 'krb-sp--stale', !! data.stale );
42					el.classList.add( 'is-live' );
43				}
44			} )
45			.catch( function () {
46				/* Stil falen: de bestaande weergave blijft gewoon staan. */
47			} )
48			.then( function () {
49				el.classList.remove( 'is-refreshing' );
50			} );
51	}
52
53	function start() {
54		var nodes = document.querySelectorAll( '.krb-sp[data-krb-args]' );
55
56		Array.prototype.forEach.call( nodes, function ( el ) {
57			var seconds = parseInt( el.getAttribute( 'data-krb-refresh' ), 10 );
58			var live    = '1' === el.getAttribute( 'data-krb-live' );
59
60			if ( live ) {
61				refresh( el );
62			}
63
64			if ( ! seconds || seconds < 30 ) {
65				return;
66			}
67
68			setInterval( function () {
69				if ( document.hidden ) {
70					return;
71				}
72
73				refresh( el );
74			}, seconds * 1000 );
75		} );
76
77		// Terug op het tabblad na een tijdje weg: meteen bijwerken.
78		document.addEventListener( 'visibilitychange', function () {
79			if ( document.hidden ) {
80				return;
81			}
82
83			Array.prototype.forEach.call(
84				document.querySelectorAll( '.krb-sp[data-krb-live="1"]' ),
85				refresh
86			);
87		} );
88	}
89
90	if ( document.readyState === 'loading' ) {
91		document.addEventListener( 'DOMContentLoaded', start );
92	} else {
93		start();
94	}
95} )();

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.