Skip to content

Commit d6ba79b

Browse files
authored
Merge pull request #9 from Nullifiers/shortcut
Keyboard Shortcut
2 parents 79133e6 + d74b658 commit d6ba79b

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# Realtime-Currency-Convertor
2-
Browser Extension to convert foreign currency to local currency, realtime.
2+
3+
Browser Extension to convert foreign currency to local currency, real time.
4+
5+
## How to use:-
6+
7+
- Navigate to any page which has a different currency mentioned in its article body, for example in [this](https://www.smartprix.com/bytes/samsung-galaxy-note-10-realme-5-pro-realme-5-mi-a3-launch-in-india-next-week-heres-what-to-expect/) article the prices are mentioned in dollars and we want them in say Rupees.
8+
9+
- There are two ways to get the currency converted in your desired currency with its real time conversion rate:-
10+
1. Simply press the extension icon and your converted currency will be highlighted in the article.
11+
12+
2. Press the combo of `Ctrl+Shift+K` in the case of Windows/Linux or `Cmd+Shift+K` in the case of Mac computers to get the same result as in 1st case.

src/js/background.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
chrome.browserAction.onClicked.addListener((tab) => {
2-
chrome.tabs.executeScript(tab.id, {
1+
function executeScript(id) {
2+
chrome.tabs.executeScript(id, {
33
runAt: 'document_end',
44
allFrames: true,
55
file: 'js/contentScript.js',
66
});
7-
});
7+
}
8+
9+
chrome.browserAction.onClicked.addListener(tab => executeScript(tab.id));
10+
11+
chrome.commands.onCommand.addListener(command => {
12+
if (command !== "convert_currency") {
13+
return;
14+
}
15+
chrome.tabs.query({
16+
active: true,
17+
currentWindow: true
18+
}, tabs => executeScript(tabs[0].id));
19+
});

src/js/contentScript.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function() {
1+
(function () {
22
function replace($node, regex, replaceMethod) {
33
const queue = [$node];
44
while (queue.length) {
@@ -15,8 +15,7 @@
1515

1616
if (top.nodeType === Node.ELEMENT_NODE && regex.test(top.innerHTML)) {
1717
top.innerHTML = top.innerHTML.replace(regex, replaceMethod.bind(top));
18-
}
19-
else if (top.nodeType === Node.TEXT_NODE && regex.test(top.nodeValue)) {
18+
} else if (top.nodeType === Node.TEXT_NODE && regex.test(top.nodeValue)) {
2019
top.nodeValue = top.nodeValue.replace(regex, replaceMethod.bind(top));
2120
}
2221
}
@@ -29,7 +28,10 @@
2928
const currencySymbols = ['\\$', '€'];
3029
const currencyRegex = new RegExp(`(${currencySymbols.join('|')})\\s?(\\d+(?:,\\d{2,3})*(?:\\.\\d+)?)`, 'g');
3130

32-
const INR = new Intl.NumberFormat('en-IN', {style: 'currency', currency: 'INR'});
31+
const INR = new Intl.NumberFormat('en-IN', {
32+
style: 'currency',
33+
currency: 'INR'
34+
});
3335

3436
const spanStyle = 'background: rgba(220, 220, 220, 0.7); color: #333; padding: 2px 5px; border-radius: 3px';
3537
const format = price => `<span style="${spanStyle}">${INR.format(price)}</span>`;
@@ -42,4 +44,4 @@
4244
format(toRupeeRatio[currency] * numval) :
4345
INR.format(toRupeeRatio[currency] * numval);
4446
});
45-
})();
47+
})();

src/manifest.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
"manifest_version": 2,
33
"name": "Realtime Currency Converter",
44
"version": "0.0.2",
5-
"description": "Browser Extenstion to convert foreign currency to local currency, realtime.",
5+
"description": "Browser Extension to convert foreign currency to local currency, realtime.",
66
"browser_action": {},
77
"background": {
88
"scripts": ["js/background.js"],
99
"persistent": false
1010
},
11+
"commands": {
12+
"convert_currency": {
13+
"suggested_key": {
14+
"default": "Ctrl+Shift+K",
15+
"mac": "Command+Shift+K"
16+
},
17+
"description": "Currency Convertor Shortcut"
18+
}
19+
},
1120
"permissions": ["activeTab", "storage"]
1221
}

0 commit comments

Comments
 (0)