Browse files

Added options page and exclusion list.

  • Loading branch information...
1 parent fd484fc commit fae1850ed194e4ba3b2dd2ebee9a92c1e8cb400f @ocodia committed Feb 2, 2012
Showing with 264 additions and 19 deletions.
  1. +65 −2 background.html
  2. +14 −16 check.js
  3. BIN icon.png
  4. +2 −1 manifest.json
  5. +142 −0 options.html
  6. +41 −0 options.js
  7. BIN weeicon.png
View
67 background.html
@@ -1,12 +1,31 @@
<html>
<head>
<script type="text/javascript">
+
+ var logging = true;
chrome.extension.onRequest.addListener(onRequest);
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.getSelected(null, function (tab) {
- chrome.tabs.sendRequest(tab.id, {}, function (response) {});
+
+ var blacklistDefaults =
+ "googleleads.g.doubleclick.net\n" +
+ "doubleclick.net\n" +
+ "googleadservices.com\n" +
+ "www.googleadservices.com\n" +
+ "googlesyndication.com\n" +
+ "adservices.google.com\n" +
+ "appliedsemantics.com";
+
+ // Set up the defaults if no values are present in LocalStorage
+ if (getItem("blacklist") === null) {
+ setItem("blacklist", blacklistDefaults);
+ }
+ var blacklist = getItem("blacklist");
+
+ chrome.tabs.sendRequest(tab.id, {bl:blacklist}, function (response) {
+ });
});
});
@@ -18,6 +37,7 @@
}
}
+ // Timeout for each link is 60+1 seconds
var timeout = 30000;
function check(url, callback) {
@@ -41,7 +61,50 @@
XMLHttpTimeout=setTimeout(function (){return callback(408); xhr.abort();}, timeout += 1000);
}
+ // OPTIONS: Management
+
+ // OPTIONS: Set items in localstore
+ function setItem(key, value) {
+ try {
+ log("Inside setItem:" + key + ":" + value);
+ window.localStorage.removeItem(key);
+ window.localStorage.setItem(key, value);
+ }catch(e) {
+ log("Error inside setItem");
+ log(e);
+ }
+ log("Return from setItem" + key + ":" + value);
+ }
+
+ // OPTIONS: Get items from localstore
+ function getItem(key) {
+ var value;
+ log('Get Item:' + key);
+ try {
+ value = window.localStorage.getItem(key);
+ }catch(e) {
+ log("Error inside getItem() for key:" + key);
+ log(e);
+ value = "null";
+ }
+ log("Returning value: " + value);
+ return value;
+ }
+
+ // OPTIONS: Zap all items in localstore
+ function clearStrg() {
+ log('about to clear local storage');
+ window.localStorage.clear();
+ log('cleared');
+ }
+
+ function log(txt) {
+ if(logging) {
+ console.log(txt);
+ }
+ }
+
</script>
</head>
<body></body>
-</html>
+</html>
View
30 check.js
@@ -23,9 +23,15 @@ chrome.extension.onRequest.addListener(
var passed = 0;
var rpBox;
+
(
function(pg){
+ var blacklist = request.bl;
+ blacklist = blacklist.split("\n");
+
+ var blacklisted;
+
// Inject Styles and Elements for feedback report
var reportStyle = document.createElement("style");
@@ -92,17 +98,6 @@ chrome.extension.onRequest.addListener(
rpBoxQueue.innerHTML = "Queue: 0";
rpBoxPass.innerHTML = "0";
rpBoxFail.innerHTML = "0";
-
- var blacklist = [
- "googleleads.g.doubleclick.net",
- "doubleclick.net",
- "googleadservices.com",
- "googlesyndication.com",
- "adservices.google.com",
- "appliedsemantics.com"
- ];
-
- var blacklisted;
// Run through links, add feedback classes and ignore empty href and non http* links
for (var i = 0; i < pg.length; i++){
@@ -112,27 +107,28 @@ chrome.extension.onRequest.addListener(
var rel = link.rel;
blacklisted = false;
- if (url.length > 0 && url.startsWith('http') && rel != "nofollow"){
+ if (url.length > 0 && url.startsWith('http') && rel !== "nofollow"){
for (var b = 0; b < blacklist.length; b++)
{
- if (url.contains(blacklist[b])){
+ if (blacklist[b] !== "" && url.contains(blacklist[b])){
blacklisted = true;
}
}
if (blacklisted === true){
- console.log("Skipping Adsense links");
+ console.log("Skipped (blacklisted): " + url);
totalvalid -=1;
}
else{
queued +=1;
link.classList.add("CMY_Link");
checkURL(url, link);
+ //console.log("Checking:" + url);
}
}
else{
- console.log("Skipping non-links (rel: nofollow or not http/https)");
+ console.log("Skipped: " + url);
totalvalid -=1;
}
}
@@ -171,4 +167,6 @@ chrome.extension.onRequest.addListener(
sendResponse({});
- });
+ });
+
+
View
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 manifest.json
@@ -1,4 +1,5 @@
{
+ "options_page": "options.html",
"background_page": "background.html",
"browser_action": {
"default_icon": "weeicon.png",
@@ -13,5 +14,5 @@
"icons": { "128": "icon.png" },
"name": "Check My Links",
"permissions": [ "tabs", "http://*/*", "https://*/*" ],
- "version": "2.3.3"
+ "version": "3.0"
}
View
142 options.html
@@ -0,0 +1,142 @@
+<html>
+<head>
+ <title>Check My Links: Options</title>
+ <script type="text/javascript" src="options.js"></script>
+ <style rel="stylesheet" type="text/css">
+ body{
+ background-color:#eee;
+ font-family:arial,sans-serif;
+ font-size:13px
+ }
+
+ #content{
+ background-color: white;
+ border: 1px solid #DDD;
+ margin: 40px auto 20px;
+ padding: 12px;
+ width: 500px;
+ -webkit-border-radius: 12px;
+ box-shadow: 0px 0px 10px #ddd;
+ }
+
+ h1{
+ color:#333333;
+ font-size:1.5em;
+ margin:0.7em 0 0;
+ }
+
+
+ p{
+ font-size: 12px;
+ }
+
+ .buttons{
+ clear:left;
+ padding:5px;
+ text-align: center;
+ }
+
+ #save_status{
+ background-color:#fff1a8;
+ font-weight:bold;
+ margin-left:10px;
+ opacity:0;
+ padding:3px;
+ -webkit-border-radius:3px
+ }
+
+ .footer{
+ text-align:center;
+ margin-top:0.4em;
+ color: rgba(0,0,0,0.2);
+ }
+
+ .footer a{
+ color: #333;
+ text-shadow: 1px 1px 1px white;
+ text-decoration: none;
+ border: 1px solid #ddd;
+ padding: 5px;
+ background: -webkit-gradient(linear, center top, center bottom, from(white), to(#fafafa));
+ border-radius: 5px;
+ }
+
+ .footer a:hover{
+ color: #111;
+ text-shadow: 1px 1px 1px white;
+ text-decoration: underline;
+ }
+
+ #msg{
+ background: #090;
+ border-radius: 5px 5px;
+ color: #fff;
+ font-weight: bold;
+ padding: 5px;
+ text-align: center;
+ }
+
+ #blacklistEntries{
+ width: 500px;
+ height: 200px;
+ }
+
+ #logo{
+ background: -webkit-gradient(linear, center top, center bottom, from(white), to(#EEE));
+ padding: 15px 0px 10px 10px;
+ height: 30px;
+ border-bottom: 1px solid #DDD;
+ margin: -12px -12px 20px -12px;
+ border-top-left-radius: 10px;
+ border-top-right-radius: 10px;
+ text-shadow: 1px 1px 1px white;
+ color: #666;
+ }
+
+ span{
+ font-family: monospace;
+ background: #D9EDF7;
+ padding: 3px;
+ color: #3A87AD;
+ border-radius: 5px;
+ }
+
+ label{
+ font-weight: bold;
+ }
+
+ #support{
+ margin: 0px -12px -12px -12px;
+ background: whitef;
+ padding: 0px 10px;
+ border-bottom-left-radius: 10px;
+ border-bottom-right-radius: 10px;
+ border-top: 1px dashed #DDD;
+
+ }
+ </style>
+
+</head>
+<body onload="loadOptions()">
+<div id="content">
+ <h1 id="logo">Check My Links: Options</h1>
+<p>To prevent this extension from checking a link, please enter all or part of the URL in the blacklist below. Each URL must be entered on a new line.</p>
+<p style="line-height: 26px">For example: <span>www.mydomain.com</span> will prevent the following links from being checked: <span>www.mydomain.com/page1.html</span> or <span>www.mydomain.com/page2.html</span></p>
+<label for="blacklistEntries">Exclude links from these domains:</label><br/>
+ <textarea name="blacklistEntries" id="blacklistEntries" rows="2" cols="20"></textarea>
+
+
+ <div class="buttons">
+
+ <button onclick="saveOptions()">Save my preferences</button></div>
+ <div id="msg" style="visibility: hidden;">Preferences Saved!</div>
+
+ <div id="support">
+ <p>Support this extension by contributing towards it's upkeep: </p><p><a href="http://flattr.com/thing/474052/Check-My-Links" target="_blank">
+<img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a></p>
+</div>
+ </div>
+
+ <div class="footer"><a href="http://ocodia.com">By Paul Livingstone</a> - <a href="http://twitter.com/ocodia">@ocodia</a> - <a href="https://github.com/ocodia/Check-My-Links/wiki">Wiki</a> - <a href="https://github.com/ocodia/Check-My-Links/issues">Report an issue</a> - <a href="https://github.com/ocodia/Check-My-Links">Fork me on Github</a></div>
+</body>
+</html>
View
41 options.js
@@ -0,0 +1,41 @@
+// Check My Links
+// Paul Livingstone
+// 2012
+
+var blacklistDefaults =
+ "googleleads.g.doubleclick.net\n" +
+ "doubleclick.net\n" +
+ "googleadservices.com\n" +
+ "www.googleadservices.com\n" +
+ "googlesyndication.com\n" +
+ "adservices.google.com\n" +
+ "appliedsemantics.com";
+
+function loadOptions() {
+
+ // Load up the background page
+ var bkg = chrome.extension.getBackgroundPage();
+
+ var blacklistItems = bkg.getItem("blacklist");
+
+ // Set up the defaults if no values are present in LocalStorage
+ if (blacklistItems === null) {
+ bkg.setItem("blacklist", blacklistDefaults);
+ }
+
+ blacklistItems = bkg.getItem("blacklist");
+ blacklistItems.split(" ");
+
+ document.getElementById("blacklistEntries").value = blacklistItems;
+
+}
+
+function saveOptions() {
+ var bkg = chrome.extension.getBackgroundPage();
+ var blacklistEntries = document.getElementById("blacklistEntries");
+
+ // Save selected options to localstore
+ bkg.setItem("blacklist", blacklistEntries.value);
+ document.getElementById("msg").style.visibility = "visible";
+}
+
View
BIN weeicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fae1850

Please sign in to comment.