PageSourceSearch

http://www.sqlshack.com/wp-content/uploads/apexsql/js/warnCookies.js

js sqlshack.com collected 2026-10-01 09:09:57 UTC 5,437 bytes, 120 lines download raw bytes

1// Assign current date to variable //
2var currentDate = new Date();
3
4// Create some DOM elements
5var newCookiesWarningDiv = document.createElement("div");
6
7// Retrieving cookie's information
8function checkCookie(cookieName) {
9  "use strict";
10  var cookieValue, cookieStartsAt, cookieEndsAt;
11
12  // Get all cookies in one string
13  cookieValue = document.cookie;
14  // Check if cookie's name is within that string
15  cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
16  if (cookieStartsAt === -1) {
17    cookieStartsAt = cookieValue.indexOf(cookieName + "=");
18  }
19  if (cookieStartsAt === -1) {
20    cookieValue = null;
21  } else {
22    cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
23    cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
24
25    if (cookieEndsAt === -1) {
26      cookieEndsAt = cookieValue.length;
27    }
28
29    // Get and return cookie's value
30    cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
31    return cookieValue;
32  }
33}
34
35// Cookie setup function
36function setCookie(cookieName, cookieValue, cookiePath, cookieExpires) {
37  "use strict";
38
39  // Convert characters that are not text or numbers into hexadecimal equivalent of their value in the Latin-1 character set
40  cookieValue = escape(cookieValue);
41
42  // If cookie's expire date is not set
43  if (cookieExpires === "") {
44    // Default expire date is set to 6 after the current date
45    currentDate.setMonth(currentDate.getMonth() + 6);
46    // Convert a date to a string, according to universal time (same as GMT)
47    cookieExpires = currentDate.toUTCString();
48  }
49
50  // If cookie's path value has been passed
51  if (cookiePath !== "") {
52    cookiePath = ";path = " + cookiePath;
53  }
54
55  // Add cookie to visitors computer
56  document.cookie = cookieName + "=" + cookieValue + ";expires = " + cookieExpires + cookiePath;
57
58  // Call function to get cookie's information
59  checkCookie(cookieName);
60}
61
62// Check if cookies are allowed by browser //
63function checkCookiesEnabled() {
64  "use strict";
65  // Try to set temporary cookie
66  setCookie("TestCookieExist", "Exist", "", "");
67  // If temporary cookie has been set, delete it and return true
68  if (checkCookie("TestCookieExist") === "Exist") {
69    setCookie("TestCookieExist", "Exist", "", "1 Jan 2000 00:00:00");
70    return true;
71  // If temporary cookie hasn't been set, return false  
72  }
73  if (checkCookie("TestCookieExist") !== "Exist") {
74    return false;
75  }
76}
77
78// Add HTML form to the website   
79function acceptCookies() {
80  "use strict";
81
82  document.getElementById("cookiesWarning").appendChild(newCookiesWarningDiv).setAttribute("id", "cookiesWarningActive");
83  document.getElementById("cookiesWarningActive").setAttribute("class", "row vertical-align");
84  document.getElementById("cookiesWarningActive").setAttribute("style", "min-height: 100%; vertical-align: middle");
85  document.getElementById("cookiesWarningActive").innerHTML = "<div class='contCookie'><div class='emptySpace1'></div><div class='cookieTxt'><span id='text'><p>This website uses cookies. By continuing to use this site and/or clicking the &quot;Accept&quot; button you are providing&nbsp;consent</p></span><br><span id='text'><p>Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our <a target='_blank' rel='nofollow' class='cookiesLink' href='https://www.quest.com/legal/privacy.aspx'>Privacy Policy</a> and our data protection efforts, please visit <a target='_blank' rel='nofollow' class='cookiesLink' href='https://www.quest.com/legal/gdpr-hq.aspx'>GDPR-HQ</a></p></span><form name='cookieAgreement'><input type='checkbox' name='agreed' value='Agreed' checked style='display: none'/><span class='acceptance'></span></div><div class='cookieBtn'><input type='submit' value='Accept' onclick='getAgreementValue(); return false;' id='cookiesOK' class='acceptButton'></form></div><div class='emptySpace2'></div></div>";
86}
87
88function acceptCookiesTickBoxWarning() {
89  "use strict";
90
91  setCookie("TestCookie", "Yes", "", "1 Jan 2000 00:00:00");
92  document.getElementById("cookiesWarning").appendChild(newCookiesWarningDiv).setAttribute("id", "cookiesWarningActive");
93}
94
95// Check if cookie has been set before //
96function checkCookieExist() {
97  "use strict";
98  // Call function to check if cookies are enabled in browser
99  if (checkCookiesEnabled()) {                                          
100    // If cookies enabled, check if our cookie has been set before and if yes, leave HTML block empty
101    if (checkCookie("TestCookie") === "Yes") {
102      document.getElementById("cookiesWarning").innerHTML = "";
103    // If our cookie hasn't been set before, call cookies' agreement form to HTML block 
104    } else {
105      acceptCookies();
106    }
107  } else {
108    // Display warning if cookies are disabled on browser
109    document.getElementById("cookiesWarning").appendChild(newCookiesWarningDiv).setAttribute("id", "cookiesWarningActive");
110    document.getElementById("cookiesWarningActive").innerHTML = "<span id='cookiesDisabled'><strong>Cookies are disabled. We use cookies to give you the best online experience.</strong><br /> Your browser currently not accepting cookies.</span>";
111  }
112}
113
114// Get agreement results
115function getAgreementValue() {
116  "use strict";
117
118    document.getElementById("cookiesWarning").innerHTML = "";
119    setCookie("TestCookie", "Yes", "", "");
120}

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.