Skip to content

Commit 38877df

Browse files
committed
Initial commit.
Initial commit.
0 parents  commit 38877df

File tree

11 files changed

+194
-0
lines changed

11 files changed

+194
-0
lines changed

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 Rafael Keramidas <ker.af>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# No Coin
2+
No coin is a tiny browser extension aiming to block coin miners such as Coinhive.
3+
4+
![v0.1 demo](https://ker.af/content/images/2017/09/nocoin-v0.1.gif)
5+
6+
You can grab the extension from the Chrome Web Store: https://chrome.google.com/webstore/detail/no-coin/gojamcfopckidlocpkbelmpjcgmbgjcl
7+
8+
Note: This is a very very early version, more features and a nicer design are planned. Also the code was written quite quickly during a [live stream](https://www.twitch.tv/iamkeraf), coming commits should be looking better :-)
9+
10+
### Why?
11+
Even though I think using coin mining in browser to monetize content is a great idea, abusing it is not. Some websites are running it during the entire browsing session which results in high consumption of your computers resources. I do believe that using it occasionally such as for the proof of work of a captcha is OK. But for an entire browsing session, the user should have the choice to opt-in which is the aim of this extension.
12+
13+
### How does it work?
14+
The extension is simply blocking a list of blacklisted domains in *blacklist.txt*. Clicking on the icon will display you a button to pause/unpause No Coin. If you are aware of any scripts or services that provide coin mining the browser, please submit a PR.
15+
16+
## Contribute
17+
Contributions are welcome! Don't hesitate to submit bug fixes, improvements and new features.
18+
19+
Regarding new features, please have a look at the issues first. If a feature you whish to work on is not listed in here, you might want to add an issue first before starting to work on a PR.
20+
21+
22+
*Made by Rafael Keramidas ([@iamkeraf](https://www.twitter.com/iamkeraf) - [ker.af](https://ker.af/)). Image used for logo by [Sandro Pereira](https://www.iconfinder.com/icons/33757/coin_question_icon).*

blacklist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://coin-hive.com/lib*
2+
https://coin-hive.com/captcha*
3+
wss://*.coin-hive.com/proxy*

img/logo.png

19.7 KB
Loading

img/logo_disabled.png

13.6 KB
Loading

js/background.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const defaultConfig = {
2+
toggle: true,
3+
};
4+
5+
const localConfig = JSON.parse(localStorage.getItem('config'));
6+
let config = {
7+
...defaultConfig,
8+
...localConfig,
9+
};
10+
11+
// Functions
12+
const saveConfig = () => {
13+
localStorage.setItem('config', JSON.stringify(config));
14+
};
15+
16+
const changeToggleIcon = (isEnabled) => {
17+
chrome.browserAction.setIcon({
18+
path: `img/${isEnabled ? 'logo' : 'logo_disabled'}.png`,
19+
});
20+
}
21+
22+
// Main
23+
if (!config.toggle) {
24+
changeToggleIcon(false);
25+
}
26+
27+
const blacklist = chrome.runtime.getURL("blacklist.txt");
28+
fetch(blacklist)
29+
.then(resp => {
30+
resp.text()
31+
.then(text => {
32+
const blacklistedUrls = text.split('\r\n');
33+
34+
chrome.webRequest.onBeforeRequest.addListener(details => {
35+
if (!config.toggle) {
36+
return { cancel: false };
37+
}
38+
39+
return { cancel: true };
40+
}, {
41+
urls: blacklistedUrls
42+
}, ['blocking']);
43+
})
44+
.catch(err => {
45+
// TODO: Handle this
46+
console.log(err);
47+
});
48+
})
49+
.catch(err => {
50+
// TODO: Handle this
51+
console.log(err);
52+
});
53+
54+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
55+
switch (message.type) {
56+
case 'GET_STATE':
57+
sendResponse({
58+
toggle: config.toggle,
59+
});
60+
break;
61+
case 'TOGGLE':
62+
config.toggle = !config.toggle;
63+
saveConfig();
64+
changeToggleIcon(config.toggle);
65+
sendResponse(config.toggle);
66+
break;
67+
}
68+
});

js/jquery.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/popup.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$(() => {
2+
3+
const setToggleText = (isEnabled) => {
4+
if (isEnabled) {
5+
$('.toggle').addClass('enabled');
6+
} else {
7+
$('.toggle').removeClass('enabled');
8+
}
9+
10+
$('.toggle').text(isEnabled ? 'Pause NoCoin' : 'Unpause NoCoin');
11+
}
12+
13+
chrome.runtime.sendMessage({ type: 'GET_STATE' }, (response) => {
14+
setToggleText(response.toggle);
15+
});
16+
17+
$('.toggle').click(() => {
18+
chrome.runtime.sendMessage({ type: 'TOGGLE' }, (response) => {
19+
setToggleText(response);
20+
});
21+
});
22+
23+
});

manifest.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "No Coin",
3+
"description": "Stop coin miners on the web!",
4+
"version": "0.1",
5+
"permissions": [
6+
"activeTab",
7+
"tabs",
8+
"<all_urls>",
9+
"webRequest",
10+
"webRequestBlocking"
11+
],
12+
"background": {
13+
"scripts": ["js/background.js"],
14+
"persistent": true
15+
},
16+
"icons": {
17+
"128": "img/logo.png"
18+
},
19+
"browser_action": {
20+
"default_title": "No Coin - Stop coin miners on the web.",
21+
"default_icon": "img/logo.png",
22+
"default_popup": "view/popup.html"
23+
},
24+
"manifest_version": 2,
25+
"minimum_chrome_version": "55",
26+
"author": "Rafael Keramidas"
27+
}

styles/popup.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
width: 120px;
3+
margin: 10px;
4+
}
5+
6+
.logo {
7+
height: 20px;
8+
}
9+
10+
.title {
11+
display: inline;
12+
}
13+
14+
.toggle {
15+
margin-top: 5px;
16+
background-color: green;
17+
border: none;
18+
color: white;
19+
padding: 5px 8px;
20+
}
21+
22+
.enabled {
23+
background-color: red;
24+
}

view/popup.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<title>No Coin</title>
4+
5+
<link rel="stylesheet" type="text/css" href="../styles/popup.css" />
6+
7+
<script src="../js/jquery.min.js"></script>
8+
<script src="../js/popup.js"></script>
9+
</head>
10+
<body>
11+
<img src="../img/logo.png" class="logo" />
12+
<h1 class="title">No Coin</h1>
13+
14+
<button class="toggle">Enable No Coin</button>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)