Browse Source

working copy

master
Lennart Weller 7 years ago
parent
commit
9a27d48afa
11 changed files with 184 additions and 140 deletions
  1. +70
    -0
      background.js
  2. +7
    -2
      contentScript.js
  3. +0
    -46
      contentScript.js.old
  4. BIN
      icon128.png
  5. BIN
      icon19.png
  6. BIN
      icon48.png
  7. +31
    -24
      manifest.json
  8. +6
    -65
      options.html
  9. +63
    -0
      options.js
  10. +3
    -3
      popup.html
  11. +4
    -0
      popup.js

+ 70
- 0
background.js View File

@ -0,0 +1,70 @@
// 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.runtime.onMessage.addListener(
function(request,sender,sendResponse) {
if(request.showIcon) chrome.pageAction.show(sender.tab.id);
if(request.save) savePage();
}
);
// 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});
});
}

+ 7
- 2
contentScript.js View File

@ -118,6 +118,11 @@ chrome.extension.onRequest.addListener(
}
);
var _waitForAutofill = window.setInterval(function() {
if(document.readyState == "complete") {
input = findFirstFilledOutPasswordInput()
chrome.runtime.sendMessage({showIcon: (input != false)});
window.clearInterval(_waitForAutofill);
}
}, 20);
// Check if the "page action" icon should be displayed
input = findFirstFilledOutPasswordInput()
chrome.extension.sendRequest({showIcon: (input != false)});

+ 0
- 46
contentScript.js.old View File

@ -1,46 +0,0 @@
// 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 Width: 128  |  Height: 128  |  Size: 13 KiB

BIN
icon19.png View File

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

BIN
icon48.png View File

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

+ 31
- 24
manifest.json View File

@ -1,24 +1,31 @@
{
"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"
}
{
"background": {
"scripts": ["background.js"]
},
"content_scripts": [ {
"css": [ "overlay.css" ],
"js": [ "contentScript.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_idle"
} ],
"description": "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": {
"19": "icon19.png",
"48": "icon48.png",
"128": "icon128.png"
},
"default_title": "Log in to this page automatically.",
"default_popup": "popup.html"
},
"permissions": [ "tabs" ],
"version": "1.6.0",
"manifest_version": 2
}

+ 6
- 65
options.html View File

@ -49,76 +49,16 @@ table {
</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>
(only active if message is displayed)&nbsp; <input type="text" name="wait" value="0" size="2"></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>
<div id="pages">
</div>
<p>&nbsp;</p>
<p class="center">
<b>Note:</b> your password must be saved by the browser to be automatically logged in.
@ -130,4 +70,5 @@ else
Bugs? Feature requests? Praise? <a href="mailto:autologin@plaidweb.com">Tell me what you think</a>
</p>
</body>
</html>
<script src="options.js"></script>
</html>

+ 63
- 0
options.js View File

@ -0,0 +1,63 @@
window.onunload = function() {
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);
}
}
function removePage(index) {
localStorage.removeItem(localStorage.key(index));
pages = document.getElementsByTagName("tr")
for(i = 0; i < pages.length; ++i)
if(pages[i].dataset.index)
pages[i].parentNode.removeChild(pages[i])
}
// 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;
pages = document.getElementById("pages")
if(localStorage.length < 2) {
pages.innerHTML += '<p style="font-weight:bold">No sites are set for auto login yet.</p>';
pages.innerHTML += '<p>To add a site, navigate to the login page of a site which Chrome has saved the password for ';
pages.innerHTML += 'and click the Auto Login icon that will appear next to the site\'s URL';
} else {
table = document.createElement("table");
table.setAttribute("border", 1);
table.setAttribute("cellspacing", 0);
table.setAttribute("cellpadding", 3);
table.innerHTML += '<tr><th>Remove</th><th>Page Title</th><th>Page URL</th></tr>';
for(i = 0; i < localStorage.length; ++i)
{
if(localStorage.key(i) == 'options')
continue;
tr = document.createElement("tr");
tr.setAttribute("data-index", i);
tr.innerHTML += '<td align="center"><a class="delete" data-key="'+i+'" href="#">X</a></td>'
tr.innerHTML += '<td><small class="title">' + localStorage.getItem(localStorage.key(i)) + '</small></td>'
tr.innerHTML += '<td><input class="url" value="' + localStorage.key(i) + '"/></td>'
table.appendChild(tr);
}
pages.appendChild(table);
deleteLinks = document.getElementsByClassName("delete")
for(i = 0; i < deleteLinks.length; ++i) {
deleteLinks[i].addEventListener("click", function(e) {
removePage(e.target.dataset.key);
});
}
}

+ 3
- 3
popup.html View File

@ -9,7 +9,7 @@
</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>
<button id="savePage">Automatically log in on this site</button>
</body>
</html>
<script src="popup.js"></script>
</html>

+ 4
- 0
popup.js View File

@ -0,0 +1,4 @@
document.getElementById("savePage").addEventListener("click", function() {
chrome.runtime.sendMessage({save: true});
window.close();
});

Loading…
Cancel
Save