MCPcopy Index your code
hub / github.com/violentmonkey/violentmonkey / inferScriptHome

Function inferScriptHome

src/background/utils/script.js:191–227  ·  view source on GitHub ↗

* @param {VMScript} script * @returns {string | undefined}

(script)

Source from the content-addressed store, hash-verified

189 * @returns {string | undefined}
190 */
191function inferScriptHome(script) {
192 let u = script.custom.lastInstallURL;
193 if (u) {
194 u = u.split('/', 6);
195 switch (u[2]) {
196 case 'update.greasyfork.org':
197 case 'update.sleazyfork.org':
198 u[2] = u[2].slice(7);
199 // fallthrough
200 case 'greasyfork.org':
201 case 'sleazyfork.org':
202 if (u[3] !== 'scripts') u.splice(3, 1);
203 break;
204 case 'raw.githubusercontent.com':
205 u[2] = 'github.com';
206 break;
207 case 'github.com':
208 break;
209 case 'openuserjs.org':
210 u[3] = 'scripts';
211 u[4] = u[4].replace(/(\.min)?\.user\.js$/, '');
212 break;
213 default:
214 u = false;
215 }
216 if (u) {
217 u.length = 5; // scheme + 1 + host + group + name
218 u = u.join('/');
219 }
220 }
221 if (!u) {
222 u = script.meta.namespace;
223 u = /^https?:\/\/(?!tampermonkey\.net\/)/.test(u)
224 && getFullUrl(u).replace(/^https?(:\/\/userscripts)(\.org\/users\/\w)/, 'https$1-mirror$2');
225 }
226 return u;
227}
228
229/**
230 * @param {VMScript} script

Callers 1

inferScriptPropsFunction · 0.85

Calls 2

getFullUrlFunction · 0.90
testMethod · 0.45

Tested by

no test coverage detected