Skip to content

Commit 8e48e0f

Browse files
committed
Fix amp urls which do not have origin (they are path only)
1 parent 74c2946 commit 8e48e0f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

amplifier.js

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ chrome.runtime.sendMessage({
4444
method: "clear"
4545
});
4646

47+
chrome.runtime.sendMessage({
48+
sentinel: "__SIMPLIFYMESSAGE__",
49+
method: "origin",
50+
data: location.origin
51+
})
52+
4753
// look for amp header
4854
chrome.runtime.sendMessage({
4955
sentinel: "__SIMPLIFYMESSAGE__",

background.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function processTabState(tabId, senderUrl) {
174174
console.log("setting previous url to " + senderUrl);
175175
setTabStatus(tabStatus, function() {
176176
working = false;
177-
chrome.tabs.update(tabId, { url : status.ampUrl });
177+
chrome.tabs.update(tabId, { url : status.ampUrl.startsWith('/') ? (status['origin'] + status.ampUrl) : status.ampUrl });
178178
});
179179
} else {
180180
updatePageActionIcon(tabId, senderUrl, status);
@@ -236,6 +236,18 @@ function handleClear(sender) {
236236
});
237237
}
238238

239+
function handleOrigin(tabId, origin) {
240+
checkAndWork(function() {
241+
getTabStatus(function(tabStatus) {
242+
var status = tabId in tabStatus ? tabStatus[tabId] : {};
243+
status['origin'] = origin;
244+
console.log('got new origin ' + origin);
245+
tabStatus[tabId] = status;
246+
setTabStatus(tabStatus, function() { working = false });
247+
});
248+
});
249+
}
250+
239251
function handleGetBack(sender, callback) {
240252
var theurl = sender.url;
241253
checkAndWork(function() {
@@ -295,6 +307,9 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
295307
case "clear":
296308
handleClear(sender);
297309
break;
310+
case "origin":
311+
handleOrigin(sender.tab.id, message.data);
312+
break;
298313
case "onAmpPage":
299314
handleOnAmpPage(sender, message.data);
300315
break;

0 commit comments

Comments
 (0)