PageSourceSearch

https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/resources/sac.php?ver=20260422

js soundsmint.co.uk collected 2026-10-07 02:14:08 UTC 17,656 bytes, 632 lines download raw bytes

1/*
2	Simple Ajax Chat > JavaScript
3	@ https://wordpress.org/plugins/simple-ajax-chat/
4*/
5
6// Fade Anything Technique by Adam Michela
7var Fat = { 
8	make_hex : function(d,c,a) {
9		d = d.toString(16);
10		if (d.length == 1) {
11			d = '0' + d;
12		}
13		c = c.toString(16);
14		if (c.length == 1) {
15			c = '0' + c;
16		}
17		a = a.toString(16);
18		if (a.length == 1) {
19			a = '0' + a;
20		}
21		return '#' + d + c + a;
22	},
23	fade_all : function() {
24		var b = document.getElementsByTagName('*');
25		for (var c = 0; c < b.length; c++) {
26			var e = b[c];
27			var d = /fade-?(\w{3,6})?/.exec(e.className);
28			if (d) {
29				if (!d[1]) {
30					d[1] = '';
31				}
32				if (e.id) {
33					Fat.fade_element(e.id, null, null, '#' + d[1]);
34				}
35			}
36		}
37	},
38	fade_element : function(m, c, a, o, d) {
39		if (!c) {
40			c = 30; 
41		}
42		if (!a) {
43			a = 3000;
44		}
45		if (!o || o == '#') {
46			o = '#ffff33';
47		}
48		if (!d) { 
49			d = this.get_bgcolor(m);
50		}
51		var i = Math.round(c * (a/1000));
52		var s = a / i;
53		var w = s;
54		var j = 0;
55		if (o.length < 7) {
56			o += o.substr(1, 3);
57		}
58		if (d.length < 7) {
59			d += d.substr(1, 3);
60		}
61		var n = parseInt(o.substr(1, 2), 16);
62		var u = parseInt(o.substr(3, 2), 16);
63		var e = parseInt(o.substr(5, 2), 16);
64		var f = parseInt(d.substr(1, 2), 16);
65		var l = parseInt(d.substr(3, 2), 16);
66		var t = parseInt(d.substr(5, 2), 16);
67		var k, q, v, p;
68		while (j < i) {
69			k = Math.floor(n * ((i - j) / i) + f * (j / i));
70			q = Math.floor(u * ((i - j) / i) + l * (j / i));
71			v = Math.floor(e * ((i - j) / i) + t * (j / i));
72			p = this.make_hex(k, q, v);
73			setTimeout(Fat.set_bgcolor.bind(null, m, p), w);
74			j++;
75			w = s * j;
76		}
77		setTimeout(Fat.set_bgcolor.bind(null, m, d), w);
78	}, 
79	set_bgcolor : function(d, b) {
80		var a = document.getElementById(d);
81		a.style.backgroundColor = b;
82	},
83	get_bgcolor : function(e) {
84		var b = document.getElementById(e);
85		while(b) {
86			var d;
87			if (window.getComputedStyle) {
88				d = window.getComputedStyle(b, null).getPropertyValue('background-color');
89			}
90			if (b.currentStyle) {
91				d = b.currentStyle.backgroundColor;
92			}
93			if ((d != '' && d != 'transparent') || b.tagName == 'body') {
94				break;
95			}
96			b = b.parentNode;
97		}
98		if (d == undefined || d == '' || d == 'transparent') {
99			d = '#ffffff';
100		}
101		var a = d.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
102		if (a) {
103			d = this.make_hex(parseInt(a[1]), parseInt(a[2]), parseInt(a[3]));
104		}
105		return d;
106	}
107};
108
109// smilies
110var smilies = [
111	[':\\)',      'icon_smile.gif'], 
112	[':\\-\\)',   'icon_smile.gif'], 
113	[':D',        'icon_biggrin.gif'], 
114	[':\\-D',     'icon_biggrin.gif'], 
115	[':grin:',    'icon_biggrin.gif'], 
116	[':smile:',   'icon_smile.gif'], 
117	[':\\(',      'icon_sad.gif'], 
118	[':\\-\\(',   'icon_sad.gif'], 
119	[':sad:',     'icon_sad.gif'], 
120	[':o',        'icon_surprised.gif'], 
121	[':\\-o',     'icon_surprised.gif'], 
122	['8o',        'icon_eek.gif'], 
123	['8\\-o',     'icon_eek.gif'], 
124	['8\\-0',     'icon_eek.gif'], 
125	[':eek:',     'icon_surprised.gif'], 
126	[':s',        'icon_confused.gif'], 
127	[':\\-s',     'icon_confused.gif'], 
128	[':lol:',     'icon_lol.gif'], 
129	[':cool:',    'icon_cool.gif'], 
130	['8\\)',      'icon_cool.gif'], 
131	['8\\-\\)',   'icon_cool.gif'], 
132	[':x',        'icon_mad.gif'], 
133	[':-x',       'icon_mad.gif'], 
134	[':mad:',     'icon_mad.gif'], 
135	[':p',        'icon_razz.gif'], 
136	[':\\-p',     'icon_razz.gif'], 
137	[':razz:',    'icon_razz.gif'], 
138	[':\\$',      'icon_redface.gif'], 
139	[':\\-\\$',   'icon_redface.gif'], 
140	[":'\\(",     'icon_cry.gif'], 
141	[':evil:',    'icon_evil.gif'], 
142	[':twisted:', 'icon_twisted.gif'], 
143	[':cry:',     'icon_cry.gif'], 
144	[':roll:',    'icon_rolleyes.gif'], 
145	[':wink:',    'icon_wink.gif'], 
146	[';\\)',      'icon_wink.gif'], 
147	[';\\-\\)',   'icon_wink.gif'], 
148	[':!:',       'icon_exclaim.gif'], 
149	[':\\?',      'icon_question.gif'], 
150	[':\\-\\?',   'icon_question.gif'], 
151	[':idea:',    'icon_idea.gif'], 
152	[':arrow:',   'icon_arrow.gif'], 
153	[':\\|',      'icon_neutral.gif'], 
154	[':neutral:', 'icon_neutral.gif'], 
155	[':\\-\\|',   'icon_neutral.gif'], 
156	[':mrgreen:', 'icon_mrgreen.gif']
157];
158
159// apply filters
160function sac_apply_filters(s) { 
161	return filter_smilies(make_links((s))); 
162};
163
164// filter smilies
165function filter_smilies(s) {
166	for (var i = 0; i < smilies.length; i++) {
167		var search = smilies[i][0];
168		var imgalt = smilies[i][0].replace(/\\/g, '');
169		var imgsrc = 'https://soundsmint.co.uk/wp-includes/images/smilies/' + smilies[i][1];
170		var replace = '<img src="' + imgsrc + '" class="wp-smiley" border="0" style="border:none;" alt="' + imgalt + '" />';
171		re = new RegExp(search, 'gi');
172		s = s.replace(re, replace);
173	}
174	return s;
175};
176
177// links
178function make_links(s) {
179	var re = /((http|https|ftp):\/\/[^\s\'\"\%]*)/gi;
180	var text = s.replace(re, '<a target="_blank" rel="noopener noreferrer" href="$1" class="sac-chat-link">&laquo;link&raquo;</a>');
181	return text;
182};
183
184// sound alerts
185var myBox = new Object();
186myBox.onInit = function(){};
187
188// Generic onload @ https://www.brothercake.com/site/resources/scripts/onload/
189if (typeof window.addEventListener != 'undefined') {
190	window.addEventListener('load', initJavaScript, false);
191} else {
192	if (typeof document.addEventListener != 'undefined') {
193		document.addEventListener('load', initJavaScript, false);
194	} else {
195		if (typeof window.attachEvent != 'undefined') {
196			window.attachEvent('onload', initJavaScript);
197		}
198	}
199};
200
201// scroll to position
202function scroll_to_position() {
203		
204	jQuery('#sac-output').animate({ scrollTop: jQuery('#sac-output').prop('scrollHeight') }, 100);
205		
206};
207
208// get timeout
209function get_timeout() {
210	
211	return 3000;
212	
213};
214
215// XHTML live Chat by Alexander Kohlhofer
216
217var sac_loadtimes;
218var httpReceiveChat;
219var httpSendChat;
220
221var get_timeout = get_timeout();
222var sac_timeout = get_timeout;
223var GetChaturl  = 'https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/simple-ajax-chat-core.php?sacGetChat=yes';
224var SendChaturl = 'https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/simple-ajax-chat-core.php?sacSendChat=yes';
225
226function initJavaScript() {
227	
228	if (!document.getElementById('sac_chat')) return;
229	
230	document.forms['sac-form'].elements.sac_chat.setAttribute('autocomplete', 'off');
231	
232	checkStatus('');
233	checkName();
234	checkUrl();
235	
236	sac_loadtimes   = 1;
237	httpReceiveChat = getHTTPObject();
238	httpSendChat    = getHTTPObject();
239	
240	setTimeout(receiveChatText, sac_timeout);
241	
242	var sacUrl = document.getElementById('sac_url');
243	if (sacUrl != null) sacUrl.onblur = checkUrl;
244	
245	document.getElementById('sac_name').onblur        = checkName;
246	document.getElementById('sac_chat').onfocus       = function(){ checkStatus('active'); };
247	document.getElementById('sac_chat').onblur        = function(){ checkStatus(''); };
248	document.getElementById('sac-form').onsubmit      = function(){ return false; };
249	document.getElementById('submitchat').onclick     = sendComment;
250	document.getElementById('sac-output').onmouseover = function(){
251		
252		if (sac_loadtimes > 9){
253			sac_loadtimes = 1;
254			receiveChatText();
255		}
256		
257		sac_timeout = get_timeout;
258		
259	}
260	
261	scroll_to_position();
262	
263};
264
265function receiveChatText() {
266	
267	sac_lastID = parseInt(document.getElementById('sac_lastID').value) - 1;
268	
269	if (httpReceiveChat.readyState == 4 || httpReceiveChat.readyState == 0) {
270		
271		var id    = '&sac_lastID=' + sac_lastID;
272		var rand  = '&rand=' + Math.floor(Math.random() * 1000000);
273		var nonce = '&sac_nonce_receive=daaf64c3bc';
274		var query = GetChaturl + id + nonce + rand;
275		
276		httpReceiveChat.open('GET', query, true);
277		httpReceiveChat.onreadystatechange = handlehHttpReceiveChat;
278		httpReceiveChat.send(null);
279		
280		sac_loadtimes++;
281		if (sac_loadtimes > 9) {
282			sac_timeout = sac_timeout * 1.25;
283		}
284		
285	}
286	
287	// console.log('sac_loadtimes: '+ sac_loadtimes + ', Timeout: ' + sac_timeout);
288	
289	setTimeout(receiveChatText, sac_timeout);
290	
291};
292
293// http receive chat
294function handlehHttpReceiveChat() {
295	if (httpReceiveChat.readyState == 4) { 
296		results = httpReceiveChat.responseText.split('---');
297		if (results.length > 4) {
298			for (i = 0; i < (results.length - 1); i = i + 5) {
299				insertNewContent(results[i + 1], results[i + 2], results[i + 3], results[i + 4], results[i]);
300				document.getElementById('sac_lastID').value = parseInt(results[i]) + 1;
301			}
302			sac_timeout = get_timeout;
303			sac_loadtimes = 1;
304		}
305	}
306};
307
308// send chat
309function sendComment() {
310	currentChatText = document.forms['sac-form'].elements.sac_chat.value;
311	if (httpSendChat.readyState == 4 || httpSendChat.readyState == 0) {
312		if(currentChatText == '' || currentChatText.trim().length === 0) {
313			return;
314		}
315		currentName = document.getElementById('sac_name').value;
316		
317		var currentUrl = document.getElementById('sac_url');
318		if (currentUrl != null) currentUrl = currentUrl.value;
319		
320		currentNonce   = document.getElementById('sac_nonce').value;
321		currentJSNonce = document.getElementById('sac_js_nonce').value;
322		
323		var n = 'n='  + encodeURIComponent(currentName);
324		var c = '&c=' + encodeURIComponent(currentChatText);
325		var u = '&u=' + encodeURIComponent(currentUrl);
326		var nonce = '&sac_nonce=' + encodeURIComponent(currentNonce);
327		var jsnonce = '&sac_js_nonce=' + encodeURIComponent(currentJSNonce);
328		
329		param = n + c + u + nonce + jsnonce;
330		httpSendChat.open('POST', SendChaturl, true);
331		httpSendChat.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
332		httpSendChat.onreadystatechange = receiveChatText;
333		httpSendChat.send(param);
334		document.forms['sac-form'].elements.sac_chat.value = '';
335	}
336};
337
338// insert chat
339function insertNewContent(liName,liText,lastResponse, liUrl, liId) {
340	
341	response = document.getElementById('responseTime');
342	response.replaceChild(document.createTextNode(lastResponse), response.firstChild);
343	insertO = document.getElementById('sac-messages');
344
345	var audio = document.getElementById('TheBox');
346	if (audio) audio.play();
347
348	oLi = document.createElement('li');
349	oLi.setAttribute('id', 'comment-new' + liId);
350	
351	// li date
352	Date.prototype.date = function() {
353		
354		var li_date_1 = this.getFullYear();
355		var li_date_2 = (((this.getMonth() + 1) < 10) ? '0' : '');
356		var li_date_3 = (this.getMonth() + 1);
357		var li_date_4 = ((this.getDate() < 10) ? '0' : '');
358		var li_date_5 = this.getDate();
359		
360		return li_date_1 + '-' + li_date_2 + li_date_3 + '-' + li_date_4 + li_date_5;
361		
362	};
363	
364	// li time
365	Date.prototype.time = function() {
366		
367		var li_time_1 = ((this.getHours() < 10) ? '0' : '');
368		var li_time_2 = this.getHours();
369		var li_time_3 = ((this.getMinutes() < 10) ? '0' : '');
370		var li_time_4 = this.getMinutes();
371		var li_time_5 = ((this.getSeconds() < 10) ? '0' : '');
372		var li_time_6 = this.getSeconds();
373		
374		return li_time_1 + li_time_2 + ':' + li_time_3 + li_time_4 + ':' + li_time_5 + li_time_6;
375		
376	};
377	
378	var newDate = new Date();
379	var timestamp = newDate.date() + ',' + newDate.time();
380	oLi.setAttribute('data-time', timestamp);
381	
382	oSpan = document.createElement('span');
383	oSpan.setAttribute('class', 'sac-chat-name');
384	
385	// span date
386	Date.prototype.today = function() {
387		
388		var span_date_1 = this.getFullYear();
389		var span_date_2 = (((this.getMonth() + 1) < 10) ? '0' : '');
390		var span_date_3 = (this.getMonth() + 1);
391		var span_date_4 = ((this.getDate() < 10) ? '0' : '');
392		var span_date_5 = this.getDate();
393		
394		return span_date_1 + '/' + span_date_2 + span_date_3 + '/' + span_date_4 + span_date_5;
395		
396	};
397	
398	// span time
399	Date.prototype.timeNow = function() {
400		
401		var span_time_1 = ((this.getHours() < 10) ? '0' : '');
402		var span_time_2 = this.getHours();
403		var span_time_3 = ((this.getMinutes() < 10) ? '0' : '');
404		var span_time_4 = this.getMinutes();
405		var span_time_5 = ((this.getSeconds() < 10) ? '0' : '');
406		var span_time_6 = this.getSeconds();
407		
408		return span_time_1 + span_time_2 + ':' + span_time_3 + span_time_4 + ':' + span_time_5 + span_time_6;
409		
410	};
411	
412	var datetime = 'Posted: ' + newDate.today() + ' @ ' + newDate.timeNow();
413	oSpan.setAttribute('title', datetime);
414	oName = document.createTextNode(liName);
415	
416		
417	oURL = oName;
418	oSpan.appendChild(oURL);
419	
420		
421	name_class = liName.replace(/[\s\.\#\(\)]+/g,'-');
422	
423	oLi.className = 'sac-chat-message sac-live sac-user-' + name_class;
424	oSpan.appendChild(document.createTextNode(' : '));
425	oLi.appendChild(oSpan);
426	oLi.innerHTML += sac_apply_filters(liText);
427	
428		
429	if ('Notification' in window) {
430		sacCustomNotify('New chat message', liName + ': ' + sac_apply_filters(liText) + "\r\n" + '(' + datetime + ')', window.location.href);
431	}
432	
433		
434		
435	insertO.insertBefore(oLi, insertO.lastChild);
436	
437		jQuery.post('https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/includes/sac-check-user.php', 'sac_user=' + encodeURIComponent(liName), function(response){
438		jQuery('.sac-user-' + name_class).addClass('sac-online');
439	});
440	
441		
442	jQuery('#sac-output').animate({ scrollTop: jQuery('#sac-output').prop('scrollHeight') }, 300);
443	
444		
445	var fade_length = 1500;
446	var fade_from   = '#ffffcc';
447	var fade_to     = '#ffffff';
448	
449	Fat.fade_element('comment-new' + liId, 30, fade_length, fade_from, fade_to);
450
451};
452
453// textarea enter
454function pressedEnter(b,a) {
455	var c = a.keyCode ? a.keyCode : a.which ? a.which : a.charCode;
456	if (c == 13) { 
457		sendComment();
458		return false;
459	} else { 
460		return true;
461	}
462};
463
464// chat status
465function checkStatus(a) {
466	currentChatText = document.forms['sac-form'].elements.sac_chat;
467	oSubmit = document.forms['sac-form'].elements.submit;
468	if (currentChatText.value != '' || a == 'active') {
469		oSubmit.disabled = false;
470	} else {
471		oSubmit.disabled = true;
472	}
473};
474
475// get cookie
476function sac_getCookie(c) {
477	var b = document.cookie;
478	var e = c + '=';
479	var d = b.indexOf('; ' + e);
480	if (d == -1) {
481		d = b.indexOf(e);
482		if (d != 0) {
483			return null;
484		}
485	} else {
486		d += 2;
487		var a = document.cookie.indexOf(';', d);
488		if (a == -1) {
489			a = b.length;
490		}
491		return unescape(b.substring(d + e.length, a));
492	}
493};
494
495// check name
496function checkName() {
497	sacCookie = sac_getCookie('sacUserName');
498	currentName = document.getElementById('sac_name');
499	currentName.value = currentName.value.replace(/[^\p{L}0-9\s_-]/gui, '');
500	
501		
502	chat_name = currentName.value;
503		
504	if (currentName.value != chat_name) {
505		currentName.value = chat_name;
506	}
507	if (chat_name != sacCookie) {
508		document.cookie = 'sacUserName=' + chat_name + '; expires=Sun, 06 Dec 2026 02:14:08 UTC; samesite=strict;';
509	}
510	if (sacCookie && currentName.value == '') {
511		currentName.value = sacCookie;
512		return;
513	}
514	if (currentName.value == '' || currentName.value.trim().length === 0) {
515		currentName.value = 'guest_' + Math.floor(Math.random() * 10000);
516	}
517};
518
519// check url
520function checkUrl() {
521	var sacCookie = sac_getCookie('sacUrl');
522	var sacUrl = document.getElementById('sac_url');
523	if (sacUrl != null) {
524		sacUrl.value = encodeURI(sacUrl.value);
525		if (sacUrl.value == '') {
526			return;
527		}
528		if (sacUrl.value != sacCookie) {
529			document.cookie = 'sacUrl=' + sacUrl.value + '; expires=Sun, 06 Dec 2026 02:14:08 UTC; samesite=strict;';
530			return;
531		}
532		if (sacCookie && (sacUrl.value == '' || sacUrl.value == 'http://' || sacUrl.value == 'https://')) {
533			sacUrl.value = sacCookie;
534			return;
535		}
536	}
537};
538
539// ajax
540function getHTTPObject() {
541	var xmlhttp;
542	/*@cc_on
543		@if (@_jscript_version >= 5)
544		try {
545			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
546		} catch (e) {
547			try {
548				xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
549			} catch (E) {
550				xmlhttp = false;
551			}
552		}
553		@else
554		xmlhttp = false;
555	@end @*/
556	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
557		try { 
558			xmlhttp = new XMLHttpRequest();
559		} catch (e) {
560			xmlhttp = false;
561		}
562	}
563	return xmlhttp;
564};
565
566jQuery(document).ready(function($){
567	
568	// nonce
569	var url = 'https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/resources/nonce.php';
570	$('.sac_js_nonce').load(url);
571	
572	// blank targets
573	jQuery("#sac-messages").on("click", "a[rel*=external]", function(e) {
574		e.preventDefault();
575		e.stopPropagation();
576		window.open(this.href);
577	});
578	
579});
580
581// tooltips
582jQuery(document).on({
583	mouseenter: function() {
584		var item = jQuery(this);
585		var link = item.children('a');
586		var title = item.attr('title');
587		item.data('tip', title).removeAttr('title');
588		link.css({ 'cursor' : 'help' });
589		item.css({ 'position' : 'relative', 'display' : 'inline-block', 'cursor' : 'help' });
590		jQuery('<div class="tooltip"></div>').text(title).appendTo(item);
591		jQuery('.tooltip').css({ 
592			'position' : 'absolute', 'z-index' : '9999', 'top' : '-2px', 'left' : '105%', 'line-height' : '16px',
593			'padding' : '5px 10px', 'font-size' : '12px', 'font-weight' : 'normal', 'white-space' : 'nowrap',
594			'color' : '#333', 'background-color' : '#efefef', 'box-shadow' : '0 5px 15px -5px rgba(0,0,0,0.5)'
595		});
596	}, mouseleave: function() {
597		var item = jQuery(this);
598		item.attr('title', item.data('tip'));
599		jQuery('.tooltip').remove();
600	}
601}, '.sac-chat-name');
602
603// notifications
604function isNewNotificationSupported() {
605	if (!window.Notification || !Notification.requestPermission) return false;
606	if (Notification.permission == 'granted') throw new Error('Browser notification error for SAC plugin');
607	try {
608		new Notification('');
609	} catch (e) {
610		if (e.name == 'TypeError') return false;
611	}
612	return true;
613}
614
615function sacCustomNotify(title, desc, url) {
616	if (window.Notification && Notification.permission == 'granted') {
617		var notification = new Notification(title, {
618			icon: 'https://soundsmint.co.uk/wp-content/plugins/simple-ajax-chat/resources/sac-400.png',
619			body: desc,
620		});
621		if (url) {
622			notification.onclick = function() {
623				window.open(url);
624			};
625		}
626		notification.onclose = function() {
627			// console.log('Notification closed');
628		};
629	} else if (isNewNotificationSupported()) {
630		Notification.requestPermission();
631	}
632}

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.