Browse Source

Refactor: minor changes

SukkaW 1 year ago
parent
commit
b4df4bab00
3 changed files with 34 additions and 23 deletions
  1. 1 3
      Build/build-common.ts
  2. 1 1
      Build/build-sgmodule-always-realip.ts
  3. 32 19
      Build/lib/parse-filter.ts

+ 1 - 3
Build/build-common.ts

@@ -28,9 +28,7 @@ export const buildCommon = task(import.meta.main, import.meta.path)(async (span)
     //   if (dirName === 'domainset' || dirName === 'ip' || dirName === 'non_ip') {
     //     return false;
     //   }
-
-  //   console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`));
-
+    //   console.error(picocolors.red(`[build-comman] Unknown dir: ${dirPath}`));
     //   return true;
     // })
     .filter((filepath, isDirectory) => {

+ 1 - 1
Build/build-sgmodule-always-realip.ts

@@ -44,7 +44,7 @@ const HOSTNAMES = [
 
 export const buildAlwaysRealIPModule = task(import.meta.main, import.meta.path)(async (span) => {
   // Intranet, Router Setup, and mant more
-  const dataset = ([Object.entries(DIRECTS), Object.entries(LANS)]);
+  const dataset = [Object.entries(DIRECTS), Object.entries(LANS)];
   const surge = dataset.flatMap(data => data.flatMap(([, { domains }]) => domains.flatMap((domain) => [`*.${domain}`, domain])));
   const clash = dataset.flatMap(data => data.flatMap(([, { domains }]) => domains.map((domain) => `+.${domain}`)));
 

+ 32 - 19
Build/lib/parse-filter.ts

@@ -434,28 +434,41 @@ function parse($line: string, gorhill: PublicSuffixList, result: [string, ParseT
     let sliceStart = 0;
     let sliceEnd: number | undefined;
 
-    if (line[2] === '|') { // line.startsWith('@@|')
-      sliceStart = 3;
-      whiteIncludeAllSubDomain = false;
+    switch (line[2]) {
+      case '|':
+        // line.startsWith('@@|')
+        sliceStart = 3;
+        whiteIncludeAllSubDomain = false;
+
+        if (line[3] === '|') { // line.startsWith('@@||')
+          sliceStart = 4;
+          whiteIncludeAllSubDomain = true;
+        }
+
+        break;
 
-      if (line[3] === '|') { // line.startsWith('@@||')
-        sliceStart = 4;
+      case '.': { // line.startsWith('@@.')
+        sliceStart = 3;
         whiteIncludeAllSubDomain = true;
+        break;
       }
-    } else if (line[2] === '.') { // line.startsWith('@@.')
-      sliceStart = 3;
-      whiteIncludeAllSubDomain = true;
-    } else if (
-      /**
-       * line.startsWith('@@://')
-       *
-       * `@@://googleadservices.com^|`
-       * `@@://www.googleadservices.com^|`
-       */
-      line[2] === ':' && line[3] === '/' && line[4] === '/'
-    ) {
-      whiteIncludeAllSubDomain = false;
-      sliceStart = 5;
+
+      case ':': {
+        /**
+         * line.startsWith('@@://')
+         *
+         * `@@://googleadservices.com^|`
+         * `@@://www.googleadservices.com^|`
+         */
+        if (line[3] === '/' && line[4] === '/') {
+          whiteIncludeAllSubDomain = false;
+          sliceStart = 5;
+        }
+        break;
+      }
+
+      default:
+        break;
     }
 
     if (lineEndsWithCaretOrCaretVerticalBar) {