-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathui.html
More file actions
147 lines (145 loc) · 4.55 KB
/
ui.html
File metadata and controls
147 lines (145 loc) · 4.55 KB
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
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="ui.css">
<link rel="icon" type="image/png" href="icon/icon-16.png">
<title>ContainerScript Editor</title>
<style>
body {
margin: 0;
padding: 20px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 15px;
}
.header img {
width: 70px;
height: 70px;
}
.header h1 {
color: #2c3e50;
margin: 0 0 10px 0;
}
.header p {
color: #7f8c8d;
margin: 0;
}
#root {
width: 100%;
height: 700px;
border: 1px solid #e0e0e0;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
background-color: #fff;
margin-bottom: 30px;
}
.instructions {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.instructions summary {
padding: 20px 25px;
cursor: pointer;
user-select: none;
color: #2c3e50;
font-weight: 600;
font-size: 1.2em;
}
.instructions summary:hover {
background-color: #f8f9fa;
}
.instructions summary:focus {
outline: none;
}
.instructions-content {
padding: 0 25px 25px 25px;
border-top: 1px solid #eee;
}
.instructions h3 {
color: #2c3e50;
margin-top: 20px;
margin-bottom: 15px;
}
.instructions p {
color: #34495e;
line-height: 1.6;
margin-bottom: 15px;
}
.instructions code {
background-color: #f8f9fa;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9em;
color: #e83e8c;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<img src="icon/icon-512.png" alt="ContainerScript Logo">
<div>
<h1>Container Script</h1>
<p>Programmatically assign URLs to containers.</p>
</div>
</div>
<div id="root"></div>
<details class="instructions">
<summary>How to Use ContainerScript</summary>
<div class="instructions-content">
<p>
Write JavaScript code to define container rules.
The code runs each time you navigate to a URL. Two variables are available:
</p>
<ul style="color: #34495e; line-height: 1.8; margin-bottom: 15px;">
<li><code>url</code> — the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL">URL</a> being navigated to.</li>
<li><code>sourceUrl</code> — the URL of the page that initiated the navigation (may be <code>undefined</code> for new tabs).</li>
</ul>
<p>
The code is executed using <a href="https://github.com/Siubaak/sval">Sval</a> due to <a href="https://www.w3.org/TR/CSP/">CSP</a> restrictions.
</p>
<h3>Basic Usage</h3>
<p>Return a string to open the URL in that container (replaces the current tab):</p>
<p><code>if (url.hostname === "www.amazon.com") return "shopping";</code></p>
<p>Return <code>null</code> to open the URL in the default container (no container):</p>
<p><code>if (url.hostname === "github.com") return null;</code></p>
<h3>Advanced Configuration</h3>
<p>Return an object for more control. Use <code>name</code> (or <code>profile</code>) for the container name, and <code>replace</code> to control whether the original tab is closed:</p>
<p><code>if (url.toString().includes("bank.com")) return { name: "finance", icon: "fingerprint", color: "blue" };</code></p>
<p>Keep the original tab open by setting <code>replace</code> to <code>false</code>:</p>
<p><code>if (url.hostname === "example.com") return { name: "work", replace: false };</code></p>
<p>Use <code>sourceUrl</code> to keep the original tab open when navigating from a specific site (e.g. Google):</p>
<pre style="background-color: #f8f9fa; padding: 12px 16px; border-radius: 3px; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 0.9em; color: #e83e8c; line-height: 1.6; overflow-x: auto;"><code>
let replace = true;
switch (sourceUrl?.hostname) {
case "www.google.com":
case "duckduckgo.com":
case "www.bing.com":
replace = false;
}
switch (url.hostname) {
case "www.youtube.com":
case "chatgpt.com":
case "www.reddit.com":
return { name: "Personal", replace };
}
return null;
</code></pre>
</div>
</details>
</div>
<script src="ui.js"></script>
</body>
</html>