Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* cookies.js - PUBLIC DOMAIN RELEASE - VERSION 1.0.0 - https://pastebin.com/RPyacWpg */
- var Cookies = new function ( ) {
- var UseCookies = false;
- try { UseCookies = G_USE_COOKIES; }
- catch ( error ) { UseCookies = true; }
- this.SetUseCookies = function ( UseCookiesIn ) { UseCookies = UseCookiesIn; }
- this.GetUseCookies = function ( ) { return UseCookies; }
- this.GetCookie = function ( NameIn, DefaultValueIn ) {
- var CookieValue = Private.GetCookieValue ( NameIn );
- if ( CookieValue == null || CookieValue == undefined ) { CookieValue = ''; }
- var CookieDefault = DefaultValueIn;
- if ( CookieDefault == null || CookieDefault == undefined ) { CookieDefault = ''; }
- if ( CookieValue == '' && CookieDefault != '' ) {
- CookieValue = CookieDefault;
- this.SetCookie ( NameIn, CookieValue, 365 );
- }
- return CookieValue;
- }
- this.GetCookieAndSetDaily = function ( NameIn, DefaultValueIn ) {
- var CookieValue = Private.GetCookieValue ( NameIn );
- if ( CookieValue == null || CookieValue == undefined ) { CookieValue = ''; }
- var CookieDefault = DefaultValueIn;
- if ( CookieDefault == null || CookieDefault == undefined ) { CookieDefault = ''; }
- var Today = new Date ( );
- var CookieDateName = NameIn + ' Date';
- var CookieDate = this.GetCookie ( CookieDateName, Today );
- CookieDate = Date.parse ( CookieDate );
- CookieDate = new Date ( CookieDate );
- var DoSet = false;
- if ( CookieValue == '' && CookieDefault != '' ) {
- CookieValue = CookieDefault;
- DoSet = true;
- }
- if ( DoSet == true || Today.toDateString ( ) != CookieDate.toDateString ( ) ) {
- this.SetCookie ( CookieDateName, Today, 365 );
- this.SetCookie ( NameIn, CookieValue, 365 );
- }
- return CookieValue;
- }
- this.SetCookie = function ( NameIn, ValueIn, DaysExpireIn ) {
- if ( UseCookies == false ) { return; }
- var ExpiryDate = new Date ( );
- ExpiryDate.setTime ( ExpiryDate.getTime ( ) + ( DaysExpireIn * 24 * 60 * 60 * 1000 ) );
- var Expires = 'expires=' + ExpiryDate.toUTCString ( );
- document.cookie = NameIn + '=' + ValueIn + '; ' + Expires + '; path=/';
- }
- var Private = {
- GetCookieValue: function ( NameIn ) {
- var Output = '';
- var CookieValue = '';
- var Name = NameIn + '=';
- var CookieArray = document.cookie.split ( ';' );
- for ( var Count = 0; Count < CookieArray.length; Count++ ) {
- CookieValue = CookieArray[Count];
- CookieValue = CookieValue.trim ( );
- if ( CookieValue.indexOf( Name ) == 0 ) {
- Output = CookieValue.substring ( Name.length );
- break;
- }
- }
- return Output;
- }
- };
- }
Advertisement
RAW Paste Data
Copied
Advertisement