blob: 591d810ee9eb29ee4f03b0ccb87bdb8c7170d470 [file] [log] [blame]
Adrià Vilanova Martínez0335b512022-01-21 13:34:59 +01001// Returns whether the extension is a production version (released stable or
2// beta version).
3export function isProdVersion() {
4 // #!if production && !canary
5 return true;
6 // #!else
7 return false;
8 // #!endif
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02009}
Adrià Vilanova Martíneze32adc42021-08-30 17:16:49 +020010
11// Returns the extension version
12export function getExtVersion() {
13 var manifest = chrome.runtime.getManifest();
14 return manifest?.version;
15}
Adrià Vilanova Martínez5a8055b2022-09-29 13:05:19 +020016
Adrià Vilanova Martínezf1905852024-02-28 22:28:36 +010017// Returns a semver-compatible extension version
18export function getSemVerExtVersion() {
19 const version = getExtVersion();
20 if (!(typeof version === 'string')) return null;
21 return version.match(/^[^.]*(?:\.[^.]*){0,2}/)?.[0] ?? null;
22}
23
Adrià Vilanova Martínez5a8055b2022-09-29 13:05:19 +020024// Get a URL to a document which is part of the extension documentation (using
25// |ref| as the Git ref).
26export function getDocURLWithRef(doc, ref) {
27 return 'https://gerrit.avm99963.com/plugins/gitiles/infinitegforums/+/' +
28 ref + '/docs/' + doc;
29}
30
31// Get a URL to a document which is part of the extension documentation
32// (autodetect the appropriate Git ref)
33export function getDocURL(doc) {
34 if (!isProdVersion()) return getDocURLWithRef(doc, 'HEAD');
35
36 var version = getExtVersion();
37 return getDocURLWithRef(doc, 'refs/tags/v' + version);
38}