MCPcopy Index your code
hub / github.com/NobyDa/Script / eTLD

Function eTLD

Rule-Storage/Rule-Storage.js:111–132  ·  view source on GitHub ↗
(content = {})

Source from the content-addressed store, hash-verified

109}
110
111async function eTLD(content = {}) {
112 if (!content.update_time || (Date.now() - content.update_time > 86400000 * 30)) {
113 await new Promise(resolve => {
114 $httpClient.get({
115 url: 'https://publicsuffix.org/list/public_suffix_list.dat'
116 }, (error, resp, body) => {
117 if (resp.status == 200 && !error && body) {
118 content.update_time = Date.now();
119 content.public_suffix = body.replace(/\r|.*(\/\/|#|;).*|\n(\!|\*\.)/g, '\n').split('\n').filter((t) => t);
120 $persistentStore.write(JSON.stringify(content), `${args.key}-eTLD`);
121 resolve()
122 } else if (content.update_time) {
123 console.log(`Update eTLD list failed: ${error}`);
124 resolve()
125 } else {
126 throw new Error(`Download eTLD list failed: ${error}`)
127 }
128 })
129 })
130 }
131 return content
132}
133
134/*
135Shorten multi level domain: non-eTLD, full eTLD, second level domain will return original

Callers 1

Rule-Storage.jsFile · 0.85

Calls 4

getMethod · 0.45
writeMethod · 0.45
stringifyMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected