Skip to content

Commit 48593da

Browse files
committed
Replaced onRequest and sendRequest with onMessage and sendMessage. Changed background page persistence to true. Made separate popup.js file. Made popup wider. Works in latest Chrome now.
1 parent a29ac51 commit 48593da

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

bg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var selectedItem = null;
44
var selectedId = null;
55

66
function updateItem(tabId) {
7-
chrome.tabs.sendRequest(tabId, {}, function(item) {
7+
chrome.tabs.sendMessage(tabId, {}, function(item) {
88
items[tabId] = item;
99
if (!item) {
1010
chrome.pageAction.hide(tabId);

cs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (window == top) {
2-
chrome.extension.onRequest.addListener(function(req, sender, senderResponse) {
2+
chrome.extension.onMessage.addListener(function(req, sender, senderResponse) {
33
senderResponse(findItemID());
44
});
55
}

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Generate an Amazon affiliate link with one click",
66
"background": {
77
"scripts": ["jq.min.js","bg.js"],
8-
"persistent": false
8+
"persistent": true
99
},
1010
"icons": {
1111
"16": "images/icon_16.png",

popup.html

+3-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<title>Popup</title>
44
<style>
55
body {
6-
width: 300px;
6+
width: 400px;
77
}
88

99
label {
@@ -14,7 +14,7 @@
1414

1515
input[type='text'] {
1616
display: inline-block;
17-
width: 200px;
17+
width: 300px;
1818
}
1919
</style>
2020
</head>
@@ -24,19 +24,5 @@
2424
</body>
2525
<script src="jq.min.js"></script>
2626
<script src="jquery.url.js"></script>
27-
<script>
28-
window.onload = function() {
29-
var item = chrome.extension.getBackgroundPage().selectedItem;
30-
if (item) {
31-
chrome.tabs.getSelected(null, function(tab) {
32-
var tablink = tab.url,
33-
host = $.url(tablink).attr('host'),
34-
link = 'http://' + host + '/dp/' + item + '/?tag='
35-
+ localStorage['trackId'];
36-
console.log(link);
37-
$('#txt').val(link);
38-
});
39-
}
40-
}
41-
</script>
27+
<script src="popup.js"></script>
4228
</html>

popup.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
window.onload = function() {
2+
var item = chrome.extension.getBackgroundPage().selectedItem;
3+
if (item) {
4+
chrome.tabs.getSelected(null, function(tab) {
5+
var tablink = tab.url,
6+
host = $.url(tablink).attr('host'),
7+
link = 'http://' + host + '/dp/' + item + '/?tag='
8+
+ localStorage['trackId'];
9+
console.log(link);
10+
$('#txt').val(link);
11+
});
12+
}
13+
}

0 commit comments

Comments
 (0)