Skip to content

Commit

Permalink
Added HTTP Request Type options (GET or HEAD)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocodia committed Nov 23, 2012
1 parent 34b7161 commit 102c5ae
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
11 changes: 10 additions & 1 deletion background.js
@@ -1,4 +1,5 @@
var logging = false;
var checkType;

chrome.extension.onMessage.addListener(onRequest);

Expand All @@ -13,12 +14,20 @@ chrome.browserAction.onClicked.addListener(function (tab) {
"adservices.google.com\n" +
"appliedsemantics.com";

var checkTypeDefault = "HEAD";

// Set up the defaults if no values are present in LocalStorage
if (getItem("blacklist") === null) {
setItem("blacklist", blacklistDefaults);
}

if(getItem("checkType") == null){
setItem("checkType", checkTypeDefault);
}


var blacklist = getItem("blacklist");
checkType = getItem("checkType");

chrome.tabs.sendMessage(tab.id, {bl:blacklist});
});
Expand Down Expand Up @@ -47,7 +56,7 @@ function check(url, callback) {
};

try {
xhr.open("HEAD", url, true);
xhr.open(checkType, url, true);
xhr.send();
}
catch(e){
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -8,7 +8,7 @@
"icons": { "128": "icon.png" },
"name": "Check My Links",
"permissions": [ "tabs", "http://*/*", "https://*/*" ],
"version": "3.1.2",
"version": "3.2",
"manifest_version": 2,
"background": { "scripts": ["background.js"] }
}
34 changes: 34 additions & 0 deletions options.html
Expand Up @@ -115,6 +115,27 @@
border-top: 1px dashed #DDD;

}


.option_row{
clear:left;
}

.option_name{
float:left;
font-weight:bold;
margin-top:3px;
}

.option_picker{
float:left
}

hr{
border: 1px solid #EEE;
border-bottom: none;
margin: 10px 0px;
}
</style>

</head>
Expand All @@ -125,6 +146,19 @@ <h1 id="logo">Check My Links: Options</h1>
<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>
<hr/>
<div class="option_row">
<div class="option_name">
<label for="requestType">Request Type:</label> </div>
<div class="option_picker">
<select id="requestType">
<option value="HEAD">HEAD</option>
<option value="GET">GET</option>
</select>
</div>
</div>
<p style="clear:both;">HEAD is quicker, but sometimes doesn't reflect the true HTTP status of a page, switch to GET if you're getting weird results.</p>
<hr/>
<div class="buttons">
<button id="save">Save my preferences</button></div>
<div id="msg" style="visibility: hidden;">Preferences Saved!</div>
Expand Down
21 changes: 19 additions & 2 deletions options.js
Expand Up @@ -10,28 +10,45 @@ var blacklistDefaults =
"adservices.google.com\n" +
"appliedsemantics.com";

var checkTypeDefault = "HEAD";

function loadOptions() {

var bkg = chrome.extension.getBackgroundPage();
var blacklistItems = bkg.getItem("blacklist");
var checkTypeSelection = bkg.getItem("checkType");

if (blacklistItems === null) {
bkg.setItem("blacklist", blacklistDefaults);
}

blacklistItems = bkg.getItem("blacklist");
if (checkTypeSelection === null) {
bkg.setItem("checkType", checkTypeDefault);
}

//blacklistItems = bkg.getItem("blacklist");
blacklistItems.split(" ");

document.getElementById("blacklistEntries").value = blacklistItems;
var requestType = document.getElementById("requestType");

// Select the appropriate saved option for TRENDS
for (var i = 0; i < requestType.children.length; i++) {
var requestTypechild = requestType.children[i];
if (requestTypechild.value == checkTypeSelection) {
requestTypechild.selected = "true";
break;
}
}
}

function saveOptions() {
var bkg = chrome.extension.getBackgroundPage();
var blacklistEntries = document.getElementById("blacklistEntries");

var requestType = document.getElementById("requestType");
// Save selected options to localstore
bkg.setItem("blacklist", blacklistEntries.value);
bkg.setItem("checkType", requestType.children[requestType.selectedIndex].value);
document.getElementById("msg").style.visibility = "visible";
}

Expand Down

0 comments on commit 102c5ae

Please sign in to comment.