Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added firefox-desktop-amp.xpi
Binary file not shown.
63 changes: 63 additions & 0 deletions firefox-nightly/amp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var docEl = document.documentElement;
var isAMP = docEl.hasAttribute('amp') || docEl.hasAttribute('⚡️');
var observerConfig = { childList: true, subtree: true };

var documentObserver = observeNode(docEl, inspectDocNodes);
var headObserver;


function observeNode(node, cb){
var obs = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
for (var i = 0; i < mutation.addedNodes.length; i++)
cb(mutation.addedNodes[i]);
});
});
obs.observe(node, observerConfig);
return obs;
}

function inspectDocNodes(node){
if (node.tagName == "LINK" && node.getAttribute('rel').toLowerCase() == 'amphtml'){
documentObserver.disconnect();
redirect(node);
}

if (node.tagName != "HEAD") return;

if (isAMP)
applyMobileCSS(node);
else {
queryForMeta(node);
headObserver = observeNode(node, inspectHeadNodes);
documentObserver.disconnect();
// console.log('disconnected from doc')
}
}

function inspectHeadNodes(node) {
// node.nodeType == 1 && console.log(node);
if (node.tagName == "LINK" && node.getAttribute('rel').toLowerCase() == 'amphtml') {
headObserver.disconnect();
redirect(node);
}
// if no match found, headObserver is not disconnected.
}

function queryForMeta(head) {
var node = head.querySelector('link[rel="amphtml"]');
if (node)
redirect(node);
}

function redirect(node) {
window.location = node.getAttribute("href");
}

function applyMobileCSS(node) {
var css = "body > * { max-width: 600px; margin: 0px auto; }";
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
node.appendChild(style);
}
Binary file added firefox-nightly/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox-nightly/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox-nightly/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions firefox-nightly/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"manifest_version": 2,
"name": "⚡️ Desktop AMP",
"description": "Load the AMP version of a page if available",
"version": "1.2",
"author": "Agustin Mendez",

"applications": {
"gecko": {
"id": "desktop-amp@matagus",
"strict_min_version": "42.0.0"
}
},

"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at": "document_start",
"js": ["amp.js"]
}
],

"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
}