Skip to content

Commit d094861

Browse files
committed
feat: Implement new functionality
1 parent 23dae2a commit d094861

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ description: This is a simple tool I created that does not require a backend
1717

1818
1. **Automatic account switchover**<br>
1919
This tool will automatically resolve permission errors on Google Forms as much as possible.</br>
20-
Click [here](#) to use this tool
20+
Click [here](./switchover) to use this tool

src/layouts/switchover.njk

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Redirecting...
3+
layout: base.njk
4+
eleventyExcludeFromCollections: true
5+
---
6+
<blockquote><p><strong>Note:</strong> If it does not redirect correctly or an error occurs, please contact <a href="mailto:[email protected]">[email protected]</a>.</p></blockquote>
7+
<p id="result"></p>
8+
<script>
9+
function checkUrl(url) {
10+
try {
11+
const parsedUrl = new URL(url);
12+
const hostname = parsedUrl.hostname;
13+
return (
14+
parsedUrl.protocol === 'https:' &&
15+
(hostname === 'google.com' || hostname.endsWith('.google.com'))
16+
);
17+
} catch {
18+
return false;
19+
}
20+
}
21+
22+
function generateViewUrl(id) {
23+
return `https://docs.google.com/forms/d/e/${id}/viewform`;
24+
}
25+
26+
function toViewUrl(url) {
27+
// Remove any u/{number}/ pattern from the URL
28+
url = url.replace(/\/u\/\d+\//, '/');
29+
30+
const googleFormsPattern =
31+
/https:\/\/docs\.google\.com\/forms\/d\/e\/([a-zA-Z0-9_-]+)(\/(?:edit|formrestricted))?/;
32+
33+
const match = url.match(googleFormsPattern);
34+
if (match) {
35+
const id = match[1];
36+
return generateViewUrl(id);
37+
}
38+
39+
const newURL = new URL(url);
40+
newURL.searchParams.delete('authuser');
41+
newURL.searchParams.delete('pli');
42+
43+
return newURL.toString();
44+
}
45+
</script>
46+
47+
{{ content | safe }}

src/tools/.gitkeep

Whitespace-only changes.

src/tools/switchover/automatic.njk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
permalink: /switchover/automatic/
3+
layout: switchover.njk
4+
eleventyExcludeFromCollections: true
5+
---
6+
<script>
7+
const params = new URLSearchParams(document.location.search);
8+
const url = params.get('url');
9+
10+
if (!url) {
11+
document.getElementById('result').textContent = 'Error: Please provide a URL';
12+
throw new Error('No URL provided');
13+
}
14+
15+
if (!checkUrl(url)) {
16+
document.getElementById('result').textContent = 'Error: Invalid URL';
17+
throw new Error('Invalid URL');
18+
}
19+
20+
const newUrl = toViewUrl(url);
21+
window.location.href = newUrl;
22+
</script>

src/tools/switchover/chooser.njk

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
permalink: /switchover/chooser/
3+
layout: switchover.njk
4+
eleventyExcludeFromCollections: true
5+
---
6+
<script>
7+
const params = new URLSearchParams(document.location.search);
8+
const url = params.get('url');
9+
10+
if (!url) {
11+
document.getElementById('result').textContent = 'Error: Please provide a URL';
12+
throw new Error('No URL provided');
13+
}
14+
15+
if (!checkUrl(url)) {
16+
document.getElementById('result').textContent = 'Error: Invalid URL';
17+
throw new Error('Invalid URL');
18+
}
19+
20+
const encodedUrl = encodeURIComponent(toViewUrl(url));
21+
const newUrl = `https://accounts.google.com/AccountChooser?continue=${encodedUrl}`;
22+
window.location.href = newUrl;
23+
</script>

src/tools/switchover/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Automatic account switchover - Tools
3+
layout: base.njk
4+
permalink: /switchover/
5+
breadcrumbs:
6+
description: This tool will automatically resolve permission errors on Google Forms as much as possible.
7+
---
8+
9+
## How to use
10+
11+
1. **Copy the link**<br>
12+
Copy the link of the Google Form that cannot be opened.
13+
Example: `https://docs.google.com/forms/d/e/{id}/formrestricted`
14+
15+
2. **Paste the link**<br>
16+
Paste the link that does not open after the following URL
17+
Example: `https://misakisota.com/tools/switchover/automatic/?url=https://docs.google.com/forms/d/e/{id}/formrestricted`
18+
19+
> **Note:** For `automatic`, the account is automatically switched. With `chooser`, you can choose your own account.
20+
21+
f you would like more details, please join my [#times_ms](https://n-highschool.slack.com/archives/C06TUUYJDT8) on N High School's Slack and ask.

0 commit comments

Comments
 (0)