forked from lxhom/GitHubCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.nomodule.ts
More file actions
29 lines (29 loc) · 1.5 KB
/
generator.nomodule.ts
File metadata and controls
29 lines (29 loc) · 1.5 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
/**
* Generate the footer & Copy URLs.
* @param {string[]} copyStrings The strings that should be copyable
* @param {string} githubURL The link to your markdown file on your GitHub Page (NOT your repository). Example for demo.md from this repository: https://lxhom.github.io/GitHubCopy/demo
* @param {boolean} shhh Add a message saying "Shhh, this is the secret JS Section!"
* @param {boolean} link Add a link to my GitHub page
* @param {string} footerText Add a text to the footer arrow
* @return {{markdown: string, urls: {code: string, url: string}[]}} The output markdown string, and an array with {code, url} objects (indices match with copyStrings)
*/
function generate(
copyStrings: string[],
githubURL: string,
shhh: boolean = true,
link: boolean = true,
footerText: string = ""
): {markdown: string, urls: {code: string, url: string}[]} {
let markdown: string = `<details><summary>${footerText}</summary>\n\n`;
if (shhh) markdown += "Shhh, this is the secret JS Section!\n\n";
if (link) markdown += "Generated by [GitHubCopy](https://github.com/lxhom/GitHubCopy/)\n\n";
markdown += "<script>let i=location.search.split('?')[1];i.length?history.back(navigator.clipboard.writeText(unescape([";
let urls: {code: string, url: string}[] = []
copyStrings.forEach((value: string, index: number) => {
markdown += "'" + escape(value) + "',"
urls.push({code: value, url: githubURL + "?" + index})
})
markdown.substr
markdown += "][+i]))):i</script>\n\n</details>\n\n";
return {markdown, urls};
}