tld.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import tldjs from 'tldjs/tld';
  2. // import { fromUserSettings } from 'tldjs';
  3. // import Trie from 'tldjs/lib/suffix-trie';
  4. // import { request } from '@/common';
  5. // let tldjs;
  6. // export function initTLD(remote) {
  7. // // TLD rules are too large to be packed, download them at runtime.
  8. // const url = 'https://violentmonkey.top/static/tld-rules.json';
  9. // const key = 'dat:tldRules';
  10. // browser.storage.local.get(key)
  11. // .then(({ [key]: tldRules }) => {
  12. // if (tldRules) return tldRules;
  13. // if (!remote) return Promise.reject('ignore TLD');
  14. // return request(url, { responseType: 'json' })
  15. // .then(({ data: rules }) => {
  16. // console.info('Downloaded public suffix data');
  17. // return browser.storage.local.set({ [key]: rules })
  18. // .then(() => rules);
  19. // });
  20. // })
  21. // .then(tldRules => {
  22. // console.info('Initialized TLD');
  23. // tldjs = fromUserSettings({ rules: Trie.fromJson(tldRules) });
  24. // })
  25. // .catch(err => {
  26. // if (process.env.DEBUG) console.error(err);
  27. // console.info('Failed initializing TLD');
  28. // });
  29. // }
  30. export function initTLD() {}
  31. function exportMethod(key) {
  32. return (...args) => tldjs && tldjs[key](...args);
  33. }
  34. export function isReady() {
  35. return !!tldjs;
  36. }
  37. export const getDomain = exportMethod('getDomain');
  38. export const getSubdomain = exportMethod('getSubdomain');
  39. export const getPublicSuffix = exportMethod('getPublicSuffix');