From 44357faff2b560a84602fdbbba22e03a98ca6a5c Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 5 Jun 2016 03:16:21 -0400 Subject: [PATCH] Fix for #4 and #15 --- js/common.js | 8 +++++++- js/popup.js | 2 +- js/scriptsafe.js | 16 ++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/js/common.js b/js/common.js index 4e1d18b..885e52c 100644 --- a/js/common.js +++ b/js/common.js @@ -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 diff --git a/js/popup.js b/js/popup.js index eaea6e0..5def710 100644 --- a/js/popup.js +++ b/js/popup.js @@ -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'); }); diff --git a/js/scriptsafe.js b/js/scriptsafe.js index df4fc48..2f6c743 100644 --- a/js/scriptsafe.js +++ b/js/scriptsafe.js @@ -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; } @@ -828,8 +828,8 @@ 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 = []; @@ -837,12 +837,8 @@ function cacheLists() { 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