Best JavaScript code snippet using chromeless
jqueryCookieGuard.1.0.1.js
Source:jqueryCookieGuard.1.0.1.js
1// *************************************************************************2// * CookieGuard v1.0.13// *4// * (c) 2012 Ultimateweb LTD <info@ultimateweb.co.uk>5// * All Rights Reserved.6// *7// * This program is free software: you can redistribute it and/or modify8// * it under the terms of the GNU General Public License as published by9// * the Free Software Foundation, either version 3 of the License, or10// * (at your option) any later version.11// *12// * This program is distributed in the hope that it will be useful,13// * but WITHOUT ANY WARRANTY; without even the implied warranty of14// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15// * GNU General Public License for more details.16// *17// * GNU General Public License <http://www.gnu.org/licenses/>.18// *19// *************************************************************************20// CHANGELOG21//22// 1.0.123// - Uses jquery.cookie (as used by Drupal).24//25(function($){26 if(typeof $.cookieguard === 'undefined') {27 $.cookieguard = function(options){28 var defaults = {cookieDeleteDelay: 100, messageShowDelay: 1000, messageHideDelay: null, answeredHideDelay: 2000, slideSpeed: 500, cookiePrefix: 'cookieguard_', alertOfUnknown: true};29 $.cookieguard.settings = $.extend(defaults, options, {'cookiesUsed': new Array(), 'messageHideTimeout': null});30 };31 }32 if(typeof $.cookieguard.cookies === 'undefined') {33 $.cookieguard.cookies = function(){};34 }35 if(typeof $.cookieguard.cookies.add === 'undefined') {36 $.cookieguard.cookies.add = function(name, cookie, description, essential){37 var cookies = cookie.split(",");38 for( var i = 0; i < cookies.length; i++) {39 $.cookieguard.settings.cookiesUsed.push({'name': name, 'cookie': cookies[i], 'description': description, 'essential': essential});40 if(essential) $.cookieguard.cookies.storeAllowedCookie(cookies[i]);41 }42 };43 }44 if(typeof $.cookieguard.cookies.findUnknownCookies === 'undefined') {45 $.cookieguard.cookies.findUnknownCookies = function(){46 var allowedCookies = $.cookieguard.cookies.getAllowedCookies();47 var disallowedCookies = $.cookieguard.cookies.getDisallowedCookies();48 var definedCookies = $.cookieguard.settings.cookiesUsed;49 var allCookies = new Array();50 var unknownCookies = new Array();51 for( var i in $.cookie()) {52 allCookies.push(i);53 }54 for( var i = 0; i < allCookies.length; i++) {55 var cookieFound = false;56 if(allowedCookies != null) {57 for( var j = 0; j < allowedCookies.length; j++) {58 if(allowedCookies[j].indexOf('*') === 0 && allowedCookies[j].match("\\*$") == '*') {59 if(allCookies[i].indexOf(allowedCookies[j].replace('*', '')) > -1) {60 cookieFound = true;61 break;62 }63 } else if(allowedCookies[j].indexOf('*') === 0) {64 if(allCookies[i].match(allowedCookies[j].replace('*', '') + '$') == allowedCookies[j].replace('*', '')) {65 cookieFound = true;66 break;67 }68 } else if(allowedCookies[j].match("\\*$") == "*") {69 if(allCookies[i].indexOf(allowedCookies[j].replace('*', '')) === 0) {70 cookieFound = true;71 break;72 }73 } else if(allowedCookies[j] == allCookies[i]) {74 cookieFound = true;75 break;76 }77 }78 }79 if(!cookieFound) {80 if(disallowedCookies != null) {81 for( var j = 0; j < disallowedCookies.length; j++) {82 if(disallowedCookies[j].indexOf('*') === 0 && disallowedCookies[j].match("\\*$") == '*') {83 if(allCookies[i].indexOf(disallowedCookies[j].replace('*', '')) > -1) {84 cookieFound = true;85 break;86 }87 } else if(disallowedCookies[j].indexOf('*') === 0) {88 if(allCookies[i].match(disallowedCookies[j].replace('*', '') + '$') == disallowedCookies[j].replace('*', '')) {89 cookieFound = true;90 break;91 }92 } else if(disallowedCookies[j].match("\\*$") == "*") {93 if(allCookies[i].indexOf(disallowedCookies[j].replace('*', '')) === 0) {94 cookieFound = true;95 break;96 }97 } else if(disallowedCookies[j] == allCookies[i]) {98 cookieFound = true;99 break;100 }101 }102 }103 }104 if(!cookieFound) {105 if(definedCookies.length > 0) {106 for( var j = 0; j < definedCookies.length; j++) {107 if(definedCookies[j].cookie.indexOf('*') === 0 && definedCookies[j].cookie.match("\\*$") == '*') {108 if(allCookies[i].indexOf(definedCookies[j].cookie.replace(/\*/g, '')) > -1) {109 cookieFound = true;110 break;111 }112 } else if(definedCookies[j].cookie.indexOf('*') === 0) {113 if(allCookies[i].match(definedCookies[j].cookie.replace(/\*/g, '') + '$') == definedCookies[j].cookie.replace(/\*/g, '')) {114 cookieFound = true;115 break;116 }117 } else if(definedCookies[j].cookie.match("\\*$") == "*") {118 if(allCookies[i].indexOf(definedCookies[j].cookie.replace(/\*/g, '')) === 0) {119 cookieFound = true;120 break;121 }122 } else if(definedCookies[j].cookie == allCookies[i]) {123 cookieFound = true;124 break;125 }126 }127 }128 }129 if(!cookieFound) if(allCookies[i].indexOf($.cookieguard.settings.cookiePrefix) === 0) cookieFound = true;130 if(!cookieFound) {131 unknownCookies.push(allCookies[i]);132 }133 }134 return unknownCookies;135 };136 }137 if(typeof $.cookieguard.cookies.storeAllowedCookie === 'undefined') {138 $.cookieguard.cookies.storeAllowedCookie = function(cookie){139 var allowedCookies = $.cookieguard.cookies.getAllowedCookies();140 var allowedCookiesStr;141 if(allowedCookies == null)142 allowedCookiesStr = cookie;143 else {144 allowedCookiesStr = allowedCookies.join(',');145 if($.inArray(cookie, allowedCookies) == -1) allowedCookiesStr = allowedCookiesStr + ',' + cookie;146 }147 $.cookie($.cookieguard.settings.cookiePrefix + 'allowedCookies', allowedCookiesStr, 365);148 };149 }150 if(typeof $.cookieguard.cookies.getAllowedCookies === 'undefined') {151 $.cookieguard.cookies.getAllowedCookies = function(){152 var allowedCookies = $.cookie($.cookieguard.settings.cookiePrefix + 'allowedCookies');153 if(allowedCookies != null) return allowedCookies.split(',');154 return null;155 };156 }157 if(typeof $.cookieguard.cookies.storeDisallowedCookie === 'undefined') {158 $.cookieguard.cookies.storeDisallowedCookie = function(cookie){159 var disallowedCookies = $.cookieguard.cookies.getDisallowedCookies();160 var disallowedCookiesStr;161 if(disallowedCookies == null)162 disallowedCookiesStr = cookie;163 else {164 disallowedCookiesStr = disallowedCookies.join(',');165 if($.inArray(cookie, disallowedCookies) == -1) disallowedCookiesStr = disallowedCookiesStr + ',' + cookie;166 }167 $.cookie($.cookieguard.settings.cookiePrefix + 'disallowedCookies', disallowedCookiesStr, {expires: 365});168 };169 }170 if(typeof $.cookieguard.cookies.getDisallowedCookies === 'undefined') {171 $.cookieguard.cookies.getDisallowedCookies = function(){172 var disallowedCookies = $.cookie($.cookieguard.settings.cookiePrefix + 'disallowedCookies')173 if(disallowedCookies != null) return disallowedCookies.split(',');174 return null;175 };176 }177 if(typeof $.cookieguard.eradicateCookies === 'undefined') {178 $.cookieguard.eradicateCookies = function(){179 var cookiesToDestroy = $.cookieguard.cookies.getDisallowedCookies();180 var cookiesToAllow = $.cookieguard.cookies.getAllowedCookies();181 var allCookies = new Array();182 for( var i in $.cookie()) {183 allCookies.push(i);184 }185 for( var i = 0; i < allCookies.length; i++) {186 var cookieFound = false;187 if(allCookies[i].indexOf($.cookieguard.settings.cookiePrefix) === 0) cookieFound = true;188 if(!cookieFound) {189 if(cookiesToAllow != null) {190 for( var j = 0; j < cookiesToAllow.length; j++) {191 if(cookiesToAllow[j].indexOf('*') === 0 && cookiesToAllow[j].match("\\*$") == '*') {192 if(allCookies[i].indexOf(cookiesToAllow[j].replace('*', '')) > -1) {193 cookieFound = true;194 break;195 }196 } else if(cookiesToAllow[j].indexOf('*') === 0) {197 if(allCookies[i].match(cookiesToAllow[j].replace('*', '') + '$') == cookiesToAllow[j].replace('*', '')) {198 cookieFound = true;199 break;200 }201 } else if(cookiesToAllow[j].match("\\*$") == "*") {202 if(allCookies[i].indexOf(cookiesToAllow[j].replace('*', '')) === 0) {203 cookieFound = true;204 break;205 }206 } else if(cookiesToAllow[j] == allCookies[i]) {207 cookieFound = true;208 break;209 }210 }211 }212 if(!cookieFound) {213 if(cookiesToDestroy != null) {214 for( var j = 0; j < cookiesToDestroy.length; j++) {215 if(cookiesToDestroy[j].indexOf('*') === 0 && cookiesToDestroy[j].match("\\*$") == '*') {216 if(allCookies[i].indexOf(cookiesToDestroy[j].replace('*', '')) > -1) {217 $.removeCookie(allCookies[i]);218 cookieFound = true;219 break;220 }221 } else if(cookiesToDestroy[j].indexOf('*') === 0) {222 if(allCookies[i].match(cookiesToDestroy[j].replace('*', '') + '$') == cookiesToDestroy[j].replace('*', '')) {223 $.removeCookie(allCookies[i]);224 cookieFound = true;225 break;226 }227 } else if(cookiesToDestroy[j].match("\\*$") == "*") {228 if(allCookies[i].indexOf(cookiesToDestroy[j].replace('*', '')) === 0) {229 $.removeCookie(allCookies[i]);230 cookieFound = true;231 break;232 }233 } else if(cookiesToDestroy[j] == allCookies[i]) {234 $.removeCookie(allCookies[i]);235 cookieFound = true;236 break;237 }238 }239 }240 }241 }242 }243 }244 }245 if(typeof $.cookieguard.run === 'undefined') {246 $.cookieguard.run = function(){247 setTimeout(function(){248 var unknownCookies;249 if($.cookieguard.settings.alertOfUnknown)250 unknownCookies = $.cookieguard.cookies.findUnknownCookies();251 else252 unknownCookies = new Array();253 if(!$.cookieguard.hasAnswered()) {254 $.cookieguard.buildMessage(true, $.cookieguard.settings.cookiesUsed, unknownCookies);255 $.cookieguard.displayMessage($.cookieguard.settings.messageShowDelay, $.cookieguard.settings.messageHideDelay);256 } else {257 $.cookieguard.eradicateCookies();258 if(unknownCookies.length > 0) {259 $.cookieguard.buildMessage(false, null, unknownCookies);260 $.cookieguard.displayMessage($.cookieguard.settings.messageShowDelay, $.cookieguard.settings.messageHideDelay);261 }262 }263 }, $.cookieguard.settings.cookieDeleteDelay);264 };265 }266 if(typeof $.cookieguard.hasAnswered === 'undefined') {267 $.cookieguard.hasAnswered = function(){268 if($.cookie($.cookieguard.settings.cookiePrefix + "initialised") != null)269 return true;270 else271 return false;272 };273 }274 if(typeof $.cookieguard.buildMessage === 'undefined') {275 $.cookieguard.buildMessage = function(init, knownCookies, unknownCookies){276 $('body').prepend('<div id="cookieGuardMsg"><div id="cookieGuardMsgInner"><a href="http://cookieguard.eu" target="_blank" id="cookieGuardLink">Click here to get Cookie Guard for your site</a></div></div>');277 if(init) {278 $('#cookieGuardMsgInner').append('This website uses cookies.<br/>');279 if(unknownCookies.length == 0 && $.cookieguard.hasOnlyEssential())280 $('#cookieGuardMsgInner').addClass('onlyEssential').append('<a href="#" id="showCookies">Show</a><a href="#" id="cookieGuardOkay">Okay</a>');281 else282 $('#cookieGuardMsgInner').append('You may choose to block non-essential and unknown cookies.<a href="#" id="showCookies">Show</a><a href="#" id="authoriseCookies">Allow</a><a href="#" id="denyCookies">Block</a>');283 } else {284 $('#cookieGuardMsgInner').append('Cookie Guard has found new cookies.<br/>');285 $('#cookieGuardMsgInner').append('You may choose to block these cookies.<a href="#" id="showCookies">Show</a><a href="#" id="authoriseCookies">Allow</a><a href="#" id="denyCookies">Block</a>');286 }287 $.cookieguard.buildCookieList(init, knownCookies, unknownCookies);288 $('#cookieGuardOkay').click(function(){289 clearTimeout($.cookieguard.settings.messageHideTimeout);290 $.cookieguard.hideMessage(0);291 $.cookie($.cookieguard.settings.cookiePrefix + 'initialised', '1', {expires: 365});292 return false;293 });294 $('#showCookies').click(function(){295 if($(this).text() == 'Show') {296 clearTimeout($.cookieguard.settings.messageHideTimeout);297 $('#cookieList').show();298 $(this).text('Hide');299 var h = $('#cookieList').outerHeight();300 $('#cookieList').css({'overflow': 'hidden', 'height': 0}).animate({'height': h}, $.cookieguard.settings.slideTimer);301 } else if($(this).text() == 'Hide') {302 $(this).text('Show');303 $('#cookieList').animate({'height': 0}, $.cookieguard.settings.slideTimer, null, function(){304 $('#cookieList').hide().attr('style', '').removeAttr('style');305 });306 }307 return false;308 });309 $('#authoriseCookies').click(function(){310 clearTimeout($.cookieguard.settings.messageHideTimeout);311 $('#cookieGuardMsgInner').empty().addClass('msgAllowed').html('The listed cookies have now been allowed on this site.');312 $.cookieguard.hideMessage($.cookieguard.settings.answeredHideDelay);313 if(knownCookies != null) {314 for( var i = 0; i < knownCookies.length; i++)315 $.cookieguard.cookies.storeAllowedCookie(knownCookies[i].cookie);316 }317 if(unknownCookies != null) {318 for( var i = 0; i < unknownCookies.length; i++)319 $.cookieguard.cookies.storeAllowedCookie(unknownCookies[i]);320 }321 $.cookie($.cookieguard.settings.cookiePrefix + 'initialised', '1', {expires: 365});322 return false;323 });324 $('#denyCookies').click(function(){325 clearTimeout($.cookieguard.settings.messageHideTimeout);326 $('#cookieGuardMsgInner').empty().addClass('msgDenied').html('Non-essential and unknown cookies have now been blocked on this site.');327 $.cookieguard.hideMessage($.cookieguard.settings.answeredHideDelay);328 if(knownCookies != null) {329 for( var i = 0; i < knownCookies.length; i++)330 if(knownCookies[i].essential == false) $.cookieguard.cookies.storeDisallowedCookie(knownCookies[i].cookie);331 }332 if(unknownCookies != null) {333 for( var i = 0; i < unknownCookies.length; i++)334 $.cookieguard.cookies.storeDisallowedCookie(unknownCookies[i]);335 }336 $.cookie($.cookieguard.settings.cookiePrefix + 'initialised', '1', {expires: 365});337 $.cookieguard.eradicateCookies();338 return false;339 });340 };341 }342 if(typeof $.cookieguard.buildCookieList === 'undefined') {343 $.cookieguard.buildCookieList = function(init, knownCookies, unknownCookies){344 var essentialCookies = new Array();345 var unessentialCookies = new Array();346 var knownNames = new Array();347 if(knownCookies != null) {348 for( var i = 0; i < knownCookies.length; i++) {349 if($.inArray(knownCookies[i].name, knownNames) == -1) {350 knownNames.push(knownCookies[i].name);351 if(knownCookies[i].essential)352 essentialCookies.push(knownCookies[i]);353 else354 unessentialCookies.push(knownCookies[i]);355 }356 }357 }358 $('#cookieGuardMsgInner').append('<div id="cookieList"/>');359 if(init) {360 $('#cookieList').append('<div class="cookiesHeader">Essential Cookies <span>- The site owner has indicated that these are essential to the running of the site.</span></div>');361 $('#cookieList').append('<ul class="essentialCookies"/>');362 $('#cookieList > ul.essentialCookies').append('<li><div class="cookieName">Cookie Guard</div><div class="cookieDescription"> - This cookie is essential for storing the status of your cookie choices whilst using this site.</div></li>');363 for( var i = 0; i < essentialCookies.length; i++) {364 $('#cookieList > ul.essentialCookies').append('<li><div class="cookieName">' + essentialCookies[i].name + '</div><div class="cookieDescription"> - ' + essentialCookies[i].description + '</div></li>');365 }366 }367 if(unessentialCookies.length > 0) {368 $('#cookieList').append('<div class="cookiesHeader">Non-Essential Cookies <span>- The site owner has approved these cookies but you may turn them off.</span></div>');369 $('#cookieList').append('<ul class="knownCookies" />');370 for( var i = 0; i < unessentialCookies.length; i++) {371 $('#cookieList > ul.knownCookies').append('<li><div class="cookieName">' + unessentialCookies[i].name + '</div><div class="cookieDescription"> - ' + unessentialCookies[i].description + '</div></li>');372 }373 }374 if(unknownCookies != null && unknownCookies.length > 0) {375 $('#cookieList').append('<div class="cookiesHeader">Unknown Cookies <span>- The site owner has not approved these cookies.</span></div>');376 $('#cookieList').append('<ul class="unknownCookies" />');377 for( var i = 0; i < unknownCookies.length; i++) {378 $('#cookieList > ul.unknownCookies').append('<li><div class="cookieName">' + unknownCookies[i] + '</div></li>');379 }380 }381 };382 }383 if(typeof $.cookieguard.displayMessage === 'undefined') {384 $.cookieguard.displayMessage = function(showDelay, hideDelay){385 $.cookieguard.createCSS();386 $('body').attr('marginTop', $('body').css('marginTop')).css('margin', 0).delay(showDelay).animate({'marginTop': $('#cookieGuardMsg').outerHeight()}, $.cookieguard.settings.slideSpeed);387 $('#cookieGuardMsg').css('top', -$('#cookieGuardMsg').outerHeight());388 $('#cookieGuardMsg').delay(showDelay).show().animate({'top': 0}, $.cookieguard.settings.slideSpeed);389 if($.cookieguard.settings.messageHideDelay != null) {390 $.cookieguard.settings.messageHideTimeout = setTimeout(function(){391 $.cookieguard.hideMessage(0);392 }, hideDelay);393 }394 };395 }396 if(typeof $.cookieguard.hideMessage === 'undefined') {397 $.cookieguard.hideMessage = function(hideDelay){398 $('body').delay(hideDelay).animate({'marginTop': $('body').attr('marginTop')}, $.cookieguard.settings.slideSpeed);399 $('#cookieGuardMsg').delay(hideDelay).animate({'top': -$('#cookieGuardMsg').height()}, $.cookieguard.settings.slideSpeed, null, function(){400 $('#cookieGuardMsg').remove();401 $('body').attr('style', '').removeAttr('style');402 });403 }404 }405 if(typeof $.cookieguard.hasOnlyEssential === 'undefined') {406 $.cookieguard.hasOnlyEssential = function(){407 var knownCookies = $.cookieguard.settings.cookiesUsed;408 for( var i = 0; i < knownCookies.length; i++) {409 if(!knownCookies[i].essential) return false;410 }411 return true;412 }413 }414 if(typeof $.cookieguard.createCSS == 'undefined') {415 $.cookieguard.createCSS = function(){416 var style = '<style id="cookieGuardStyles" type="text/css">';417 style += '#cookieGuardMsg { position: absolute; text-align: left; top: 0; left: 0; width: 100%; display: none; border-bottom: 2px solid #5c5c5c; font-size: 12px; font-family: Arial, Helvetica, Sans-Serif; color: #333; background: #e2e2e2 url(http://cookieguard.eu/images/cookieguardicon.png) no-repeat 12px 12px; min-height: 50px; z-index:99999; }';418 style += '#cookieGuardMsgInner { padding: 10px 10px 10px 55px; }';419 style += '#cookieGuardMsg a { text-decoration: none; font-weight: normal; font-style: normal; }';420 style += '#cookieGuardLink { position: absolute; bottom: 5px; right: 10px; font-size: 10px; color: #912b2b; }';421 style += '#showCookies { position: absolute; display: block; left: 415px; top: 13px; border: 1px solid #999; background: #d4d4d4; color: #5b5858; padding: 5px 10px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }';422 style += '#showCookies:hover { border-color: #666; }';423 style += '#authoriseCookies, #cookieGuardOkay { position: absolute; display: block; left: 500px; top: 13px; border: 1px solid #a2bf8e; background: #d1ecbe; color: #384c2a; padding: 5px 10px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }';424 style += '#authoriseCookies:hover { border-color: #6f8f59; }';425 style += '#denyCookies { position: absolute; display: block; left: 560px; top: 13px; border: 1px solid #cc9c9c; background: #ecc1c1; color: #7e5353; padding: 5px 10px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }';426 style += '#denyCookies:hover { border-color: #9e6a6a;}';427 style += '#cookieList { display: none; padding: 10px 60px 0 0; }';428 style += '#cookieList ul { list-style: none; padding-left: 20px; }';429 style += '#cookieList li { padding: 5px 0; }';430 style += '.cookieName { font-weight: bold; display: inline; }';431 style += '.cookieDescription { display: inline; }';432 style += '.cookiesHeader { font-weight: bold; border-bottom: 1px solid #222; color: #222; margin-bottom: 3px; padding-top: 10px; }';433 style += '.cookiesHeader span { font-weight: normal; font-size: 11px; }';434 style += '#cookieGuardMsgInner.msgAllowed, #cookieGuardMsgInner.msgDenied, #cookieGuardMsgInner.onlyEssential { padding-top: 17px; }';435 style += '</style>';436 $('head').append(style);437 }438 }...
Login.js
Source:Login.js
1import React from 'react';2import axios from "axios";3import {Link} from 'react-router-dom';4import {useCookies, withCookies} from 'react-cookie';5import './Login.css'6function FormLogin(props) {7 return (8 <><h1 class="titre">Login </h1>9 <form onSubmit={props.onSignin}>10 <div class="email">11 <input class="user" type="text" placeholder='Username' id="username" autoComplete="off" ref={props.usernameRef} />12 </div>13 <div class="mdp">14 <input class="pass" type="password" name="password" placeholder='PassWorld' autoComplete="off" ref={props.passwordRef} />15 </div>16 <div className="mt-1 mb-4 text-center">17 <button class="button" type="submit" name="login"><span>Send</span></button>18 </div>19 </form></>20 );21}22function Login() {23 const [cookies, setCookie, removeCookie] = useCookies(['login']);24 const usernameRef = React.createRef();25 const passwordRef = React.createRef();26 function disconnect() {27 removeCookie('login');28 }29 async function onSignup() {30 const user = {31 username: usernameRef.current.value,32 password: passwordRef.current.value33 };34 try {35 const p = (await axios.post('http://localhost:8000/signup', user));36 if (p.status === 200) {37 user.token = p.data.token;38 setCookie('login', user, '/');39 }40 } catch (err) {41 console.error(err)42 }43 }44 async function onSignin(e) {45 e.preventDefault();46 const user = {47 username: e.target.username.value,48 password: e.target.password.value49 };50 try {51 const p = (await axios.post('http://localhost:8000/signin', user));52 if (p.status === 200) {53 user.token = p.data.token;54 setCookie('login', user, '/');55 }56 } catch (err) {57 console.error(err)58 }59 }60 if (cookies.login && cookies.login.token) {61 return <button className="disconnect" id="disconnect" onClick={disconnect}>disconnect</button>;62 }63 return <FormLogin onSignin={onSignin} onSignup={onSignup} usernameRef={usernameRef} passwordRef={passwordRef}/>64}65function LocalProtectedRoute({children, ...rest}) {66 if (rest.allCookies && rest.allCookies.login && rest.allCookies.login.username && rest.allCookies.login.token) {67 return (68 React.cloneElement(children, {username: rest.allCookies.login.username, token: rest.allCookies.login.token})69 )70 }71 return <></>72}73/**74 * @return {null}75 */76function LocalProtectedLink({...rest}) {77 if (rest.allCookies && rest.allCookies.login && rest.allCookies.login.username && rest.allCookies.login.token) {78 return <Link className={rest.className} to={rest.to}>articles</Link>79 } else {80 return null;81 }82}83function NotLocalProtectedLink({...rest}) {84 if (!(rest.allCookies && rest.allCookies.login && rest.allCookies.login.username && rest.allCookies.login.token)) {85 return <Link className={rest.className} to={rest.to}>{rest.children}</Link>86 } else {87 return null;88 }89}90const ProtectedRoute = withCookies(LocalProtectedRoute);91const ProtectedLink = withCookies(LocalProtectedLink);92const NotProtectedLink = withCookies(NotLocalProtectedLink);93export {ProtectedRoute, ProtectedLink,NotProtectedLink};...
cookies.js
Source:cookies.js
1/*****************************************************2 JavaScript Functions for reading and writing cookies3*/45//---------------------------------------------------------678function setCookie (name, value, expire) {9 var expires;10 11 if (expire)12 expires = "; expires=" + expire.toGMTString();13 else14 expires = "";15 16 document.cookie = name + "=" + escape(value) + expires + "; path=/";17} // setCookie1819//---------------------------------------------------------2021function getCookie (Name) {22 var end;23 var search;24 var offset;25 var value;26 var allcookies = document.cookie;27 28 search = Name + "=";2930 if (allcookies.length > 0) { 31 offset = allcookies.indexOf(search);3233 if (offset != -1) {34 offset += search.length;35 // set index of beginning of value36 end = allcookies.indexOf(";", offset);37 // set index of end of cookie value38 if (end == -1) end = allcookies.length;3940 value = unescape(allcookies.substring(offset, end));41 }42 else43 value = null;44 }45 else46 value = null;47 48 return value;49} // getCookie5051//---------------------------------------------------------5253function deleteCookie (name) {54 if (""!=getCookie(name)) {55 // document.cookie = name + "=" + "; expires=Fri, 01-Jan-70 00:00:01 GMT; path=/";56 document.cookie = name + "=" + "; expires=; path=/";57 }
...
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 const cookies = await chromeless.cookies()5 console.log(cookies)6 await chromeless.end()7}8run().catch(console.error.bind(console))9const Chromeless = require('chromeless').Chromeless10async function run() {11 const chromeless = new Chromeless()12 const cookies = await chromeless.cookies()13 console.log(cookies)14 await chromeless.end()15}16run().catch(console.error.bind(console))17const Chromeless = require('chromeless').Chromeless18async function run() {19 const chromeless = new Chromeless()20 await chromeless.setCookie({21 })22 await chromeless.end()23}24run().catch(console.error.bind(console))25const Chromeless = require('chromeless').Chromeless26async function run() {27 const chromeless = new Chromeless()28 await chromeless.setCookie({29 })30 await chromeless.end()31}32run().catch(console.error.bind(console))33const Chromeless = require('chromeless').Chromeless34async function run() {35 const chromeless = new Chromeless()36 await chromeless.clearCookies()37 await chromeless.end()38}39run().catch(console.error.bind(console))40const Chromeless = require('chromeless').Chromeless41async function run() {42 const chromeless = new Chromeless()43 await chromeless.clearCookies()44 await chromeless.end()45}46run().catch(console.error.bind(console))
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .allCookies()8 await chromeless.end()9}10run().catch(console.error.bind(console))11const Chromeless = require('chromeless').Chromeless12async function run() {13 const chromeless = new Chromeless()14 .type('chromeless', 'input[name="q"]')15 .press(13)16 .wait('#resultStats')17 .deleteAllCookies()18 await chromeless.end()19}20run().catch(console.error.bind(console))21const Chromeless = require('chromeless').Chromeless22async function run() {23 const chromeless = new Chromeless()24 .type('chromeless', 'input[name="q"]')25 .press(13)26 .wait('#resultStats')27 .deleteCookie('NID')28 await chromeless.end()29}30run().catch(console.error.bind(console))31const Chromeless = require('chromeless').Chromeless32async function run() {33 const chromeless = new Chromeless()34 .type('chromeless', 'input[name="q"]')35 .press(13)36 .wait('#resultStats')37 .setCookie({name: 'NID', value: '1234567890', domain: 'google.com'})38 await chromeless.end()39}40run().catch(console.error.bind(console))
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 const cookies = await chromeless.allCookies()5 await chromeless.end()6}7run().catch(console.error.bind(console))8const Chromeless = require('chromeless').Chromeless9async function run() {10 const chromeless = new Chromeless()11 const cookies = await chromeless.allCookies()12 await chromeless.end()13}14run().catch(console.error.bind(console))15const Chromeless = require('chromeless').Chromeless16async function run() {17 const chromeless = new Chromeless()18 const cookies = await chromeless.allCookies()19 await chromeless.end()20}21run().catch(console.error.bind(console))22const Chromeless = require('chromeless').Chromeless23async function run() {24 const chromeless = new Chromeless()25 const cookies = await chromeless.allCookies()26 await chromeless.end()27}28run().catch(console.error.bind(console))29const Chromeless = require('chromeless').Chromeless30async function run() {31 const chromeless = new Chromeless()32 const cookies = await chromeless.allCookies()33 await chromeless.end()34}35run().catch(console.error.bind(console))36const Chromeless = require('chromeless').Chromeless37async function run() {38 const chromeless = new Chromeless()39 const cookies = await chromeless.allCookies()40 await chromeless.end()41}42run().catch(console.error.bind(console))43const Chromeless = require('chromeless').Chromeless44async function run() {45 const chromeless = new Chromeless()
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless;2const chromeless = new Chromeless();3 .type('chromeless', 'input[name="q"]')4 .press(13)5 .wait('#resultStats')6 .allCookies()7 .then((cookies) => {8 console.log(cookies);9 })10 .end()11 .catch((err) => {12 console.error(err);13 process.exit(1);14 });15const Chromeless = require('chromeless').Chromeless;16const chromeless = new Chromeless();17 .type('chromeless', 'input[name="q"]')18 .press(13)19 .wait('#resultStats')20 .allCookies()21 .then((cookies) => {22 console.log(cookies);23 })24 .end()25 .catch((err) => {26 console.error(err);27 process.exit(1);28 });29const Chromeless = require('chromeless').Chromeless;30const chromeless = new Chromeless();31 .type('chromeless', 'input[name="q"]')32 .press(13)33 .wait('#resultStats')34 .allCookies()35 .then((cookies) => {36 console.log(cookies);37 })38 .end()39 .catch((err) => {40 console.error(err);41 process.exit(1);42 });43const Chromeless = require('chromeless').Chromeless;44const chromeless = new Chromeless();45 .type('chromeless', 'input[name="q"]')46 .press(13)47 .wait('#resultStats')48 .allCookies()49 .then((cookies) => {50 console.log(cookies);51 })52 .end()53 .catch((err) => {54 console.error(err);55 process.exit(1);56 });57const Chromeless = require('
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 .setCookie({name: 'foo', value: 'bar'})5 .setCookie({name: 'foo', value: 'baz'})6 .allCookies()7 console.log(cookies)8 await chromeless.end()9}10run().catch(console.error.bind(console))11const Chromeless = require('chromeless').Chromeless12async function run() {13 const chromeless = new Chromeless()14 .setCookie({name: 'foo', value: 'bar'})15 .setCookie({name: 'foo', value: 'baz'})16 .allCookies()17 console.log(cookies)18 await chromeless.end()19}20run().catch(console.error.bind(console))21const Chromeless = require('chromeless').Chromeless22async function run() {23 const chromeless = new Chromeless()24 .setCookie({name: 'foo', value: 'bar'})25 .setCookie({name: 'foo', value: 'baz'})26 .allCookies()27 console.log(cookies)28 await chromeless.end()29}30run().catch(console.error.bind(console))31const Chromeless = require('chromeless').Chromeless32async function run() {33 const chromeless = new Chromeless()34 .setCookie({name: 'foo', value: 'bar'})35 .setCookie({name: 'foo', value: 'baz'})36 .allCookies()37 console.log(cookies)38 await chromeless.end()39}40run().catch(console.error.bind(console))41const Chromeless = require('chromeless').Chromeless42async function run() {43 const chromeless = new Chromeless()
Using AI Code Generation
1const chromeless = new Chromeless()2 .allCookies()3await chromeless.end()4const chromeless = new Chromeless()5 .setCookie({6 })7 .allCookies()8await chromeless.end()9const chromeless = new Chromeless()10 .deleteCookie({ name: 'foo', domain: 'www.google.com', path: '/' })11 .allCookies()12await chromeless.end()13const chromeless = new Chromeless()14 .setCookie({15 })16 .allCookies()17await chromeless.end()18const chromeless = new Chromeless()19 .setCookie({20 expiry: Date.now() + 1000 * 60 *
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless;2const chromeless = new Chromeless();3 .cookies.get()4console.log(allCookies)5await chromeless.end();6const Chromeless = require('chromeless').Chromeless;7const chromeless = new Chromeless();8 .cookies.get('NID')9console.log(cookie)10await chromeless.end();11const Chromeless = require('chromeless').Chromeless;12const chromeless = new Chromeless();13 .cookies.set('NID', '123456789')14console.log(cookie)15await chromeless.end();16const Chromeless = require('chromeless').Chromeless;17const chromeless = new Chromeless();18 .cookies.clear('NID')19console.log(cookie)20await chromeless.end();21const Chromeless = require('chromeless').Chromeless;22const chromeless = new Chromeless();23 .cookies.clearAll()24console.log(cookie)25await chromeless.end();26const Chromeless = require('chromeless').Chromeless;27const chromeless = new Chromeless();28 .setUserAgent('Chromeless')29console.log(userAgent)30await chromeless.end();31const Chromeless = require('chromeless').Chromeless;32const chromeless = new Chromeless();33 .setViewport({width: 1920, height: 1080, scale: 1})34console.log(viewport)
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const chromeless = new Chromeless()3async function run() {4 .allCookies()5 await chromeless.end()6}7run().catch(console.error.bind(console))8const Chromeless = require('chromeless').Chromeless9const chromeless = new Chromeless()10async function run() {11 .setCookie({ name: 'foo', value: 'bar', domain: 'www.google.com' })12 .end()13}14run().catch(console.error.bind(console))15const Chromeless = require('chromeless').Chromeless16const chromeless = new Chromeless()17async function run() {18 .clearCookies()19 .end()20}21run().catch(console.error.bind(console))22const Chromeless = require('chromeless').Chromeless23const chromeless = new Chromeless()24async function run() {25 .clearCookies({ name: 'foo', domain: 'www.google.com' })26 .end()27}28run().catch(console.error.bind(console))29const Chromeless = require('chromeless').Chromeless30const chromeless = new Chromeless()31async function run() {32 .clearCookies()33 .end()34}35run().catch(console.error.bind(console))36const Chromeless = require('chromeless').Chromeless
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!