Hello Friends, In the last article we learned to create a sample chrome extension. Here we are going to create auto logout Gmail script as an extension.
In case you want to learn how to create a sample extension please visit this link. So here we are not going to learn the basics of extension. Lets go through the code.
Step 1 - Create a manifest.json file. It should contain a valid json content –
e.g –
{ "manifest_version": 2, "name": "Logout from Gmail", "description": "Auto logout from Gmail after 5 minute.", "version": "1.0", "author": "Saurabh Singh", "browser_action": { "default_title":"You will be logged out in 5 minute.", "default_icon": "icon.png", "default_popup": "popup.html" }, "content_scripts":[ { "matches" : ["https://mail.google.com/*"], "js" : ["Gmail.js"] }], "permissions": [ "activeTab", "idle", "storage", "tabCapture", "tabs", "https://mail.google.com/*" ] }
Step 2- In content Script we mentioned a js file which will be loaded after adding extension at chrome. Let’s see the code.
var timer = window.setInterval(logout, 500000); function Validate(object){ if(typeof object === 'undefined') {return true; } return false; } function logout() { var signoutButton = document.getElementById("gb_71"); if (!Validate(signoutButton)) { alert("Time is up. You will be logged out"); signoutButton.click(); } clearTimeout(timer); }
Step 3 – Create an icon file icon.png and place it at the same folder structure.
<html>
<head>
<style>
body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}
#status {
/* avoid an excessively wide status text */
white-space: pre;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
</head>
<body>
<h4>Auto Logout from Gmail</h4></body>
</html>
We are good with our Auto log out facebook extension. In case you want to download the code please ClickMe.