diff --git a/check.js b/check.js index c73741d..b9e5a37 100755 --- a/check.js +++ b/check.js @@ -12,6 +12,8 @@ chrome.extension.onMessage.addListener( var rpBox; var blacklist = request.options.blacklist; blacklist = blacklist.split("\n"); + var protocols = request.options.protocols; + protocols = protocols.split("\n"); var cacheType = request.options.cache; var checkType = request.options.checkType; var optURL = request.options.optionsURL; @@ -27,7 +29,7 @@ chrome.extension.onMessage.addListener( for (var i = 0; i < pageLinks.length; i++){ var link = pageLinks[i]; var isValidLink = false; - isValidLink = isLinkValid(link,request,blacklist); + isValidLink = isLinkValid(link,request,blacklist,protocols); if(isValidLink === true){ queued += 1; link.classList.add("CMY_Link"); diff --git a/css/options_style.css b/css/options_style.css index 3ec2153..4148df7 100644 --- a/css/options_style.css +++ b/css/options_style.css @@ -77,6 +77,11 @@ p{ height: 200px; } +#protocolEntries{ + width: 500px; + height: 200px; +} + #logo{ background: -webkit-gradient(linear, center top, center bottom, from(white), to(#EEE)); padding: 15px 0px 10px 10px; diff --git a/functions.js b/functions.js index b8b277b..4271eaa 100644 --- a/functions.js +++ b/functions.js @@ -34,32 +34,47 @@ function removeDOMElement(id){ } } -function isLinkValid(link,request,blacklist){ +function isLinkValid(link,request,blacklist,protocols){ var url = link.href; var rel = link.rel; + var urlProtocol = link.protocol; + var protocolPermitted = false; var blacklisted = false; + if (url.startsWith('chrome-extension://')){ return false; } - else if ((request.nf == 'false' && rel == "nofollow") || (url.startsWith('http') === false && url.length !== 0)){ - console.log("Skipped: " + url); - return false; + + if ((request.options.noFollow == 'false' && rel == "nofollow") || (url.length === 0)){ + return false; } - else{ - for (var b = 0; b < blacklist.length; b++) - { - if (blacklist[b] !== "" && url.contains(blacklist[b])){ - blacklisted = true; - } + + for (var b = 0; b < protocols.length; b++) { + if (protocols[b] !== "" + && (!urlProtocol.contains( + protocols[b].substr(0, protocols[b].length -1)) + ) + ){ + protocolPermitted = true; } + } - if (blacklisted === true){ - console.log("Skipped (blacklisted): " + url); - return false; + if (protocolPermitted === false) { + return false; + } + + for (var b = 0; b < blacklist.length; b++) + { + if (blacklist[b] !== "" && url.contains(blacklist[b])){ + blacklisted = true; } - return true; } - return false; + + if (blacklisted === true){ + return false; + } + + return true; } function clearDisplay(){ @@ -360,6 +375,10 @@ function getOption(key){ "googlesyndication.com\n" + "adservices.google.com\n" + "appliedsemantics.com", + protocols: "http\n" + + "https\n" + + "ftp\n" + + "file", checkType: "GET", cache: "false", noFollow: "false", @@ -396,6 +415,7 @@ function log(txt) { function getOptions(){ var options = {}; options.blacklist = getOption("blacklist"); + options.protocols = getOption("protocols"); options.checkType = getOption("checkType"); options.cache = getOption("cache"); options.noFollow = getOption("noFollow"); diff --git a/options.html b/options.html index fbf8fe8..c8aead0 100755 --- a/options.html +++ b/options.html @@ -14,6 +14,13 @@

Check My Links: Options


+

Only links with following protocols will be checked, please enter all protocols in the whitelist below. Each protocol must be entered on a new line.

+ + +
+ +
+ diff --git a/options.js b/options.js index d11c23d..c924783 100755 --- a/options.js +++ b/options.js @@ -34,6 +34,9 @@ function loadOptions() { } document.getElementById("blacklistEntries").value = options.blacklist.split(" "); + + document.getElementById("protocolEntries").value = options.protocols.split(" "); + var requestType = document.getElementById("requestType"); for (var i = 0; i < requestType.children.length; i++) { @@ -49,10 +52,12 @@ function loadOptions() { function saveOptions() { var bkg = chrome.runtime.getBackgroundPage(function(bkg){ var blacklistEntries = document.getElementById("blacklistEntries"); + var protocolEntries = document.getElementById("protocolEntries"); var requestType = document.getElementById("requestType"); // Save selected options to localstore bkg.setItem("blacklist", blacklistEntries.value); + bkg.setItem("protocols", protocolEntries.value); bkg.setItem("checkType", requestType.children[requestType.selectedIndex].value); if(document.getElementById("cache").checked){bkg.setItem("cache", 'true');}else{bkg.setItem("cache", 'false');}