Skip to content

Instantly share code, notes, and snippets.

View digitarald's full-sized avatar
🏳️‍🌈

Harald Kirschner digitarald

🏳️‍🌈
View GitHub Profile
@digitarald
digitarald / gist:9841c88f9398f4aa4dc9
Created November 21, 2014 04:40
Redirect from your Firefox OS packaged app to desktop website
if (!(/mobile|tablet/i).test(navigator.userAgent)) {
location.href = 'http://www.your-desktop-version.com/';
}
@digitarald
digitarald / load-me-before-all.js
Created November 17, 2014 21:30
SystemXHR Everywhere Monkeypatch
// Monkeypatch XHR to always use systemXHR
var oldXMLHttpRequest = XMLHttpRequest;
XMLHttpRequest = function() {
return new oldXMLHttpRequest({
mozSystem: true
});
};
@digitarald
digitarald / detectInstallOrigin.js
Created October 17, 2014 18:06
Detect installOrigin in Firefox apps to defer preload status.
/**
* Detect installOrigin in Firefox apps to defer preload status.
*
* For most apps the installOrigin will be https://marketplace.firefox.com
* Preloaded apps *can* customize their installOrigin to reflect country and/or
* carrier (like https://fxos.telefonia.es for Telefónica in Spain).
*
* @param {Function} done Node-style callback (err, origin)
* @example
@digitarald
digitarald / index.html
Last active August 29, 2015 14:00
famo.us benchmark, 99 surfaces rotated by easing
<!DOCTYPE HTML>
<html>
<head>
<title>Famous test</title>
<meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
</head>
<body>
@digitarald
digitarald / index.html
Last active August 29, 2015 14:00
Benchmark for setting transform styles from a 3d matrix
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Famous test</title>
<meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no" />
<style>
html, body {
margin: 0;
padding: 0;
[
{
"app_name": "connecta2",
"is_packaged": true,
"app_manifest": "https://marketplace.firefox.com/app/956189a1-c985-4824-85a9-de708d38d6f9/manifest.webapp"
},
{
"app_name": "whatsapp-firefox-os",
"is_packaged": true,
"app_manifest": "https://marketplace.firefox.com/app/90aa85eb-60f0-4e58-8147-558e162fac1c/manifest.webapp"
@digitarald
digitarald / verifyMozAppsInstallation.js
Last active December 30, 2015 12:59
Move existing installations for Facebook from HTTP to HTTPS
function verifyMozAppsInstallation() {
if (!navigator.mozApps || window.locationbar.visible) {
// Not running as Firefox app
return;
}
// Prevent multiple checks per day
// FIXME: Use a time-limited cookie
if (localStorage.mozAppsChecked) {
console.log('Skipped verifyMozAppsInstallation');
@digitarald
digitarald / detectByConnection.js
Created December 6, 2013 18:21
Using mozMobileConnections with MNC and MCC to enable app features for specific country/carrier combinations
var mccs = [];
try {
// navigator.mozMobileConnections is the new API.
// navigator.mozMobileConnection is the legacy API.
var conn;
if ((conn = navigator.mozMobileConnection)) {
console.log('navigator.mozMobileConnection available');
// `MCC`: Mobile Country Code
@digitarald
digitarald / 1-moz-mobile-connection-snippet.js
Last active December 18, 2015 03:19
Detect carrier and region from `mozMobileConnection`'s `MNC` and `MCC`
// Original https://github.com/mozilla/fireplace/blob/c50b5ca51643f13ae2e8b3a003d3aa0432358bf7/hearth/media/js/user.js#L41
// Retrieve MCC and MNC from mozMobileConnection (requires "privileged" app type and "mobileconnection" permission)
// and translates them to carrier and region via mobilenetwork.js
try {
// When Fireplace is served as a privileged packaged app (and not
// served via Yulelog) our JS will have direct access to this API.
var conn = navigator.mozMobileConnection;
if (conn) {
@digitarald
digitarald / language-detect.js
Last active December 17, 2015 04:19
Detect language changes when switching to app. I personally recommend setting current language only on app launch. Reacting to changes later benefits only a small set of users, focus on the 99%!
// Example code, use with caution!
// Events and .hidden property requires no prefix since 18
// Set current language on launch
document.documentElement.lang = navigator.language;
function visibilityChange() {
// user went off page, ignore
if (document.hidden) return;