-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
154 lines (133 loc) · 5.24 KB
/
index.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
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<title>Markdown Link Generator</title>
<style>
body { background-color: #ddd; font-family: Arial, sans-serif; padding: 10px; }
.spacing { margin: 20px 0px 0px 20px; }
form { background-color: #fff; padding: 10px; max-width: 600px; margin-bottom: 0px; }
.border { border: 1px solid #767676; }
label { font-size: 10px; display: block; }
input { margin-bottom: 3px; }
#resourceInput { width: 500px; }
#widthInput { width: 60px; }
textarea { min-width: 600px; }
h3 { margin: 0px; font-size: 12px; }
.fullwidth { max-width: 100%; }
.hidden_element { display: none; }
.wrapper { background: #fff; padding: 5px 4px 0px 0px; margin-bottom: 5px; overflow: hidden;}
.wrapper td { padding: 0px; }
.wrapper td img { margin-left: -2px; max-width: 40px; }
p.non_image_note { font-size: 11px; margin-top: 1px; }
</style>
</head>
<body>
<form id="markdownForm" class="border">
<label for="resourceInput">Resource ID or Link:</label>
<input type="text" id="resourceInput" required>
<br>
<label for="widthInput">Width (optional):</label>
<input type="number" id="widthInput">
<br>
<button type="submit">Generate Markdown Link</button>
</form>
<div id="outputDiv" style="margin-top: 5px !important;"></div>
<script>
function check_asset_url(url, callback) {
const img = new Image();
img.onload = function () {
callback("found");
};
img.onerror = function () {
callback("not found");
};
img.src = url;
}
function extractIDFromLink(input) {
const match = input.match(/\/(file\/d\/|open\?id=)([^/]+)/);
if (match && match[2]) {
return match[2];
}
const matchWithView = input.match(/\/d\/([^/?]+)/);
if (matchWithView && matchWithView[1]) {
return matchWithView[1];
}
return null;
}
function convertToMarkdownLink() {
const resourceInput = document.getElementById("resourceInput").value.trim();
const widthInput = document.getElementById("widthInput").value.trim();
let imageURL;
if (resourceInput.startsWith("http")) {
imageURL = extractIDFromLink(resourceInput);
} else {
imageURL = resourceInput;
}
if (!imageURL) {
imageURL = resourceInput;
}
const imageLink = `https://drive.google.com/thumbnail?id=${imageURL}&sz=s4000`;
check_asset_url(imageLink, function (status) {
const statusBox = document.getElementById("statusBox");
const markdownLink = `![${widthInput ? `|${widthInput}` : ""}](${imageLink})`;
const imageTag = `<h3>Image:</h3><img style="max-width:${widthInput}px" class="fullwidth" src="${imageLink}" onerror="this.style.display='none'" />`;
const pdfTag = `<p class="non_image_note"><b>Note:</b> This is either a pdf (or non-image) asset OR your have not entered a publicly-shared link or link id. In this case, please retry!</p><div class="hidden_element"><iframe data-src="${imageLink}" style="width:${widthInput}px; height:500px;"></iframe></div>`;
const outputDiv = document.getElementById("outputDiv");
// https://media.tenor.com/8KTq9czG_NgAAAAi/greentick-emoji
var MarkdownTextArea = `
<table class="wrapper border">
<tr>
<td class="left-column">
<img class="gif" src="https://media.tenor.com/8KTq9czG_NgAAAAi/greentick-emoji.gif" onload="playOnce()" alt="Animated GIF">
</td>
<td class="right-column">
<textarea class="markdown-link-textarea" readonly>${markdownLink}</textarea>
</td>
</tr>
</table>
`;
if (status === "found") {
outputDiv.innerHTML = MarkdownTextArea + `
${imageTag}
`;
copyToClipboard(markdownLink);
} else {
outputDiv.innerHTML = MarkdownTextArea + `
${pdfTag}
`;
copyToClipboard(markdownLink);
}
});
}
function copyToClipboard(text) {
const tempTextarea = document.createElement('textarea');
tempTextarea.value = text;
document.body.appendChild(tempTextarea);
tempTextarea.select();
document.execCommand('copy');
document.body.removeChild(tempTextarea);
}
function loadMaxWidth() {
const maxWidthValue = localStorage.getItem("maxWidth");
if (maxWidthValue) {
document.getElementById("widthInput").value = maxWidthValue;
}
}
function saveMaxWidth(widthInputValue) {
localStorage.setItem("maxWidth", widthInputValue);
}
const form = document.getElementById("markdownForm");
form.addEventListener("submit", (event) => {
event.preventDefault();
const widthInputValue = document.getElementById("widthInput").value.trim();
saveMaxWidth(widthInputValue);
convertToMarkdownLink();
});
// Load the maxWidth when the page loads
loadMaxWidth();
</script>
<div style="position: fixed; bottom: 0px; right: 0px; background: #333; color: #fff; font-size: 10px; padding: 3px 6px; border-radius: 4px 0 0 0;">
Made by <a href="https://www.reesskennedy.com" style="color: #fff;">Reess</a>
</div>
</body>
</html>