Hype ScriptableActions (for the Tumult Hype Forum)


If you wonder why the screenshot is on iPhone 6s Plus… yes folks that’s what I still use.

This thread is for JavaScript-based actions to be used with the great and donation based Scriptable iOS-App by Simon Støvring. This extraordinary app integrates with the native APIs of iOS directly from JavaScript. So, you can do all kind of useful stuff.

https://scriptable.app/

How-To:

  • Install the Scriptable app on your phone
  • Install the script by either:
    • Navigating to this post and click on the scriptable file of your choice
    • Creating a new script and copy and pasting the code into it

Latest Posts

This script can show the latest posts using a voice command and opens the Hype Forum when clicked on a post. It is simple and based on the included example script so feel free to post additions and tweaks to it in this thread.

Plain text script for copy and paste into the app:

/**
* Hype ScriptableActions Latest Posts 1.1
* Fetch latest forum posts from Hype Forum
* based on example script and tweaked from there.
*/

let forumURL = "https://forums.tumult.com"
let url = forumURL+"/posts.json"
let req = new Request(url)
let json = await req.loadJSON()
let table = new UITable()
let posts = json.latest_posts
for (i = 0; i < posts.length; i++) {
 let item = posts[i]
 let row = new UITableRow()
 row.onSelect = (idx) => {
    let item = posts[idx]
    Safari.open(forumURL+'/t/'+item.topic_id+'/'+item.post_number)
 }
 let imageURL = item.avatar_template.replace('{size}', 240);
 if (imageURL.indexOf('http')!=0) {
    imageURL = forumURL+imageURL
 }
 let title = item.topic_title
 let subtitle = '@'+item.username+' '+item.name
 let imageCell = row.addImageAtURL(imageURL)
 let titleCell = row.addText(title, subtitle)
 imageCell.widthWeight = 20
 titleCell.widthWeight = 80
 row.height = 80
 row.cellSpacing = 10
 table.addRow(row)
}

QuickLook.present(table)

if (config.runsWithSiri) {
 Speech.speak("Here are the latest posts.")
}

Script.complete()

As scriptable file:
LatestHypeForumPosts.scriptable

3 Likes

Nice,
I have played with scriptable and Pythonista and love them.

Yes, although I didn’t play much with Pythonista… more into JS. Love how we can script iOS with JS. Would love that in export scripts, too. I know, has been discussed before.

Latest Posts Version History:
1.1 - includes links to the forum post (per row) now.

You can, open the script click the pref icon near the bottom , scroll down to the bottom of the pref and you will see a share icon, click and Save to Files or what ever.

I ment Hype Export Scripts in JS :v: … this is an old discussion (JavaScript for automation etc.) not being fully supported etc. Sorry didn’t want to reignite that old discussion in this thread.

gah… must be missing something. This presents but does not load. (remains blank)

var wbv = new WebView()

wbv.loadURL(forumURL+'/t/'+item.topic_id+'/'+item.post_number)
wbv.present()

That is totally fine. Maybe some casting or conversion error? Not sure what exactly your doing so limited feedback possible. Are you currently writing it for macOS?

Translatest to using this post as an example …

"https://forums.tumult.com" + '/t/' + '17539' + '/' + '6'

so …

https://forums.tumult.com/t/17539/6

yep, looks correct.

Does it work your end.?

In the iOS-app and as posted above. Yes. But then again I am not using that WebView reference! Only a redirection to iOS Safari as you can see. The discourse forum actually adds the full title into that URL so maybe there is one redirect involved that the WebView isn’t following?

Yep all works including Safai load :grinning:

Thats the bit I meant.

Wanted to see if this could be done…?
I put it in place of the Safari.openInApp()
Also I think you can then tal k to the webview DOM via script eval

Not sure what is mean about a WebView but before we get lost in translation. I’d love to see a script on macOS or a WebView version. Kudos for trying.

Ah! Okay. Now I understand your still on iOS. I switched to Safari.open to retain login status and additional functionality. Sorry, just saw that the snippet was updated but the copy and paste part not!

1 Like

Yer probably the best bet as the webview issue looks like something to do with the usual suspects cross origin blah,blah, blah…!
( trick there is a share button when in present, you can share the html, I used that to see whats was actaully in the view)