-
Notifications
You must be signed in to change notification settings - Fork 0
/
onenote.html
144 lines (131 loc) · 5.65 KB
/
onenote.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OneNote Protocol Forwarder</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0 auto;
max-width: 800px;
padding: 20px;
}
h1, h2, h3 {
color: #333;
}
a {
color: #0066cc;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
pre {
background-color: #f4f4f4;
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
overflow-x: auto;
}
input[type="text"] {
width: 70%;
padding: 8px;
margin-right: 10px;
}
button {
background-color: #0066cc;
border: none;
color: white;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
display: none;
}
</style>
</head>
<body>
<p><a href="javascript:history.back()">Back...</a></p>
<h1>OneNote Forwarder</h1>
<h2>What does this do?</h2>
<p>When provided a suitable query string, this page will use JavaScript to redirect to a OneNote page or section</p>
<h2>Why is this needed?</h2>
<p>OneNote urls use the <code>onenote:</code> protocol which is many applications do not allow. Using this page as an intermediary
allows you to effectively link to a OneNote page or section using a regular <code>https</code> protocol link</p>
<h2>How do I use it?</h2>
<p>OneNote links can be obtained by right-clicking on a page or section in OneNote and selecting "Copy Link to Page" or "Copy Link to Section"</p>
<p>The format of a OneNote link will look like this:</p>
<pre id="oneNoteExample">onenote:https://example.com/public/SitePages/HelloWorld/New%20World.one#Hello%20World§ion-id={407570BB-A4B0-42C5-B78A-CC4A40BF3F29}&page-id={84699AA3-6F05-456C-B953-5DFBEBEDD322}&end</pre>
<p><b>To use this page as a OneNote forwarder</b>, call this page with the OneNote link as a query string parameter like this:</p>
<pre id="forwarderExample">onenote.html?https://example.com/public/SitePages/HelloWorld/New%20World.one#Hello%20World§ion-id={407570BB-A4B0-42C5-B78A-CC4A40BF3F29}&page-id={84699AA3-6F05-456C-B953-5DFBEBEDD322}&end</pre>
<p>Note: The first time you use this, you'll likely need to allow this site to open the OneNote application.</p>
<h2>Paste Your OneNote URL</h2>
<p>Rather than manipulating the query string you can also simply paste your OneNote URL here and click the button to generate a forwarder link.</p>
<form id="oneNoteForm">
<input type="text" id="oneNoteUrl" name="oneNoteUrl" placeholder="Paste your OneNote URL here">
<button type="submit">Generate Forwarder Link</button>
</form>
<div id="result">
<h3>Generated Links:</h3>
<p>OneNote URL: <a id="oneNoteLink" href="#"></a></p>
<p>Forwarder Link: <a id="forwarderLink" href="#"></a></p>
</div>
<script>
/* Get the full query string including any '#' parts */
function getFullQueryString() {
return window.location.href.split('?')[1] || '';
}
/* Extract OneNote link from the query string */
function getOneNoteLink(fullQuery) {
if (!fullQuery) return '';
const oneNoteIndex = fullQuery.indexOf('onenote:');
return oneNoteIndex !== -1 ? fullQuery.substring(oneNoteIndex) : 'onenote:' + fullQuery;
}
/* Update links in the UI */
function updateLinks(oneNoteUrl) {
const resultDiv = document.getElementById('result');
const oneNoteLink = document.getElementById('oneNoteLink');
const forwarderLink = document.getElementById('forwarderLink');
const oneNoteExample = document.getElementById('oneNoteExample');
const forwarderExample = document.getElementById('forwarderExample');
if (oneNoteUrl) {
oneNoteLink.textContent = oneNoteLink.href = oneNoteUrl;
const encodedUrl = encodeURIComponent(oneNoteUrl.replace('onenote:', ''));
const forwarderUrl = `${thisUrl}?${encodedUrl}`;
forwarderLink.textContent = forwarderLink.href = forwarderUrl;
resultDiv.style.display = 'block';
// Update example links
oneNoteExample.innerHTML = `<a href="${oneNoteUrl}">${oneNoteUrl}</a>`;
forwarderExample.innerHTML = `<a href="${forwarderUrl}">${forwarderUrl}</a>`;
} else {
resultDiv.style.display = 'none';
}
}
/* Handle form submission */
function handleFormSubmit(event) {
event.preventDefault();
const input = document.getElementById('oneNoteUrl').value.trim();
if (input) {
const oneNoteUrl = input.startsWith('onenote:') ? input : 'onenote:' + input;
updateLinks(oneNoteUrl);
}
}
const thisUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
const fullQuery = decodeURIComponent(getFullQueryString());
const oneNoteUrl = getOneNoteLink(fullQuery);
/* Update links and redirect if a URL is provided */
if (oneNoteUrl) {
updateLinks(oneNoteUrl);
window.location.href = oneNoteUrl;
}
/* Set up event listener for form submission */
document.getElementById('oneNoteForm').addEventListener('submit', handleFormSubmit);
</script>
</body>
</html>