Simple cross-browser cookie consent plugin written in plain javascript

Cookie Consent

Simple cross-browser cookie consent plugin written in plain javascript.

Why though

I wanted a simple, lightweight but also “extensible” plugin, which could be placed in my own web server without the need of making additional external requests. The reason was to further optimize the loading speed of my website.

Main features

  • Cross-browser support (IE8+)
  • Standalone (no external dependecies needed)
  • Lightweight (~ 8kb for optimized/minified version)
  • Can easily add support for additional languages
  • Automatic browser language detection
  • No additional external http requests

How to run

  • Include file (or load it dynamically)

     <script src="<your_path>/cookieconsent.js"></script>
    
  • Initialize cookieconsent (with default config. settings)

     CookieConsent.run(<config_object>);
    
  • Show cookieconsent modal (will show only if cookieconsent was not alredy accepted)

     CookieConsent.show(<optional_delay_value>);
    
  • Hide cookieconsent modal (if it is attached to dom)

     CookieConsent.hide();
    

Custom config. settings

Another way is to run the cookieconsent with an initial config object like in the example below.

CookieConsent.run({
	"cc_autorun" : false, 						
	"cc_delay" : 0,								
	"cc_website_name" : "Orest Bida",
	"cc_website_url" : "orestbida.com",				
	"cc_enable_verbose" : true,					
	"cc_current_lang" : "en",	
	"cc_auto_language" : false,					
	"cc_theme_css" : "<your_path>/cookieconsent.css"
});

Config. properties

  • cc_autorun : (boolean)
    • default : false
    • if set to true, cookieconsent will show modal as soon as loaded
  • cc_delay : (number)
    • default : 0
    • if specified (>=0), there will be an initial delay before showing the cookieconsent modal
    • useful when you have implemented a “loader”
  • cc_enable_verbose : (boolean)
    • default : true
    • if set to true, all informational/error messages will show on console
  • cc_current_lang : (string)
    • default : “en”
    • when specified, modal will be set to that language (if it is implemented)
  • cc_auto_language : (boolean)
    • default : false
    • if set to true, cc_current_lang will be ignored, and the cookieconsent modal will set its language based on client browser language (if specific client browser language is not defined, a fallback_language=“en” will be used instead)
  • cc_theme_css : (string)
    • default : null
    • specify path to local cookieconsent.css file

TODO

List of things to implement

  • Add the possibility of “quickly” defining a new language without the necessity of directly editing source file
  • Make cookieconsent GPDR compliant:
    • Implement “learn more” modal with a brief explanation about cookies
    • Implement custom-cookie-table containing:
      • column for cookie-name
      • column for cookie-description
      • column for cookie-expiration-date
    • Implement the (eventual) possibility of opting-out of cookie-consent

Download Details:

Author: orestbida

Source Code: https://github.com/orestbida/cookieconsent

#javascript

What is GEEK

Buddha Community

Simple cross-browser cookie consent plugin written in plain javascript

Simple cross-browser cookie consent plugin written in plain javascript

Cookie Consent

Simple cross-browser cookie consent plugin written in plain javascript.

Why though

I wanted a simple, lightweight but also “extensible” plugin, which could be placed in my own web server without the need of making additional external requests. The reason was to further optimize the loading speed of my website.

Main features

  • Cross-browser support (IE8+)
  • Standalone (no external dependecies needed)
  • Lightweight (~ 8kb for optimized/minified version)
  • Can easily add support for additional languages
  • Automatic browser language detection
  • No additional external http requests

How to run

  • Include file (or load it dynamically)

     <script src="<your_path>/cookieconsent.js"></script>
    
  • Initialize cookieconsent (with default config. settings)

     CookieConsent.run(<config_object>);
    
  • Show cookieconsent modal (will show only if cookieconsent was not alredy accepted)

     CookieConsent.show(<optional_delay_value>);
    
  • Hide cookieconsent modal (if it is attached to dom)

     CookieConsent.hide();
    

Custom config. settings

Another way is to run the cookieconsent with an initial config object like in the example below.

CookieConsent.run({
	"cc_autorun" : false, 						
	"cc_delay" : 0,								
	"cc_website_name" : "Orest Bida",
	"cc_website_url" : "orestbida.com",				
	"cc_enable_verbose" : true,					
	"cc_current_lang" : "en",	
	"cc_auto_language" : false,					
	"cc_theme_css" : "<your_path>/cookieconsent.css"
});

Config. properties

  • cc_autorun : (boolean)
    • default : false
    • if set to true, cookieconsent will show modal as soon as loaded
  • cc_delay : (number)
    • default : 0
    • if specified (>=0), there will be an initial delay before showing the cookieconsent modal
    • useful when you have implemented a “loader”
  • cc_enable_verbose : (boolean)
    • default : true
    • if set to true, all informational/error messages will show on console
  • cc_current_lang : (string)
    • default : “en”
    • when specified, modal will be set to that language (if it is implemented)
  • cc_auto_language : (boolean)
    • default : false
    • if set to true, cc_current_lang will be ignored, and the cookieconsent modal will set its language based on client browser language (if specific client browser language is not defined, a fallback_language=“en” will be used instead)
  • cc_theme_css : (string)
    • default : null
    • specify path to local cookieconsent.css file

TODO

List of things to implement

  • Add the possibility of “quickly” defining a new language without the necessity of directly editing source file
  • Make cookieconsent GPDR compliant:
    • Implement “learn more” modal with a brief explanation about cookies
    • Implement custom-cookie-table containing:
      • column for cookie-name
      • column for cookie-description
      • column for cookie-expiration-date
    • Implement the (eventual) possibility of opting-out of cookie-consent

Download Details:

Author: orestbida

Source Code: https://github.com/orestbida/cookieconsent

#javascript

JavaScript Snake Game Tutorial - Develop a Simple Snake Game

Work on real-time JavaScript Snake game project and become a pro

Snake game is an interesting JavaScript project for beginners. Snake game is a single-player game, which we’ve been playing for a very long time. The game mainly consists of two components – snake and fruit. And we just need to take our snake to the food so that it can eat and grow faster and as the number of fruits eaten increases, the length of snake increases which makes the game more interesting. While moving if the snake eats its own body, then the snake dies and the game ends. Now let’s see how we can create this.

JavaScript Project Prerequisites

To implement the snake game in JavaScript you should have basic knowledge of:

1. Basic concepts of JavaScript

2. HTML

3. CSS

Download Project Code

Before proceeding ahead please download source code of Snake Game: Snake Game in JavaScript

Steps to Build the Project – JavaScript Snake game

1. Create Html file

HTML builds the basic structure. This file contains some basic HTML tags like div, h1, title, etc. also we’ve used bootstrap (CDN is already included).

index.html:

Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DataFlair Snake game</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link rel="stylesheet" href="static/style.css">
</head>
<body>
    <div class="container">
        <div class ="Jumbotron">
        <h1>DataFlair Snake game using vanilla JavaScript</h1>

            <h2 class="btn btn-info"> 
                Score:   0 
            </h2>

            <div class="containerCanvas">
                <canvas id="canvas" width="500" height="500" class="canvasmain"> </canvas>
            </div>
        </div>
    </div>
    <script src="static/fruit.js"></script>
    <script src="static/snake.js"></script>
    <script src="static/draw.js"></script>
</body>
</html>

We have used simple HTML tags except tag. This new tag was introduced in HTML5, which is used to draw graphics, via JavaScript. It is nothing without JavaScript so we will use it in our JavaScript file to actually draw the board and the objects required. We’ll see its implementation in JS files.

#javascript tutorial #javascript project #javascript snake game #simple snake game #javascript

Santosh J

1622036598

JavaScript compound assignment operators

JavaScript is unarguablly one of the most common things you’ll learn when you start programming for the web. Here’s a small post on JavaScript compound assignment operators and how we use them.

The compound assignment operators consist of a binary operator and the simple assignment operator.

The binary operators, work with two operands. For example a+b where + is the operator and the a, b are operands. Simple assignment operator is used to assign values to a variable(s).

It’s quite common to modify values stored in variables. To make this process a little quicker, we use compound assignment operators.

They are:

  • +=
  • -+
  • *=
  • /=

You can also check my video tutorial compound assignment operators.

Let’s consider an example. Suppose price = 5 and we want to add ten more to it.

var price = 5;
price = price + 10;

We added ten to price. Look at the repetitive price variable. We could easily use a compound += to reduce this. We do this instead.

price += 5;

Awesome. Isn’t it? What’s the value of price now? Practice and comment below. If you don’t know how to practice check these lessons.

Lets bring down the price by 5 again and display it.
We use console.log command to display what is stored in the variable. It is very help for debugging.
Debugging let’s you find errors or bugs in your code. More on this later.

price -= 5;
console.log(price);

Lets multiply price and show it.

price *=5;
console.log(price);

and finally we will divide it.

price /=5;
console.log(price);

If you have any doubts, comment below.

#javascript #javascript compound assignment operators #javascript binary operators #javascript simple assignment operator #doers javascript

CSS Boss

CSS Boss

1606912089

How to create a calculator using javascript - Pure JS tutorials |Web Tutorials

In this video I will tell you How to create a calculator using javascript very easily.

#how to build a simple calculator in javascript #how to create simple calculator using javascript #javascript calculator tutorial #javascript birthday calculator #calculator using javascript and html

Rahul Jangid

1622207074

What is JavaScript - Stackfindover - Blog

Who invented JavaScript, how it works, as we have given information about Programming language in our previous article ( What is PHP ), but today we will talk about what is JavaScript, why JavaScript is used The Answers to all such questions and much other information about JavaScript, you are going to get here today. Hope this information will work for you.

Who invented JavaScript?

JavaScript language was invented by Brendan Eich in 1995. JavaScript is inspired by Java Programming Language. The first name of JavaScript was Mocha which was named by Marc Andreessen, Marc Andreessen is the founder of Netscape and in the same year Mocha was renamed LiveScript, and later in December 1995, it was renamed JavaScript which is still in trend.

What is JavaScript?

JavaScript is a client-side scripting language used with HTML (Hypertext Markup Language). JavaScript is an Interpreted / Oriented language called JS in programming language JavaScript code can be run on any normal web browser. To run the code of JavaScript, we have to enable JavaScript of Web Browser. But some web browsers already have JavaScript enabled.

Today almost all websites are using it as web technology, mind is that there is maximum scope in JavaScript in the coming time, so if you want to become a programmer, then you can be very beneficial to learn JavaScript.

JavaScript Hello World Program

In JavaScript, ‘document.write‘ is used to represent a string on a browser.

<script type="text/javascript">
	document.write("Hello World!");
</script>

How to comment JavaScript code?

  • For single line comment in JavaScript we have to use // (double slashes)
  • For multiple line comments we have to use / * – – * /
<script type="text/javascript">

//single line comment

/* document.write("Hello"); */

</script>

Advantages and Disadvantages of JavaScript

#javascript #javascript code #javascript hello world #what is javascript #who invented javascript