|
|
@@ -1,36 +1,7 @@
|
|
|
-import { fromUserSettings } from 'tldjs';
|
|
|
-import Trie from 'tldjs/lib/suffix-trie';
|
|
|
-import { request } from 'src/common';
|
|
|
+import tld from './tld';
|
|
|
import cache from './cache';
|
|
|
import { getOption, hookOptions } from './options';
|
|
|
|
|
|
-let tldjs;
|
|
|
-initTLD();
|
|
|
-
|
|
|
-function initTLD() {
|
|
|
- // TLD rules are too large to be packed, download them at runtime.
|
|
|
- const url = 'https://violentmonkey.top/static/tld-rules.json';
|
|
|
- const key = 'dat:tldRules';
|
|
|
- browser.storage.local.get(key)
|
|
|
- .then(({ [key]: tldRules }) => {
|
|
|
- if (tldRules) return tldRules;
|
|
|
- return request(url, { responseType: 'json' })
|
|
|
- .then(({ data: rules }) => {
|
|
|
- console.info('Downloaded public suffix data');
|
|
|
- return browser.storage.local.set({ [key]: rules })
|
|
|
- .then(() => rules);
|
|
|
- });
|
|
|
- })
|
|
|
- .then(tldRules => {
|
|
|
- console.info('Initialized TLD');
|
|
|
- tldjs = fromUserSettings({ rules: Trie.fromJson(tldRules) });
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- if (process.env.DEBUG) console.error(err);
|
|
|
- console.info('Failed initializing TLD');
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
const RE_MATCH_PARTS = /(.*?):\/\/([^/]*)\/(.*)/;
|
|
|
let blacklistRules = [];
|
|
|
hookOptions(changes => {
|
|
|
@@ -111,13 +82,13 @@ function autoReg(str) {
|
|
|
const tests = [
|
|
|
tstr => re.test(tstr),
|
|
|
];
|
|
|
- if (tldjs && str.includes('.tld/')) {
|
|
|
+ if (tld && str.includes('.tld/')) {
|
|
|
const reTldStr = reStr.replace('\\.tld/', '((?:\\.\\w+)+)/');
|
|
|
tests.push(tstr => {
|
|
|
const matches = tstr.match(reTldStr);
|
|
|
if (matches) {
|
|
|
const suffix = matches[1].slice(1);
|
|
|
- if (tldjs.getPublicSuffix(suffix) === suffix) return true;
|
|
|
+ if (tld.getPublicSuffix(suffix) === suffix) return true;
|
|
|
}
|
|
|
return false;
|
|
|
});
|