Skip to content
This repository
Browse code

Added options page and exclusion list.

  • Loading branch information...
commit fae1850ed194e4ba3b2dd2ebee9a92c1e8cb400f 1 parent fd484fc
Paul Livingstone authored
67 background.html
... ... @@ -1,12 +1,31 @@
1 1 <html>
2 2 <head>
3 3 <script type="text/javascript">
  4 +
  5 + var logging = true;
4 6
5 7 chrome.extension.onRequest.addListener(onRequest);
6 8
7 9 chrome.browserAction.onClicked.addListener(function (tab) {
8 10 chrome.tabs.getSelected(null, function (tab) {
9   - chrome.tabs.sendRequest(tab.id, {}, function (response) {});
  11 +
  12 + var blacklistDefaults =
  13 + "googleleads.g.doubleclick.net\n" +
  14 + "doubleclick.net\n" +
  15 + "googleadservices.com\n" +
  16 + "www.googleadservices.com\n" +
  17 + "googlesyndication.com\n" +
  18 + "adservices.google.com\n" +
  19 + "appliedsemantics.com";
  20 +
  21 + // Set up the defaults if no values are present in LocalStorage
  22 + if (getItem("blacklist") === null) {
  23 + setItem("blacklist", blacklistDefaults);
  24 + }
  25 + var blacklist = getItem("blacklist");
  26 +
  27 + chrome.tabs.sendRequest(tab.id, {bl:blacklist}, function (response) {
  28 + });
10 29 });
11 30 });
12 31
@@ -18,6 +37,7 @@
18 37 }
19 38 }
20 39
  40 + // Timeout for each link is 60+1 seconds
21 41 var timeout = 30000;
22 42
23 43 function check(url, callback) {
@@ -41,7 +61,50 @@
41 61 XMLHttpTimeout=setTimeout(function (){return callback(408); xhr.abort();}, timeout += 1000);
42 62 }
43 63
  64 + // OPTIONS: Management
  65 +
  66 + // OPTIONS: Set items in localstore
  67 + function setItem(key, value) {
  68 + try {
  69 + log("Inside setItem:" + key + ":" + value);
  70 + window.localStorage.removeItem(key);
  71 + window.localStorage.setItem(key, value);
  72 + }catch(e) {
  73 + log("Error inside setItem");
  74 + log(e);
  75 + }
  76 + log("Return from setItem" + key + ":" + value);
  77 + }
  78 +
  79 + // OPTIONS: Get items from localstore
  80 + function getItem(key) {
  81 + var value;
  82 + log('Get Item:' + key);
  83 + try {
  84 + value = window.localStorage.getItem(key);
  85 + }catch(e) {
  86 + log("Error inside getItem() for key:" + key);
  87 + log(e);
  88 + value = "null";
  89 + }
  90 + log("Returning value: " + value);
  91 + return value;
  92 + }
  93 +
  94 + // OPTIONS: Zap all items in localstore
  95 + function clearStrg() {
  96 + log('about to clear local storage');
  97 + window.localStorage.clear();
  98 + log('cleared');
  99 + }
  100 +
  101 + function log(txt) {
  102 + if(logging) {
  103 + console.log(txt);
  104 + }
  105 + }
  106 +
44 107 </script>
45 108 </head>
46 109 <body></body>
47   -</html>
  110 +</html>
30 check.js
@@ -23,9 +23,15 @@ chrome.extension.onRequest.addListener(
23 23 var passed = 0;
24 24 var rpBox;
25 25
  26 +
26 27 (
27 28 function(pg){
28 29
  30 + var blacklist = request.bl;
  31 + blacklist = blacklist.split("\n");
  32 +
  33 + var blacklisted;
  34 +
29 35 // Inject Styles and Elements for feedback report
30 36
31 37 var reportStyle = document.createElement("style");
@@ -92,17 +98,6 @@ chrome.extension.onRequest.addListener(
92 98 rpBoxQueue.innerHTML = "Queue: 0";
93 99 rpBoxPass.innerHTML = "0";
94 100 rpBoxFail.innerHTML = "0";
95   -
96   - var blacklist = [
97   - "googleleads.g.doubleclick.net",
98   - "doubleclick.net",
99   - "googleadservices.com",
100   - "googlesyndication.com",
101   - "adservices.google.com",
102   - "appliedsemantics.com"
103   - ];
104   -
105   - var blacklisted;
106 101
107 102 // Run through links, add feedback classes and ignore empty href and non http* links
108 103 for (var i = 0; i < pg.length; i++){
@@ -112,27 +107,28 @@ chrome.extension.onRequest.addListener(
112 107 var rel = link.rel;
113 108 blacklisted = false;
114 109
115   - if (url.length > 0 && url.startsWith('http') && rel != "nofollow"){
  110 + if (url.length > 0 && url.startsWith('http') && rel !== "nofollow"){
116 111 for (var b = 0; b < blacklist.length; b++)
117 112 {
118   - if (url.contains(blacklist[b])){
  113 + if (blacklist[b] !== "" && url.contains(blacklist[b])){
119 114 blacklisted = true;
120 115 }
121 116 }
122 117
123 118 if (blacklisted === true){
124   - console.log("Skipping Adsense links");
  119 + console.log("Skipped (blacklisted): " + url);
125 120 totalvalid -=1;
126 121 }
127 122 else{
128 123 queued +=1;
129 124 link.classList.add("CMY_Link");
130 125 checkURL(url, link);
  126 + //console.log("Checking:" + url);
131 127 }
132 128
133 129 }
134 130 else{
135   - console.log("Skipping non-links (rel: nofollow or not http/https)");
  131 + console.log("Skipped: " + url);
136 132 totalvalid -=1;
137 133 }
138 134 }
@@ -171,4 +167,6 @@ chrome.extension.onRequest.addListener(
171 167
172 168 sendResponse({});
173 169
174   - });
  170 + });
  171 +
  172 +
BIN  icon.png
3  manifest.json
... ... @@ -1,4 +1,5 @@
1 1 {
  2 + "options_page": "options.html",
2 3 "background_page": "background.html",
3 4 "browser_action": {
4 5 "default_icon": "weeicon.png",
@@ -13,5 +14,5 @@
13 14 "icons": { "128": "icon.png" },
14 15 "name": "Check My Links",
15 16 "permissions": [ "tabs", "http://*/*", "https://*/*" ],
16   - "version": "2.3.3"
  17 + "version": "3.0"
17 18 }
142 options.html
... ... @@ -0,0 +1,142 @@
  1 +<html>
  2 +<head>
  3 + <title>Check My Links: Options</title>
  4 + <script type="text/javascript" src="options.js"></script>
  5 + <style rel="stylesheet" type="text/css">
  6 + body{
  7 + background-color:#eee;
  8 + font-family:arial,sans-serif;
  9 + font-size:13px
  10 + }
  11 +
  12 + #content{
  13 + background-color: white;
  14 + border: 1px solid #DDD;
  15 + margin: 40px auto 20px;
  16 + padding: 12px;
  17 + width: 500px;
  18 + -webkit-border-radius: 12px;
  19 + box-shadow: 0px 0px 10px #ddd;
  20 + }
  21 +
  22 + h1{
  23 + color:#333333;
  24 + font-size:1.5em;
  25 + margin:0.7em 0 0;
  26 + }
  27 +
  28 +
  29 + p{
  30 + font-size: 12px;
  31 + }
  32 +
  33 + .buttons{
  34 + clear:left;
  35 + padding:5px;
  36 + text-align: center;
  37 + }
  38 +
  39 + #save_status{
  40 + background-color:#fff1a8;
  41 + font-weight:bold;
  42 + margin-left:10px;
  43 + opacity:0;
  44 + padding:3px;
  45 + -webkit-border-radius:3px
  46 + }
  47 +
  48 + .footer{
  49 + text-align:center;
  50 + margin-top:0.4em;
  51 + color: rgba(0,0,0,0.2);
  52 + }
  53 +
  54 + .footer a{
  55 + color: #333;
  56 + text-shadow: 1px 1px 1px white;
  57 + text-decoration: none;
  58 + border: 1px solid #ddd;
  59 + padding: 5px;
  60 + background: -webkit-gradient(linear, center top, center bottom, from(white), to(#fafafa));
  61 + border-radius: 5px;
  62 + }
  63 +
  64 + .footer a:hover{
  65 + color: #111;
  66 + text-shadow: 1px 1px 1px white;
  67 + text-decoration: underline;
  68 + }
  69 +
  70 + #msg{
  71 + background: #090;
  72 + border-radius: 5px 5px;
  73 + color: #fff;
  74 + font-weight: bold;
  75 + padding: 5px;
  76 + text-align: center;
  77 + }
  78 +
  79 + #blacklistEntries{
  80 + width: 500px;
  81 + height: 200px;
  82 + }
  83 +
  84 + #logo{
  85 + background: -webkit-gradient(linear, center top, center bottom, from(white), to(#EEE));
  86 + padding: 15px 0px 10px 10px;
  87 + height: 30px;
  88 + border-bottom: 1px solid #DDD;
  89 + margin: -12px -12px 20px -12px;
  90 + border-top-left-radius: 10px;
  91 + border-top-right-radius: 10px;
  92 + text-shadow: 1px 1px 1px white;
  93 + color: #666;
  94 + }
  95 +
  96 + span{
  97 + font-family: monospace;
  98 + background: #D9EDF7;
  99 + padding: 3px;
  100 + color: #3A87AD;
  101 + border-radius: 5px;
  102 + }
  103 +
  104 + label{
  105 + font-weight: bold;
  106 + }
  107 +
  108 + #support{
  109 + margin: 0px -12px -12px -12px;
  110 + background: whitef;
  111 + padding: 0px 10px;
  112 + border-bottom-left-radius: 10px;
  113 + border-bottom-right-radius: 10px;
  114 + border-top: 1px dashed #DDD;
  115 +
  116 + }
  117 + </style>
  118 +
  119 +</head>
  120 +<body onload="loadOptions()">
  121 +<div id="content">
  122 + <h1 id="logo">Check My Links: Options</h1>
  123 +<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>
  124 +<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>
  125 +<label for="blacklistEntries">Exclude links from these domains:</label><br/>
  126 + <textarea name="blacklistEntries" id="blacklistEntries" rows="2" cols="20"></textarea>
  127 +
  128 +
  129 + <div class="buttons">
  130 +
  131 + <button onclick="saveOptions()">Save my preferences</button></div>
  132 + <div id="msg" style="visibility: hidden;">Preferences Saved!</div>
  133 +
  134 + <div id="support">
  135 + <p>Support this extension by contributing towards it's upkeep: </p><p><a href="http://flattr.com/thing/474052/Check-My-Links" target="_blank">
  136 +<img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a></p>
  137 +</div>
  138 + </div>
  139 +
  140 + <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>
  141 +</body>
  142 +</html>
41 options.js
... ... @@ -0,0 +1,41 @@
  1 +// Check My Links
  2 +// Paul Livingstone
  3 +// 2012
  4 +
  5 +var blacklistDefaults =
  6 + "googleleads.g.doubleclick.net\n" +
  7 + "doubleclick.net\n" +
  8 + "googleadservices.com\n" +
  9 + "www.googleadservices.com\n" +
  10 + "googlesyndication.com\n" +
  11 + "adservices.google.com\n" +
  12 + "appliedsemantics.com";
  13 +
  14 +function loadOptions() {
  15 +
  16 + // Load up the background page
  17 + var bkg = chrome.extension.getBackgroundPage();
  18 +
  19 + var blacklistItems = bkg.getItem("blacklist");
  20 +
  21 + // Set up the defaults if no values are present in LocalStorage
  22 + if (blacklistItems === null) {
  23 + bkg.setItem("blacklist", blacklistDefaults);
  24 + }
  25 +
  26 + blacklistItems = bkg.getItem("blacklist");
  27 + blacklistItems.split(" ");
  28 +
  29 + document.getElementById("blacklistEntries").value = blacklistItems;
  30 +
  31 +}
  32 +
  33 +function saveOptions() {
  34 + var bkg = chrome.extension.getBackgroundPage();
  35 + var blacklistEntries = document.getElementById("blacklistEntries");
  36 +
  37 + // Save selected options to localstore
  38 + bkg.setItem("blacklist", blacklistEntries.value);
  39 + document.getElementById("msg").style.visibility = "visible";
  40 +}
  41 +
BIN  weeicon.png

0 comments on commit fae1850

Please sign in to comment.
Something went wrong with that request. Please try again.