PageSourceSearch

https://www.rcn.org.uk/js/OptanonWrapper.js

js rcn.org.uk collected 2026-10-02 02:22:12 UTC 4,573 bytes, 130 lines download raw bytes

1function OptanonWrapper() {
2	if (typeof OptanonWrapperCount == 'undefined') {
3		otGetInitialGrps();
4	}
5
6	otDeleteCookie(otIniGrps);
7
8	function otGetInitialGrps() {
9		OptanonWrapperCount = '';
10		otIniGrps = OnetrustActiveGroups;
11	}
12
13	function otDeleteCookie(iniOptGrpId) {
14		let otDomainGrps = JSON.parse(JSON.stringify(Optanon.GetDomainData().Groups));
15		let otDeletedGrpIds = otGetInactiveId(iniOptGrpId, OnetrustActiveGroups, otDomainGrps);
16
17		if (otDeletedGrpIds.length != 0 && otDomainGrps.length != 0) {
18			for (let i = 0; i < otDomainGrps.length; i++) {
19				//Check if CustomGroupId matches
20				if (
21					otDomainGrps[i]['CustomGroupId'] != '' &&
22					otDeletedGrpIds.includes(otDomainGrps[i]['CustomGroupId'])
23				) {
24					for (var j = 0; j < otDomainGrps[i]['Cookies'].length; j++) {
25						eraseCookie(otDomainGrps[i]['Cookies'][j]['Name']);
26					}
27				}
28
29				//Check if Hostid matches
30				if (otDomainGrps[i]['Hosts'].length != 0) {
31					for (var j = 0; j < otDomainGrps[i]['Hosts'].length; j++) {
32						//Check if HostId presents in the deleted list and cookie array is not blank
33						if (
34							otDeletedGrpIds.includes(otDomainGrps[i]['Hosts'][j]['HostId']) &&
35							otDomainGrps[i]['Hosts'][j]['Cookies'].length != 0
36						) {
37							for (let k = 0; k < otDomainGrps[i]['Hosts'][j]['Cookies'].length; k++) {
38								eraseCookie(otDomainGrps[i]['Hosts'][j]['Cookies'][k]['Name']);
39							}
40						}
41					}
42				}
43			}
44		}
45		otGetInitialGrps(); //Reassign new group ids
46	}
47
48	//Get inactive ids
49	function otGetInactiveId(customIniId, otActiveGrp, otDomainGrps) {
50		let groupsMatch = customIniId == otActiveGrp;
51
52		customIniId = customIniId.split(',');
53		customIniId = customIniId.filter(Boolean);
54		otActiveGrp = otActiveGrp.split(',');
55		otActiveGrp = otActiveGrp.filter(Boolean);
56
57		let result = [];
58
59		for (var i = 0; i < customIniId.length; i++) {
60			if (otActiveGrp.indexOf(customIniId[i]) <= -1) {
61				result.push(customIniId[i]);
62			}
63		}
64
65		//Include non-active groups even if nothing has changed (page load)
66		if (result.length == 0 && groupsMatch) {
67			for (var i = 0; i < otDomainGrps.length; i++) {
68				if (otDomainGrps[i].OptanonGroupId != 'C0001') {
69					if (!otActiveGrp.includes(otDomainGrps[i].OptanonGroupId)) {
70						result.push(otDomainGrps[i].OptanonGroupId);
71					}
72				}
73			}
74		}
75
76		return result;
77	}
78
79	function eraseCookie(name) {
80		if (name.length > 0) {
81			//Delete LSO incase LSO being used, can be commented out.
82			localStorage.removeItem(name);
83
84			parts = window.location.hostname.split('.');
85			parts.shift();
86			tld = parts.join('.');
87
88			domainArray = [window.location.hostname, '.' + tld, 'www.' + tld];
89
90			for (var d = 0; d < domainArray.length; d++) {
91				//Delete root path cookies
92				document.cookie = name + '=; Max-Age=-99999999; Path=/;Domain=' + domainArray[d];
93				document.cookie = name + '=; Max-Age=-99999999; Path=/;';
94
95				pathArray = window.location.pathname.split('/');
96
97				//Loop through path hierarchy and delete potential cookies at each path.
98				for (let i = 0; i < pathArray.length; i++) {
99					if (pathArray[i] !== null) {
100						//Build the path string from the Path Array e.g /site/login
101						var currentPath = pathArray.slice(0, i + 1).join('/');
102
103						document.cookie =
104							name + '=; Max-Age=-99999999; Path=' + currentPath + ';Domain=' + domainArray[d];
105						document.cookie = name + '=; Max-Age=-99999999; Path=' + currentPath + ';';
106						//Maybe path has a trailing slash!
107						document.cookie =
108							name + '=; Max-Age=-99999999; Path=' + currentPath + '/;Domain=' + domainArray[d];
109						document.cookie = name + '=; Max-Age=-99999999; Path=' + currentPath + '/;';
110
111						//Check for cookies with session id (e.g. _hjSession_xxxxxx)
112						document.cookie.split(';').forEach(function (cookie) {
113							let cookieName = cookie.trim().split('=')[0];
114
115							let index = name.indexOf('_xxxxxx');
116							if (index > 0 && cookieName.substring(0, index) == name.substring(0, index)) {
117								document.cookie =
118									cookieName + '=; Max-Age=-99999999; Path=' + currentPath + ';Domain=' + domainArray[d];
119								document.cookie = cookieName + '=; Max-Age=-99999999; Path=' + currentPath + ';';
120								document.cookie =
121									cookieName + '=; Max-Age=-99999999; Path=' + currentPath + '/;Domain=' + domainArray[d];
122								document.cookie = cookieName + '=; Max-Age=-99999999; Path=' + currentPath + '/;';
123							}
124						});
125					}
126				}
127			}
128		}
129	}
130}

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.