generated from extratone/latte
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Clip Webpage.jelly
95 lines (89 loc) · 3.08 KB
/
Clip Webpage.jelly
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
import Shortcuts
#Color: blue, #Icon: documentOutline
//Unable to get shortcuts action is.workflow.actions.folder
var Folder = Folder
if(ShortcutInput != nil) {
var SourceURL = ShortcutInput
if(ShortcutInput != nil) {
markdownFromRich(text: ShortcutInput) >> markdownFromRich
splitText(text: Markdown from Rich Text) >> splitText
repeatEach(Split Text) {
text(text: "> ${Repeat Item}") >> text
} >> RepeatResult
combineText(text: Repeat Results) >> combineText
text(text: "${Combined Text}") >> text 1
var PageSelection = Text
} else {
nothing()
//Unable to get shortcuts action is.workflow.actions.setvariable
} >> IFResult
} else {
// No input passed. Assume URL is in the clipboard. This is the most likely scenario when running inside Siri or the Mac.
getURLSFromInput(text: "${Clipboard}") >> getURLSFromInput
var SourceURL = URLs
// Attempt to mitigate lack of URL in the clipboard on the Mac
if(DeviceDetails == "Mac") {
getURL() >> getURL 1
var SourceURL = URL
runAppleScript(script: "on run {input, parameters} tell application "Safari" to return name of front document return inputend run") >> runAppleScript
var TitleofURL = AppleScript Result
/*
Attempt to mitigate lack of support for webpage selections on Mac
Credit to https://macscripter.net/viewtopic.php?pid=204631#p204631 for the script
*/
// Note: you must enable Allow JavaScript from Apple Events in Safari’s Develop Menu for this to work
runAppleScript(script: "on run {input, parameters} tell application "Safari" set theText to (do JavaScript "getSelection().toString()" in document 1) end tell return theTextend run") >> runAppleScript 1
splitText(text: AppleScript Result) >> splitText 1
repeatEach(Split Text) {
text(text: "> ${Repeat Item}") >> text 2
} >> RepeatResult 1
combineText(text: Repeat Results) >> combineText 1
text(text: "${Combined Text}") >> text 3
var PageSelection = Text
} else {
}
} >> IFResult 1
// Choose to add a comment
menu(Add a Comment?, [) {
case("💭"):
askForInput(prompt: "Add a Comment") >> askForInput
text(text: "**Comment:** ${Provided Input}") >> text 4
var Comment = Text
case("❌"):
nothing()
//Unable to get shortcuts action is.workflow.actions.setvariable
} >> MenuResult
if(Title of URL == nil) {
articleDetail(detail: Title, article: Source URL) >> articleDetail
var TitleofURL = Title
} else {
} >> IFResult 2
// Create sanitized title for page
text(text: "${Title of URL}") >> text 5
replaceText(input: "${Text}", find: ":", replace: " -") >> Sanitized Title
// Get host from URL
urlComponent(url: "${Source URL}", component: Host) >> urlComponent
var C7CD872A-B7E9-442A-9552-098374C1D29D = """---
title: ""
saved: 
source: ""
publisher: ""
---
[]()

"""
text("${C7CD872A-B7E9-442A-9552-098374C1D29D}")
setName(input: Text, name: "${Updated Text}.md") >> setName
saveFile(input: Renamed Item, ask: false) >> saveFile
text(text: "[[${Sanitized Title}.md]]") >> Internal Link
var InternalLink = Internal Link
setClipboard(variable: Internal Link) >> setClipboard
runShortcut(name: "Append to Dashboard", input: Internal Link) >> runShortcut