build-reject-domainset-worker.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. exports.dedupe = ({ fullSet, input }) => {
  2. const output = new Set();
  3. for (const domainFromInput of input) {
  4. for (const domainFromFullSet of fullSet) {
  5. if (
  6. domainFromFullSet.startsWith('.')
  7. && domainFromFullSet !== domainFromInput
  8. && (
  9. domainFromInput.endsWith(domainFromFullSet)
  10. || `.${domainFromInput}` === domainFromFullSet
  11. )
  12. ) {
  13. output.add(domainFromInput);
  14. break;
  15. }
  16. }
  17. }
  18. return output;
  19. };
  20. exports.whitelisted = ({ whiteList, input }) => {
  21. const output = new Set();
  22. for (const domain of input) {
  23. for (const white of whiteList) {
  24. if (domain.includes(white) || white.includes(domain)) {
  25. output.add(domain);
  26. break;
  27. }
  28. }
  29. }
  30. return output;
  31. };
  32. exports.dedupeKeywords = ({ keywords, suffixes, input }) => {
  33. const output = new Set();
  34. for (const domain of input) {
  35. for (const keyword of keywords) {
  36. if (domain.includes(keyword) || keyword.includes(domain)) {
  37. output.add(domain);
  38. break;
  39. }
  40. }
  41. for (const suffix of suffixes) {
  42. if (domain.endsWith(suffix)) {
  43. output.add(domain);
  44. break;
  45. }
  46. }
  47. }
  48. return output;
  49. }