Skip to content

Commit

Permalink
Fix for #4 and #15
Browse files Browse the repository at this point in the history
  • Loading branch information
andryou committed Jun 5, 2016
1 parent 6c0d79e commit 44357fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 7 additions & 1 deletion js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ function getDomain(url, type) {
return url;
}
function in_array(needle, haystack) {
if (haystack && new RegExp(haystack).test(needle)) return '1';
if (!haystack || !needle) return false;
for (var i in haystack) {
if (new RegExp('(?:www\\.|^)(?:'+haystack[i].replace(/\./g, '\\.').replace(/^\[/g, '$1\\[').replace(/\]$/g, '\\]').replace(/\?/g, '.').replace(/\*\*\\./g, '(?:.+\\.|^)').replace(/\*/g, '[^.]+')+')').test(needle)) {
return '1';
break;
}
}
return false;
}
// Js-BinarySearch by amgadfahmi
Expand Down
2 changes: 1 addition & 1 deletion js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function truncate(str, len) {
return str;
}
document.addEventListener('DOMContentLoaded', function () {
setTimeout(init, 25);
setTimeout(init, 0);
$("#pop_ay").click(function() { openTab('https://twitter.com/andryou'); });
$("#pop_docs").click(function() { openTab('https://github.com/andryou/scriptsafe/wiki'); });
$("#pop_project").click(function() { openTab('https://github.com/andryou/scriptsafe'); });
Expand Down
16 changes: 6 additions & 10 deletions js/scriptsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ function domainHandler(domain,action,listtype) {
} else if (listtype == 1) {
sessionStorage['whiteList'] = JSON.stringify(tempWhitelist);
sessionStorage['blackList'] = JSON.stringify(tempBlacklist);
sessionWhiteList = regexify(tempWhitelist);
sessionBlackList = regexify(tempBlacklist);
sessionWhiteList = tempWhitelist;
sessionBlackList = tempBlacklist;
}
return true;
}
Expand Down Expand Up @@ -828,21 +828,17 @@ function cacheLists() {
if (domain.substr(0,3) == '**.') tempWildDomain.push(domain);
tempDomain.push(domain);
});
whiteList = regexify(tempDomain);
trustList = regexify(tempWildDomain);
whiteList = tempDomain;
trustList = tempWildDomain;
tempList = JSON.parse(localStorage['blackList']);
tempDomain = [];
tempWildDomain = [];
tempList.map(function(domain) {
if (domain.substr(0,3) == '**.') tempWildDomain.push(domain);
tempDomain.push(domain);
});
blackList = regexify(tempDomain);
distrustList = regexify(tempWildDomain);
}
function regexify(arr) {
if (arr.length == 0) return '';
return '(?:www\\.|^)(?:'+arr.join('|').replace(/\./g, '\\.').replace(/(\||^)\[/g, '$1\\[').replace(/\](?:\\||$)/g, '\\]').replace(/\?/g, '.').replace(/\*\*\\./g, '(?:.+\\.|^)').replace(/\*/g, '[^.]+')+')';
blackList = tempDomain;
distrustList = tempWildDomain;
}
if (!optionExists("version") || localStorage["version"] != version) {
// One-time update existing whitelist/blacklist for new regex support introduced in v1.0.7.0
Expand Down

0 comments on commit 44357fa

Please sign in to comment.