Skip to content

Commit 83d112c

Browse files
committed
refactor all to typescript and scss
1 parent f4b9eaf commit 83d112c

File tree

9 files changed

+73
-43
lines changed

9 files changed

+73
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
/build
44
*.config.js
55
*.css*
6+
*.js

GitHub One Monokai/Resources/Script.js

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function show(enabled: any, useSettingsInsteadOfPreferences: boolean) {
2+
if (useSettingsInsteadOfPreferences) {
3+
let querySelector = document.querySelector;
4+
5+
querySelector<HTMLElement>("state-on").innerText =
6+
"Status: Enabled";
7+
querySelector<HTMLElement>("state-off").innerText =
8+
"Status: Disabled";
9+
querySelector<HTMLElement>("state-unknown").innerText =
10+
"You can turn on GitHub One Monokai’s extension in the Extensions section of Safari Settings.";
11+
querySelector<HTMLElement>("open-preferences").innerText =
12+
"Open in Safari Settings…";
13+
}
14+
15+
if (typeof enabled === "boolean") {
16+
document.body.classList.toggle(`state-on`, enabled);
17+
document.body.classList.toggle(`state-off`, !enabled);
18+
} else {
19+
document.body.classList.remove(`state-on`);
20+
document.body.classList.remove(`state-off`);
21+
}
22+
}
23+
24+
function openPreferences() {
25+
// @ts-ignore
26+
webkit.messageHandlers.controller.postMessage("open-preferences");
27+
}
28+
29+
document
30+
.querySelector("button.open-preferences")
31+
.addEventListener("click", openPreferences);

GitHub One Monokai/Resources/Style.css renamed to GitHub One Monokai/Resources/Style.scss

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ body {
2626

2727
font: -apple-system-short-body;
2828
text-align: center;
29-
}
3029

31-
body:not(.state-on, .state-off) :is(.state-on, .state-off) {
32-
display: none;
33-
}
30+
&:not(.state-on, .state-off) :is(.state-on, .state-off) {
31+
display: none;
32+
}
3433

35-
body.state-on :is(.state-off, .state-unknown) {
36-
display: none;
37-
}
34+
&.state-on :is(.state-off, .state-unknown) {
35+
display: none;
36+
}
3837

39-
body.state-off :is(.state-on, .state-unknown) {
40-
display: none;
38+
&.state-off :is(.state-on, .state-unknown) {
39+
display: none;
40+
}
4141
}
4242

4343
button {

GitHub One Monokai/ViewController.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Created by Do Vien on 27/01/2023 at 01:01.
33
//
44
// Copyright © 2023 CPea2506. All rights reserved.
5-
//
6-
5+
//
76

87
import Cocoa
98
import SafariServices
109
import WebKit
1110

12-
let extensionBundleIdentifier = "com.cpea.SafariGitHubSyntaxOneMonokai.Extension"
11+
let extensionBundleIdentifier = "com.cpea.GitHubOneMonokai.Extension"
1312

14-
class ViewController: NSViewController, WKNavigationDelegate, WKScriptMessageHandler {
13+
// MARK: - ViewController
1514

15+
class ViewController: NSViewController, WKNavigationDelegate, WKScriptMessageHandler {
1616
@IBOutlet var webView: WKWebView!
1717

1818
override func viewDidLoad() {
@@ -26,9 +26,9 @@ class ViewController: NSViewController, WKNavigationDelegate, WKScriptMessageHan
2626
}
2727

2828
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
29-
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { (state, error) in
29+
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { state, error in
3030
guard let state = state, error == nil else {
31-
// Insert code to inform the user that something went wrong.
31+
debugPrint("Something went wrong: \(error!.localizedDescription)")
3232
return
3333
}
3434

@@ -43,15 +43,14 @@ class ViewController: NSViewController, WKNavigationDelegate, WKScriptMessageHan
4343
}
4444

4545
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
46-
if (message.body as! String != "open-preferences") {
47-
return;
46+
if message.body as! String != "open-preferences" {
47+
return
4848
}
4949

50-
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { error in
50+
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { _ in
5151
DispatchQueue.main.async {
5252
NSApplication.shared.terminate(nil)
5353
}
5454
}
5555
}
56-
5756
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"scripts": {
88
"build:codemirror": "tailwindcss -i './GitHub One Monokai Extension/Resources/one-monokai-codemirror.css' -o './GitHub One Monokai Extension/Resources/one-monokai-codemirror.css'",
99
"build:prettylights": "tailwindcss -i './GitHub One Monokai Extension/Resources/one-monokai-prettylights.css' -o './GitHub One Monokai Extension/Resources/one-monokai-prettylights.css'",
10-
"build:css": "sass . && pnpm build:codemirror && pnpm build:prettylights"
10+
"build:css": "sass . && pnpm build:codemirror && pnpm build:prettylights",
11+
"build": "tsc && pnpm build:css"
1112
},
1213
"type": "module",
1314
"devDependencies": {
@@ -16,6 +17,7 @@
1617
"sass": "^1.63.6",
1718
"stylelint": "^15.10.0",
1819
"stylelint-config-recommended-scss": "^12.0.0",
19-
"tailwindcss": "^3.3.2"
20+
"tailwindcss": "^3.3.2",
21+
"typescript": "^5.1.6"
2022
}
2123
}

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "Node",
6+
"declaration": false,
7+
"skipLibCheck": true,
8+
"allowSyntheticDefaultImports": true
9+
},
10+
}

0 commit comments

Comments
 (0)