From d6336bd92a26ccdd1270eedcfd21acaac570cad0 Mon Sep 17 00:00:00 2001 From: Libor Polčák Date: Jun 07 2019 14:39:31 +0000 Subject: content script: create URL module Improve code readability --- diff --git a/chrome_manifest/manifest.json b/chrome_manifest/manifest.json index 4f54d5e..6fb6829 100644 --- a/chrome_manifest/manifest.json +++ b/chrome_manifest/manifest.json @@ -21,7 +21,7 @@ "content_scripts": [ { "matches": [""], - "js": ["levels.js", "document_start.js"], + "js": ["levels.js", "url.js", "document_start.js"], "run_at": "document_start" } ], diff --git a/document_start.js b/document_start.js index 0b7ee06..56f010d 100644 --- a/document_start.js +++ b/document_start.js @@ -575,21 +575,3 @@ function createDNTWrappingFunctionString(selectOption) { } - -function extractRootDomain(thisDomain) { - // var thisDomain = extractHostname(thisUrl); - var splitArr = thisDomain.split('.'); - var arrLen = splitArr.length; - //extracting the root domain here - //if there is a subdomain - if (arrLen > 2) { - thisDomain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1]; - //check to see if it's using a Country Code Top Level Domain (ccTLD) (e.g. ".co.uk") - if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) { - //this is using a ccTLD - thisDomain = splitArr[arrLen - 3] + '.' + thisDomain; - } - } - return thisDomain; -} - diff --git a/firefox_manifest/manifest.json b/firefox_manifest/manifest.json index f357bbd..93a8ac3 100644 --- a/firefox_manifest/manifest.json +++ b/firefox_manifest/manifest.json @@ -21,7 +21,7 @@ "content_scripts": [ { "matches": [""], - "js": ["levels.js", "document_start.js"], + "js": ["levels.js", "url.js", "document_start.js"], "run_at": "document_start" } ], diff --git a/url.js b/url.js new file mode 100644 index 0000000..f5daf62 --- /dev/null +++ b/url.js @@ -0,0 +1,41 @@ +// +// JavaScript Restrictor is a browser extension which increases level +// of security, anonymity and privacy of the user while browsing the +// internet. +// +// Copyright (C) 2019 Libor Polcak +// Copyright (C) 2019 Martin Timko +// Copyright (C) 2018 Zbynek Cervinka +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + + +function extractRootDomain(thisDomain) { + // var thisDomain = extractHostname(thisUrl); + var splitArr = thisDomain.split('.'); + var arrLen = splitArr.length; + //extracting the root domain here + //if there is a subdomain + if (arrLen > 2) { + thisDomain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1]; + //check to see if it's using a Country Code Top Level Domain (ccTLD) (e.g. ".co.uk") + if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) { + //this is using a ccTLD + thisDomain = splitArr[arrLen - 3] + '.' + thisDomain; + } + } + return thisDomain; +} +