I am trying to write a code for Scriptable app that loops through a list of websites and opens them in safari every time I hit the widget. So every tap on the widget should open the next webpage. The code below sometimes does what I need but its very inconsistent. Also I want to add an option to specify what link I start from. If I have 50 weblinks and I processed 20, next time I open scriptable I want to continue from 21.
'''
// List of websites to open
const websites = [
"https://www.google.com",
"https://www.example.com",
"https://www.github.com"
];
async function openWebsite(url) {
Safari.open(url
await new Promise(resolve => Timer.schedule(5, false, resolve));
}
for (let i = 0; i < websites.length; i++) {
await openWebsite(websites[i]);
}
'''