-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.ts
137 lines (131 loc) · 4.96 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*---------------------------------------------------------------------------------------------
* Copyright (c) Rowe Wilson Frederisk Holme. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
type DisplayInfo = { text: string; tooltip: string };
/* eslint-disable @typescript-eslint/naming-convention */
jQuery.when(window.mw.loader.using('mediawiki.util'), $.ready).then((): void => {
// check is editable or its source can be viewed
if (!(window.mw.config.get("wgIsProbablyEditable") || ($('#ca-viewsource').length > 0))) {
// if not, do nothing
return undefined;
}
// i18n
const i18nSource: Record<string, DisplayInfo> = {
english: {
text: 'Open in VSCode',
tooltip: 'Open this page in Visual Studio Code',
},
russian: {
text: 'Открыть в VSCode',
tooltip: 'Открыть эту страницу в Visual Studio Code',
},
japanese: {
text: 'VSCode で開く',
tooltip: 'このページを Visual Studio Code で開く',
},
cantonese: {
text: '開啟於 VSCode',
tooltip: '喺 Visual Studio Code 開呢個頁面',
},
simplified_chinese: {
text: '在 VSCode 中打开',
tooltip: '在 Visual Studio Code 中打开此页面',
},
traditional_chinese: {
text: '使用 VSCode 開啟',
tooltip: '以 Visual Studio Code 開啟此頁面',
},
korean: {
text: 'VSCode 에서 열기',
tooltip: '이 페이지를 Visual Studio Code 에서 열기',
},
thai: {
text: 'เปิดใน VSCode',
tooltip: 'เปิดหน้านี้ใน Visual Studio Code',
},
vietnamese: {
text: 'Mở trong VSCode',
tooltip: 'Mở trang này trong Visual Studio Code',
},
indonesian: {
text: 'Buka di VSCode',
tooltip: 'Buka halaman ini di Visual Studio Code',
},
polish: {
text: 'Otwórz w VSCode',
tooltip: 'Otwórz tę stronę w Visual Studio Code',
},
dutch: {
text: 'Open in VSCode',
tooltip: 'Open deze pagina in Visual Studio Code',
},
french: {
text: 'Ouvrir dans VSCode',
tooltip: 'Ouvrir cette page dans Visual Studio Code',
},
german: {
text: 'Öffnen in VSCode',
tooltip: 'Öffne diese Seite in Visual Studio Code',
},
};
const i18n: Record<string, DisplayInfo> = {
'en': i18nSource['english'],
'ru': i18nSource['russian'],
'ja': i18nSource['japanese'],
'ko': i18nSource['korean'],
'yue': i18nSource['cantonese'],
'zh-yue': i18nSource['cantonese'],
'zh': i18nSource['simplified_chinese'],
'zh-hans': i18nSource['simplified_chinese'],
'zh-cn': i18nSource['simplified_chinese'],
'zh-sg': i18nSource['simplified_chinese'],
'zh-my': i18nSource['simplified_chinese'],
'zh-hant': i18nSource['traditional_chinese'],
'zh-tw': i18nSource['traditional_chinese'],
'zh-hk': i18nSource['traditional_chinese'],
'zh-mo': i18nSource['traditional_chinese'],
'th': i18nSource['thai'],
'vi': i18nSource['vietnamese'],
'id': i18nSource['indonesian'],
'pl': i18nSource['polish'],
'nl': i18nSource['dutch'],
'fr': i18nSource['french'],
'de': i18nSource['german'],
};
const lang: string = window.mw.config.get('wgUserLanguage');
const displayInfo: DisplayInfo = {
...i18nSource['english'], // default language
...i18n[lang.split('-')[0]], // language without region
...i18n[lang] // exact language
};
// get scheme, `vscode.env.uriScheme`
const scheme = 'vscode-insiders'; // 'vscode-insiders', 'vscode', undefined
// for codespace or code-server, you need invoke `await vscode.env.asExternalUri`
// const codespaceScheme = 'https://*.github.dev';
// const head: string = scheme ? `${scheme}://` : `${codespaceScheme}/`;
const extensionID = 'rowewilsonfrederiskholme.wikitext';
const actionPath = '/PullPage';
const args: Record<string, string> = {
RemoteBot: 'true',
TransferProtocol: window.location.protocol,
// 'https://host' => '//host': https://www.mediawiki.org/wiki/Manual:$wgServer
SiteHost: window.mw.config.get('wgServer').replace(/^[\w-]*?:(?=\/\/)/, ''),
APIPath: window.mw.util.wikiScript('api'),
Title: window.mw.config.get('wgPageName')
};
const skinMapping: Record<string, { portletId: string; nextNode: string | undefined } | undefined> = {
'minerva': { portletId: 'p-tb', nextNode: '#ca-history' },
'monobook': { portletId: 'p-cactions', nextNode: '#ca-history' },
};
const skinName: string = window.mw.config.get('skin');
window.mw.util.addPortletLink(
skinMapping[skinName]?.portletId || 'p-views',
`${scheme}://${extensionID}${actionPath}?${new URLSearchParams(args).toString()}`,
displayInfo['text'],
'wikitext-extension-gadget',
displayInfo['tooltip'],
undefined,
skinMapping[skinName]?.nextNode
);
});