Tilawah widget

Build it, preview it and watch the visits. Free and open source.

Language

Put the Tilawah player and surah list inside any website or mobile app. Everything else stays on the main site, one button away.

Give each site or app its own host name (for example my-app). Its visits are counted under that name. Apps must set it themselves, because a WebView sends no referrer.

Website

Script tag (easiest)

Adds the player where the tag is and resizes it to fit the content.

<script src="https://tilawah.shahadot.dev/embed.js" data-host="my-site"></script>

Plain iframe

Set the height yourself, or use the resize message below.

<iframe
  id="tilawah"
  src="https://tilawah.shahadot.dev/embed?host=my-site"
  title="Tilawah"
  allow="autoplay; encrypted-media"
  style="width:100%;max-width:36rem;height:40rem;border:0"
></iframe>

Resize an iframe automatically

The widget tells the page around it how tall it is. Add this next to the iframe.

window.addEventListener("message", (event) => {
  if (event.origin !== "https://tilawah.shahadot.dev") return;
  if (event.data && event.data.type === "tilawah:resize") {
    document.getElementById("tilawah").style.height = event.data.height + "px";
  }
});

Mobile app (WebView)

Open the same page in a WebView. Pass the host name yourself and turn on inline media playback.

React Native

Needs react-native-webview.

import { Linking } from "react-native";
import { WebView } from "react-native-webview";

<WebView
  source={{ uri: "https://tilawah.shahadot.dev/embed?host=my-app" }}
  allowsInlineMediaPlayback
  mediaPlaybackRequiresUserAction={false}
  setSupportMultipleWindows={false}
  onShouldStartLoadWithRequest={(request) => {
    if (request.url.startsWith("https://tilawah.shahadot.dev/embed")) return true;
    Linking.openURL(request.url);
    return false;
  }}
  onMessage={(event) => {
    const message = JSON.parse(event.nativeEvent.data);
    if (message.type === "tilawah:open") Linking.openURL(message.url);
    if (message.type === "tilawah:resize") setHeight(message.height);
  }}
/>

Flutter

Needs webview_flutter and url_launcher. Messages arrive on a channel named Tilawah.

final controller = WebViewController()
  ..setJavaScriptMode(JavaScriptMode.unrestricted)
  ..addJavaScriptChannel('Tilawah', onMessageReceived: (message) {
    final data = jsonDecode(message.message);
    if (data['type'] == 'tilawah:open') launchUrl(Uri.parse(data['url']));
    if (data['type'] == 'tilawah:resize') {
      setState(() => height = (data['height'] as num).toDouble());
    }
  })
  ..loadRequest(Uri.parse('https://tilawah.shahadot.dev/embed?host=my-app'));

// In build(): SizedBox(height: height, child: WebViewWidget(controller: controller))

A tap on a surah starts playback, because phones do not let a page start sound by itself. On iOS, inline playback must be on, as shown.

Options

Add them to the address, or as data- attributes on the script tag. A wrong value falls back to the default. In an address, write # as %23.

OptionValuesDefaultWhat it does
themeauto, light, darkautoauto follows the visitor's device.
langen, bnenLanguage of the widget.
sizefull, compactfullcompact is the player alone, about 24 rem tall.
stylekoi, tilawahkoikoi is the soft mint look; tilawah is the site's own theme.
reciter123, 30, 92, 31, 4123Starting reciter: Mishary Alafasy, Saad Al-Ghamdi, Yasser Al-Dosari, Saud Al-Shuraim, Abu Bakr Al-Shatri. A visitor's own choice is remembered.
accent#13756aby styleButtons, the progress marker and the current surah.
bg#eef6f3by stylePage background. An 8-digit hex can be see-through.
card#ffffffby styleCard background.
text#10251fby styleText colour.
radiussm, md, lgmdCorner roundness.
hostmy-appthe embedding siteThe name visits are counted under.

Messages to the page or app around the widget

A web page receives them with a message listener, React Native in onMessage, and Flutter or Android on a channel named Tilawah.

{ "type": "tilawah:resize", "height": 640 }
The content height changed. Resize the frame to match.
{ "type": "tilawah:open", "url": "https://tilawah.shahadot.dev/…" }
The visitor pressed View full details. Open the address in the system browser.

What is counted

Views (the widget loaded), plays (a surah started, once per surah per load) and clicks (a link to the main site was pressed). A visitor is counted once a day for each host, from a salted hash. No address, cookie or account is stored.