PageSourceSearch

https://tinybeans.com/wp-content/themes/tinybeans/js/foryou.js?ver=1.5.11

js tinybeans.com collected 2026-09-24 08:56:26 UTC 9,975 bytes, 256 lines download raw bytes

1(function () {
2
3	  // Leanplum Setup
4	  function leanplumSetup () {
5
6		const url = window.location.host;
7		let isDevelopmentMode = false;
8		if (url == "hinata.tinybeans.com") {
9			isDevelopmentMode = true;
10		}
11		else if (url == "koji.tinybeans.com") {
12			isDevelopmentMode = true;
13		} 
14		 else if (url == "tinybeans.vipdev.lndo.site") {
15			isDevelopmentMode = true;
16		}
17
18		consoleLogDebug(`Is DeveloplmentMode: ${isDevelopmentMode}`);
19
20		let variables = {}
21
22		if (isDevelopmentMode) {
23			Leanplum.setAppIdForDevelopmentMode("app_EMl8PHgMsONQirbeyH4DCuUygX9TM0gksxS9R0v3bN4", "dev_mqAq919WDv4ABanoGKhaevzqhoAzsxBuLRaRzWFW3Ro");
24		   } else {
25			Leanplum.setAppIdForProductionMode("app_FecVAGUayD6PshcsLrD6KL2xdLr201Gq5He47WvoSSc", "prod_drJeOMEq8OSghpPfJfhlvGZ7MPwlZBOJS92C4JUiHHo");
26		   }
27		   
28		   Leanplum.setVariables(variables);
29		   
30		   return new Promise ( resp =>{
31				Leanplum.start(function(success) {
32				resp(Leanplum.getVariables().FeatureFlagWeb);
33			});
34		   });
35
36	}
37	
38	function getFirstName() {
39		let firstName = "";
40
41		if (sessionStorage.getItem('tb_user')) {
42			firstName = JSON.parse(sessionStorage.getItem('tb_user')).firstName;
43			jQuery('.for-you-title').replaceWith("<h2 class='for-you-title'>For " + firstName + "'s family" + '</h2>');
44			console.log('firstName: ' + firstName);
45			jQuery('entry-products-title').replaceWith("  <h6 class='entry-products-title text-subtitle-1'>" + 'Recommended for the ' + firstName + ' family' + "</h6>");
46		} 
47	}
48
49	if ('undefined' !== typeof document.cookie) {
50		 async function setupLP() {
51			consoleLogDebug('Setting up Leanplum');
52		 	const featureFlag = await leanplumSetup();
53		 	consoleLogDebug(`Feature Flags: ${JSON.stringify(featureFlag)}`);
54
55		 	let access_token = document.cookie
56		 		.split('; ')
57		 		.find(row => row.startsWith('access_token'));
58
59		 	consoleLogDebug(`AccessTok ${access_token}`);
60
61		 	if (featureFlag.showForYouFeature) {
62		 		if ('undefined' !== typeof access_token) {
63		 			let user = JSON.parse(sessionStorage.getItem('tb_user'));
64					let sub = JSON.parse(sessionStorage.getItem('tb_sub'));
65		 			if (user.hasMemoriesAccess && sub) {
66							const journalsUrl = location.origin + '/api/1/journals';
67							access_token = access_token.split('=')[1];
68							const invocation = new XMLHttpRequest();
69							invocation.onreadystatechange = function () {
70								if (this.readyState == XMLHttpRequest.DONE && 'undefined' !== typeof this.responseText) {
71									let resp = JSON.parse(this.responseText);
72									let journals = (resp.journals);
73								   let hasChildren = false;
74   
75								   journals.forEach((journal,index)=>{
76									   if(journal.children){
77										   if(!hasChildren){
78											   sessionStorage.setItem('tb_journals', JSON.stringify(journal));
79											   getArticles(journal.children);	
80											   hasChildren = true;
81										   }
82									   }
83
84									   if(index === (journals.length -1) && !hasChildren){
85										   sessionStorage.setItem('tb_journals', JSON.stringify(journal));
86										   getArticles(null);
87									   }
88								   });
89								}
90							};
91							invocation.open('GET', journalsUrl, true);
92							invocation.setRequestHeader('Authorization', 'Bearer ' + access_token);
93							invocation.withCredentials = true;
94							invocation.send();
95		 			} else {
96		 				//("User doesn't have a subscription");
97		 				const text = document.getElementById('nonBeanstalk');
98		 				const adUnit = document.getElementById('for-you-ad');
99						 if (text) {
100							text.classList.toggle('for-you-hide');
101						}
102		
103						if (adUnit) {
104							adUnit.classList.add('for-you-hide');
105						}	
106		 			}
107
108		 		} else {
109		 			const text = document.getElementById('nonBeanstalk');
110		 			const adUnit = document.getElementById('for-you-ad');
111					if (text) {
112						text.classList.toggle('for-you-hide');
113					}
114	
115					if (adUnit) {
116						adUnit.classList.add('for-you-hide');
117					}	
118		 		}
119		 	} else {
120				consoleLogDebug("Leanplum feature flag not enabled.");
121		 		const adUnit = document.getElementById('for-you-ad');
122				if (adUnit) {
123					adUnit.classList.add('for-you-hide');
124				}	
125		 	}
126
127		 }(setupLP());
128
129	} else if (sessionStorage.getItem('tb_journals') && 'undefined' !== typeof sessionStorage.getItem('tb_journals') && 'undefined' !== sessionStorage.getItem('tb_journals')) {
130		consoleLogDebug("Journals Empty");
131	} else {
132		consoleLogDebug("Unable to get user info: cookies disabled");
133	}
134
135
136	function getArticles(childrenJSON) {
137		getFirstName();
138		if (childrenJSON) {
139
140			const foryouHeader = document.getElementById('for-you-header');
141			const foryouContent = document.getElementById('for-you-content');
142			if (foryouHeader) {
143				foryouHeader.classList.toggle('for-you-hide');
144			}
145			
146			if (foryouContent) {
147				foryouContent.classList.toggle('for-you-hide');
148			}
149
150			let childId = [];
151			for (const child of childrenJSON) {
152				childId.push(child.id);
153				console.log(child.id);
154			}
155
156			let access_token = document.cookie
157				.split('; ')
158				.find(row => row.startsWith('access_token'));
159			console.log(access_token);
160
161
162			const numArticles = '6';
163			let forYouUrl = new URL('https://proxy-staging.tinybeans.com' + '/article-service/api/v2/articles/for-children');
164			const params = new URLSearchParams();
165			params.set('size', numArticles);
166			params.set('ids', childId.toString());
167			forYouUrl.search = params.toString();
168			console.log(forYouUrl);
169
170
171			if ('undefined' !== typeof access_token) {
172				access_token = 'Bearer ' + access_token.split('=')[1];
173				const invocation = new XMLHttpRequest();
174				invocation.onreadystatechange = function () {
175					if (this.readyState == XMLHttpRequest.DONE && 'undefined' !== typeof this.responseText) {
176						var resp = JSON.parse(this.responseText);
177						console.log(resp);
178						printArticles(resp.articles.content);
179					}
180				};
181				invocation.open('GET', forYouUrl, true);
182				invocation.setRequestHeader('Authorization', access_token);
183				invocation.send();
184			} else {
185				//console.log("User not logged in.");
186			}
187		} else {
188			const text = document.getElementById('isBeanstalk');
189			const adUnit = document.getElementById('for-you-ad');
190			if (text) {
191				text.classList.toggle('for-you-hide');
192			}
193			if (adUnit) {
194				adUnit.classList.add('for-you-hide');
195			}	
196		}
197	}
198
199	function printArticles(articles) {
200		if (window.location.pathname !== '/') {
201			console.log('Current Path: ' + window.location.pathname)
202
203			firstName = JSON.parse(sessionStorage.getItem('tb_user')).firstName;
204			jQuery('.entry-products-title').replaceWith("<h6 class='entry-products-title text-subtitle-1'>" + 'Recommended for ' + firstName + "'s " + ' family' + "</h6>");
205
206			jQuery('.content-list-articles').replaceWith('<div></div>');
207
208			articles.forEach((article, index) => {
209				console.log(index + ': ' + article)
210				let link = 'href=' + article.url;
211				let src = 'src=' + article.featureImageUrl;
212
213				jQuery('.entry-products').append("<article class='content-list for-you-item'>" + "<a class='for-you-list'" + link + '>' + "<img data-nopin='true' class='for-you-img-top' width='640px' alt='list card image'" + src + '>' + '</a>' +
214					'<div>' + "<div class='card-subtitle'>" + article.articleCategories[0].label + '</div>' + "<h6 class='card-title'>" + '<a ' + link + '>' + article.title + '</a></h6>' + '</div>' + "<footer class='card-footer'><div class='shared-section'><svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-more-horizontal'><circle cx='12' cy='12' r='1'></circle><circle cx='19' cy='12' r='1'></circle><circle cx='5' cy='12' r='1'></circle></svg><div class='share-menu content'><ul><li class='text--link' onclick='copyUrl(this)'>Share</li></ul></div></div></footer>" + "</article>");
215			});
216
217		} else {
218			let randonIndex = Math.floor(Math.random() * 6);
219			console.log(randonIndex);
220			let link = 'href=' + articles[randonIndex].url;
221			let src = 'src=' + articles[randonIndex].featureImageUrl;
222
223			jQuery('.for-you-link').replaceWith(" <a class='for-you-link'" + link + '>' + "<img data-nopin='true' class='for-you-img-top' height='523px' width='100%' alt='Card image cap'" + src + '>' + '</a>');
224
225			jQuery('.for-you-article-link').replaceWith(" <a class='for-you-article-link'" + link + '>' + articles[randonIndex].title + '</a>');
226
227			jQuery('.for-you-text-body').replaceWith(" <span class='for-you-text-body'>" + articles[randonIndex].excerpt + '</span>');
228
229			console.log(window.location.pathname)
230
231			articles.forEach((article, index) => {
232				if (index !== randonIndex) {
233					console.log(index + ': ' + article)
234					let link = 'href=' + article.url;
235					let src = 'src=' + article.featureImageUrl;
236
237					jQuery('.for-you-side-list').append("<article class='content-list for-you-item'>" + "<a class='for-you-list'" + link + '>' + "<img data-nopin='true' class='for-you-img-top' width='640px' alt='list card image'" + src + '>' + '</a>' +
238						'<div>' + "<div class='card-subtitle'>" + article.articleCategories[0].label + '</div>' + "<h6 class='card-title'>" + '<a ' + link + '>' + article.title + '</a></h6>' + '</div>' + "<footer class='card-footer'><div class='shared-section'><svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-more-horizontal'><circle cx='12' cy='12' r='1'></circle><circle cx='19' cy='12' r='1'></circle><circle cx='5' cy='12' r='1'></circle></svg><div class='share-menu content'><ul><li class='text--link' onclick='copyUrl(this)'>Share</li></ul></div></div></footer>" + "</article>");
239				}
240			});
241		}
242	}
243
244	(function ($) {
245		$('.openForyouModal').on('click', function () {
246			$('#foryouModal').show();
247		});
248	}(jQuery));
249
250
251	// Replace Sidebar Content
252	if (window.location.pathname !== '/') {
253		getFirstName();
254	}
255
256})();

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.