Skip to content

Instantly share code, notes, and snippets.

@serena520
Created February 15, 2020 09:39
Show Gist options
  • Select an option

  • Save serena520/1e8a9e1d0fc34cf84b59d79ef8540310 to your computer and use it in GitHub Desktop.

Select an option

Save serena520/1e8a9e1d0fc34cf84b59d79ef8540310 to your computer and use it in GitHub Desktop.
Search someone's tweets in the Twitter iOS client
// Open a profile, tap the tree dots button, share
// Also see Shortcuts version: https://www.icloud.com/shortcuts/0d4684a6d9db482a9bb8ec1f9934d6b7
const types = [
{
name: "From",
pattern: "from:"
},
{
name: "To",
pattern: "to:"
},
{
name: "Mentioning",
pattern: "@"
}
];
$ui.render({
views: [
{
type: "tab",
props: {
id: "type",
items: types.map(x => x.name)
},
layout: make => {
make.left.top.right.inset(8);
make.height.equalTo(28);
}
},
{
type: "input",
props: {
id: "keyword",
returnKeyType: $rkType.search
},
layout: make => {
make.left.right.inset(8);
make.top.equalTo($("type").bottom).offset(8);
make.height.equalTo(36);
},
events: {
ready: sender => {
sender.focus();
},
returned: sender => {
const keyword = sender.text;
if (keyword.length === 0) {
return;
}
const pattern = types[$("type").index].pattern;
search(keyword, pattern);
}
}
}
]
});
function search(keyword, pattern) {
const user = $context.link.split("/").pop();
const query = encodeURIComponent(`${keyword} (${pattern}${user})`);
const url = `twitter://search?query=${query}`;
$context.close();
$app.openURL(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment