Lennart Weller 7 years ago
commit
4f2bd4a5bd
11 changed files with 452 additions and 0 deletions
  1. +123
    -0
      contentScript.js
  2. +46
    -0
      contentScript.js.old
  3. BIN
      icon128.png
  4. BIN
      icon19.png
  5. BIN
      icon48.png
  6. +79
    -0
      main.html
  7. +24
    -0
      manifest.json
  8. +133
    -0
      options.html
  9. +32
    -0
      overlay.css
  10. BIN
      overlay.png
  11. +15
    -0
      popup.html

+ 123
- 0
contentScript.js View File

@ -0,0 +1,123 @@
// Variable to keep track of if autologin has been stopped
stopped = false
// Helper function
function findFirstFilledOutPasswordInput()
{
input = false;
arDocuments = new Array();
// add main document
arDocuments.push(document);
// add frames
frames = document.getElementsByTagName('frame');
for(i in frames)
arDocuments.push(frames[i].contentDocument);
// add iframes
iframes = document.getElementsByTagName('frame');
for(i in iframes)
arDocuments.push(iframes[i].contentDocument);
// iterate over documents looking for password inputs
for(i in arDocuments)
{
result = document.evaluate("//input[@type='password']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// iterate over password inputs looking for filled ones
for(i=0;i<result.snapshotLength;i++)
{
if(result.snapshotItem(i).value != '')
{
input = result.snapshotItem(i);
break;
}
}
if(input)
break;
}
return input;
}
// Submits the form, calling event handlers first
// (if the log in hasn't been stopped)
function submitWithEventHandlers(theForm)
{
if (!stopped)
{
submitForm = true;
// look for onsubmit handler
submitFunc = theForm.onsubmit;
if (typeof submitFunc == 'function')
{
submitForm = submitFunc.call(theForm);
}
else // look for inline defined onsubmit
{
// nevermind, can't call it because of scope issues
}
if (submitForm)
{
theForm.submit();
}
else
{
alert('Form submittal was cancelled by the page. Check for invalid inputs. If there are none, AutoLogin may not be compatible with this site.');
if(overlay = document.getElementById('AutoLoginOverlay'))
document.body.removeChild(overlay);
}
}
}
// Respond to requests from the background page
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse)
{
if (!stopped)
{
input = findFirstFilledOutPasswordInput();
// submit form
if (input)
{
if (request.overlay) // display cool graphic
{
var overlay = document.createElement('div');
overlay.setAttribute('id', 'AutoLoginOverlay');
//overlay.style.height = window.innerHeight + 'px';
document.body.appendChild(overlay);
h1 = document.createElement('h1');
h1.innerText = 'Logging in...';
h1.style.marginTop = ((window.innerHeight / 2) - (150 / 2)) + 'px';
overlay.appendChild(h1);
var h2 = document.createElement('h2');
h2.innerText = "Cancel";
h2.onclick = function ()
{
window.stop();
stopped = true;
document.body.removeChild(overlay);
};
overlay.appendChild(h2);
setTimeout(function () { submitWithEventHandlers(input.form) }, request.wait * 1000);
}
else
{
submitWithEventHandlers(input.form);
}
}
}
}
);
// Check if the "page action" icon should be displayed
input = findFirstFilledOutPasswordInput()
chrome.extension.sendRequest({showIcon: (input != false)});

+ 46
- 0
contentScript.js.old View File

@ -0,0 +1,46 @@
// Preload image
//var img = document.createElement('img');
//img.src = chrome.extension.getURL("overlay.png");
// Respond to requests from the background page
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse)
{
result = document.evaluate("//input[@type='password']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// finds the first filled out password field
for(i=0;i<result.snapshotLength;i++)
{
input = result.snapshotItem(i);
// check that it's filled
if(input.value != '')
{
if(request.overlay) // display cool graphic
{
var overlay = document.createElement('div');
overlay.setAttribute('id','AutoLoginOverlay');
overlay.style.height = document.height + 'px';
//var img = document.createElement('img');
//img.src = chrome.extension.getURL("overlay.png");
//img.style.marginTop = ((window.innerHeight/2) - (256/2)) + 'px';
//overlay.appendChild(img);
h1 = document.createElement('h1');
h1.innerText = 'Logging in...';
h1.style.marginTop = ((window.innerHeight/2) - (50/2)) + 'px';
overlay.appendChild(h1);
document.body.appendChild(overlay);
}
// submit form
input.form.submit();
break;
}
}
}
);
// Check if the "page action" icon should be displayed
result = document.evaluate("//input[@type='password']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
chrome.extension.sendRequest({showIcon: (result.snapshotLength > 0 && result.snapshotItem(0).value != '')});

BIN
icon128.png View File

Before After
Width: 128  |  Height: 128  |  Size: 11 KiB

BIN
icon19.png View File

Before After
Width: 19  |  Height: 19  |  Size: 934 B

BIN
icon48.png View File

Before After
Width: 48  |  Height: 48  |  Size: 2.8 KiB

+ 79
- 0
main.html View File

@ -0,0 +1,79 @@
<html>
<body>
<script>
// initialize options
defaultOptions = {
'overlay' : true,
'wait' : 0
}
// clean up bad data in localStorage from version 1.1
if(localStorage.getItem('options') && localStorage.getItem('options') == '"options"')
localStorage.removeItem('options');
if(o = localStorage.getItem('options'))
{
options = JSON.parse(o);
if(!options.overlay)
options.overlay = defaultOptions.overlay;
if(!options.wait)
options.wait = defaultOptions.wait;
}
else
{
options = defaultOptions;
localStorage.setItem('options', JSON.stringify(defaultOptions));
}
// add new tab listener
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (tab.status == "complete") {
for (i = 0; i < localStorage.length; i++)
{
url = localStorage.key(i);
if (url.indexOf("*") > -1)
{
url = url.split('*')[0];
if (tab.url.indexOf(url) == 0) // if the tab URL starts with the wildcarded URL, request log in
{
chrome.tabs.sendRequest(tab.id, options);
break;
}
}
else
{
if (url == tab.url) // if URL is in the list, send a request to log in
{
chrome.tabs.sendRequest(tab.id, options);
break;
}
}
}
}
});
// Respond to request to display "page action" icon from the content script
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse)
{
if (request.showIcon) // if password field is present, present icon
chrome.pageAction.show(sender.tab.id);
}
);
// function to save page to localStorage. called by the popup.
function savePage()
{
chrome.tabs.getSelected(null, function(tab)
{
localStorage.setItem(tab.url, tab.title);
chrome.tabs.update(tab.id,{'url':tab.url});
});
}
</script>
</body>
</html>

+ 24
- 0
manifest.json View File

@ -0,0 +1,24 @@
{
"background_page": "main.html",
"content_scripts": [ {
"css": [ "overlay.css" ],
"js": [ "contentScript.js" ],
"matches": [ "http://*/*", "https://*/*" ]
} ],
"description": "Why not skip the login page? Automatically logs you into sites that Chrome has a saved password for.",
"icons": {
"128": "icon128.png",
"19": "icon19.png",
"48": "icon48.png"
},
"name": "Auto Login",
"options_page": "options.html",
"page_action": {
"default_icon": "icon19.png",
"default_title": "Log in to this page automatically.",
"popup": "popup.html"
},
"permissions": [ "tabs" ],
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "1.5.1"
}

+ 133
- 0
options.html View File

@ -0,0 +1,133 @@
<html>
<head>
<style>
body {
font-family: sans-serif;
}
#header {
text-align: center;
background-color: black;
color: white;
text-align: left;
}
h1, h3 {
padding: 10px;
margin: 0px;
}
h3 {
text-align: right;
}
td a {
color: red;
text-decoration: none;
}
p {
width: 500px;
}
p.center {
margin: 20px auto;
}
table {
border-collapse: collapse;
width: 100%;
}
.url {
width: 100%;
}
</style>
</head>
<body>
<table id="header"><tr>
<td valign="middle"><h1><img src="icon48.png" align="center"/>&nbsp;&nbsp;&nbsp;Auto Login Options</h1></td>
<td valign="middle"><h3>(close this tab to save)</h3></td>
</tr></table>
<h4>
Display message while login page is being submitted?
<label><input type="radio" name="overlay" value="true">Yes</label>
<label><input type="radio" name="overlay" value="false">No</label>
</h4>
<h4>
<label>Seconds to wait before auto submitting
(only active if message is displayed)&nbsp; <input type="text" name="wait" value="0" size="1"></label>
</h4>
<script>
// radio buttons
var options = chrome.extension.getBackgroundPage().options;
buttons = document.getElementsByTagName('input');
if(options.overlay) {
buttons[0].checked = true;
} else {
buttons[1].checked = true;
}
buttons[2].value = options.wait;
window.onunload = function saveOptions()
{
localStorage.clear()
options.overlay = buttons[0].checked;
options.wait = buttons[2].value;
localStorage.setItem('options', JSON.stringify(options));
urlList = document.getElementsByClassName('url');
titleList = document.getElementsByClassName('title');
for (i = 0; i < urlList.length; i++) {
localStorage.setItem(urlList[i].value, titleList[i].innerText);
}
}
</script>
<h2>Login pages to bypass</h2>
<p>If you'd like to match the beginning of an URL, add a * to the end of it.
For example, "http://www.facebook.com/*" will log you in to "http://www.facebook.com/" and "http://www.facebook.com/index.php"</p>
<script>
function removePage(element, key)
{
row = element.parentElement.parentElement;
row.parentElement.removeChild(row);
localStorage.removeItem(key);
if(localStorage.length == 1) // reload to show instructions if list empty
window.location=window.location;
}
// list of pages
if(localStorage.length == 1) // there will always be options
{
document.write('<p style="font-weight:bold">No sites are set for auto login yet.</p>');
document.write('<p>To add a site, navigate to the login page of a site which Chrome has saved the password for ');
document.write('and click the Auto Login icon that will appear next to the site\'s URL')
}
else
{
document.write('<table border="1" cellspacing="0" cellpadding="3">');
document.write('<tr><th>Remove</th><th>Page Title</th><th>Page URL <small>(add * after the URL to enable partial matching)</small></th></tr>');
for(i=0; i<localStorage.length; i++)
{
if(localStorage.key(i) == 'options')
continue;
document.write('<tr>');
//document.write('<td align="center"><a href="javascript:localStorage.removeItem(\'' + localStorage.key(i) + '\');window.location=window.location;">X</a></td>');
document.write('<td align="center"><a href="#" onclick="removePage(this, \'' + localStorage.key(i) + '\');">X</a></td>');
document.write('<td><small class="title">' + localStorage.getItem(localStorage.key(i)) + '</small></td>');
document.write('<td><input class="url" value="' + localStorage.key(i) + '"/></td>');
document.write('</tr>');
}
document.write('</table>');
}
</script>
<p>&nbsp;</p>
<p class="center">
<b>Note:</b> your password must be saved by the browser to be automatically logged in.
The <a href="https://chrome.google.com/extensions/detail/ecpgkdflcnofdbbkiggklcfmgbnbabhh">"Autocomplete = on"</a> extension can help
for pages that disallow saving your password.
</p>
<p>&nbsp;</p>
<p class="center">
Bugs? Feature requests? Praise? <a href="mailto:autologin@plaidweb.com">Tell me what you think</a>
</p>
</body>
</html>

+ 32
- 0
overlay.css View File

@ -0,0 +1,32 @@
div#AutoLoginOverlay {
position: absolute;
width: 100%;
height: 100%;
background: rgba(0,0,0,.75);
top: 0px;
left: 0px;
text-align: center;
margin: 0px;
padding: 0px;
}
div#AutoLoginOverlay h1, div#AutoLoginOverlay h2 {
text-align: center;
font-family: sans-serif;
color: white;
}
div#AutoLoginOverlay h1 {
font-size: 50px;
}
div#AutoLoginOverlay h2 {
font--size: 30px;
margin: auto;
margin-top: 20px;
width: 70px;
padding: 10px;
border-radius: 10px;
border: 2px solid white;
cursor: pointer;
}

BIN
overlay.png View File

Before After
Width: 256  |  Height: 256  |  Size: 34 KiB

+ 15
- 0
popup.html View File

@ -0,0 +1,15 @@
<html>
<head>
<style>
body {
width: 260px;
font-family: sans-serif;
}
</style>
</head>
<body>
<h2>Auto Login</h2>
<input type="button" value="Automatically log in when this page is visited" onclick="chrome.extension.getBackgroundPage().savePage();window.close();"/>
<p>You can undo this later in the options page.</p>
</body>
</html>

Loading…
Cancel
Save