Skip to content

Commit fe8dffd

Browse files
committed
Original public domain code
0 parents  commit fe8dffd

8 files changed

+89
-0
lines changed

amplifier.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function() {
2+
var amplink = document.querySelector("link[rel='amphtml']");
3+
var canonical = document.querySelector("link[rel='canonical']");
4+
5+
var amp = {
6+
sentinel: "__AMPLIFIER__",
7+
ampurl : null,
8+
canonical : null,
9+
isamp : (document.querySelector("html[amp]") !== null || document.querySelector("html[⚡]") !== null)
10+
};
11+
12+
if (amplink !== null) {
13+
amp.ampurl = amplink.href;
14+
15+
}
16+
if (canonical !== null) {
17+
amp.canonical = canonical.href;
18+
}
19+
20+
21+
chrome.runtime.sendMessage(amp);
22+
23+
})();

amplifier128.png

3.11 KB
Loading

amplifier48.png

724 Bytes
Loading

amplify.png

582 Bytes
Loading

background.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var ampTabs = [];
2+
3+
4+
chrome.runtime.onMessage.addListener(function(amp, sender, sendResponse) {
5+
if (amp.sentinel === undefined || amp.sentinel != "__AMPLIFIER__") {
6+
return; //not from amplifier
7+
}
8+
if (amp.isamp) {
9+
chrome.pageAction.setIcon({tabId:sender.tab.id, path: 'canonical.png'});
10+
chrome.pageAction.setTitle({tabId:sender.tab.id, title: 'Show the Canonical version of this page'});
11+
} else {
12+
chrome.pageAction.setIcon({tabId:sender.tab.id, path: 'amplify.png'});
13+
chrome.pageAction.setTitle({tabId:sender.tab.id, title: 'Show the AMP version of this page'});
14+
}
15+
if(amp.ampurl !== null || (amp.canonical !=null && amp.isamp)) {
16+
chrome.pageAction.show(sender.tab.id);
17+
}
18+
ampTabs[sender.tab.id] = amp;
19+
20+
if (localStorage["devMode"] == "true") {
21+
amp.ampurl += "#development=1";
22+
}
23+
24+
});
25+
26+
//
27+
chrome.pageAction.onClicked.addListener(function(tab){
28+
var amp = ampTabs[tab.id];
29+
if (amp.isamp) {
30+
if (amp.canonical != null) {
31+
chrome.tabs.update(tab.id, { url: amp.canonical });
32+
}
33+
} else {
34+
chrome.tabs.update(tab.id, { url: amp.ampurl });
35+
}
36+
});
37+

canonical.png

574 Bytes
Loading

manifest.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Amplifier AMP/Canonical switcher",
4+
"short_name": "Amplifier",
5+
"description": "Quickly switch between canonical and AMP version of a page",
6+
"version": "0.0.5",
7+
"author": "John Pettitt",
8+
"icons": {
9+
"48": "amplifier48.png",
10+
"128": "amplifier128.png"
11+
},
12+
"background" : {
13+
"scripts": ["background.js"],
14+
"persistent": true
15+
},
16+
"content_scripts": [
17+
{
18+
"matches": ["http://*/*","https://*/*"],
19+
"js": ["amplifier.js"],
20+
"run_at" : "document_end"
21+
}
22+
],
23+
"page_action" :
24+
{
25+
"default_icon" : "switcher.png",
26+
"default_title" : "AMP version not detected."
27+
},
28+
"options_page" : "options.html"
29+
}

switcher.png

734 Bytes
Loading

0 commit comments

Comments
 (0)