Skip to content
This repository has been archived by the owner on Sep 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #34 from keraf/dev
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
keraf authored Sep 24, 2017
2 parents bc2dadf + a832a98 commit ee536b3
Show file tree
Hide file tree
Showing 15 changed files with 1,847 additions and 74 deletions.
102 changes: 99 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ gulp.task('build:copy', () => {
`${srcFolder}/**/*`,
`!${srcFolder}/**/*.js`,
`!${srcFolder}/**/*.css`,
`!${srcFolder}/view/background.html`,
`!${srcFolder}/manifest.json`])
.pipe(gulp.dest(buildFolder));
});

gulp.task('build:copy-edge', () => {
return gulp.src([`${srcFolder}/view/background.html`])
.pipe(gulp.dest(`${buildFolder}/view`));
});

// Transform the manifest
gulp.task('build:manifest', () => {
return gulp.src(`${srcFolder}/manifest.json`)
Expand All @@ -41,6 +47,37 @@ gulp.task('build:manifest', () => {
.pipe(gulp.dest(buildFolder));
});

gulp.task('build:manifest-ff', () => {
return gulp.src(`${srcFolder}/manifest.json`)
.pipe(jeditor({
'version': package.version,
'applications': {
'gecko': {
'id': '{5657c026-efc3-4860-b43b-16e4eaa8a9aa}',
},
},
}))
.pipe(gulp.dest(buildFolder));
});

gulp.task('build:manifest-edge', () => {
return gulp.src(`${srcFolder}/manifest.json`)
.pipe(jeditor({
'version': package.version,
'minimum_edge_version': '33.14281.1000.0',
'-ms-preload': {
'backgroundScript': 'js/backgroundScriptsAPIBridge.js',
'contentScript': 'js/contentScriptsAPIBridge.js',
},
'background': {
'scripts': [],
'page': 'view/background.html',
'persistent': true
},
}))
.pipe(gulp.dest(buildFolder));
});

// Transform the JS files
gulp.task('build:js', () => {
return gulp.src([`${srcFolder}/js/background.js`, `${srcFolder}/js/popup.js`])
Expand All @@ -49,6 +86,13 @@ gulp.task('build:js', () => {
.pipe(gulp.dest(`${buildFolder}/js`));
});

gulp.task('build:js-edge', () => {
return gulp.src([`${srcFolder}/js/backgroundScriptsAPIBridge.js`, `${srcFolder}/js/contentScriptsAPIBridge.js`])
.pipe(babel(babelConfig))
.pipe(uglify())
.pipe(gulp.dest(`${buildFolder}/js`));
});

// Transform the CSS file
gulp.task('build:css', () => {
return gulp.src(`${srcFolder}/styles/popup.css`)
Expand Down Expand Up @@ -82,8 +126,9 @@ gulp.task('pack:chromium', () => {
.pipe(gulp.dest('./dist/chromium'));
});

gulp.task('default', () => {
runSequence(
// Target platforms
gulp.task('chrome', () => {
return runSequence(
'build:clean',
'build:copy',
[
Expand All @@ -92,9 +137,60 @@ gulp.task('default', () => {
'build:css',
],
[
'pack:firefox',
'pack:chrome',
]
);
});

gulp.task('firefox', () => {
return runSequence(
'build:clean',
'build:copy',
[
'build:manifest-ff',
'build:js',
'build:css',
],
[
'pack:firefox',
]
);
});

gulp.task('chromium', () => {
return runSequence(
'build:clean',
'build:copy',
[
'build:manifest',
'build:js',
'build:css',
],
[
'pack:chromium',
]
);
});

gulp.task('edge', () => {
return runSequence(
'build:clean',
'build:copy',
'build:copy-edge',
[
'build:manifest-edge',
'build:js',
'build:js-edge',
'build:css',
]
);
});

gulp.task('default', () => {
return runSequence(
'chrome',
'firefox',
'chromium',
'edge'
);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "no-coin",
"version": "0.3.5",
"version": "0.4.0",
"description": "Stop coin miners on the web!",
"repository": {
"type": "git",
Expand Down
13 changes: 9 additions & 4 deletions src/blacklist.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
https://coin-hive.com/lib*
https://coin-hive.com/captcha*
*://coin-hive.com/lib*
*://coin-hive.com/captcha*
wss://*.coin-hive.com/proxy*
https://jsecoin.com/server*
https://*.jsecoin.com/server*
*://jsecoin.com/server*
*://*.jsecoin.com/server*
*://static.reasedoper.pw/*
*://mataharirama.xyz/*
*://listat.biz/*
*://lmodr.biz/*
*://minecrunch.co/web/*
Binary file modified src/img/logo_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/img/logo_enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/logo_enabled_blocked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/logo_enabled_whitelisted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 58 additions & 11 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ let config = {
...localConfig,
};

/**
* Variables
*/
let domains = [];
let detected = [];

/**
* Functions
*/
Expand Down Expand Up @@ -89,16 +95,38 @@ const runBlocker = (blacklist) => {
const blacklistedUrls = blacklist.split('\n');

chrome.webRequest.onBeforeRequest.addListener(details => {
chrome.browserAction.setBadgeBackgroundColor({
color: [200, 0, 0, 100],
tabId: details.tabId,
});

chrome.browserAction.setBadgeText({
text: '!',
tabId: details.tabId,
});

detected[details.tabId] = true;

// Globally paused
if (!config.toggle) {
return { cancel: false };
}

// Is domain white listed
if (isDomainWhitelisted(domains[details.tabId])) {
chrome.browserAction.setIcon({
path: 'img/logo_enabled_whitelisted.png',
tabId: details.tabId,
});

return { cancel: false };
}

chrome.browserAction.setIcon({
path: 'img/logo_enabled_blocked.png',
tabId: details.tabId,
});

return { cancel: true };
}, {
urls: blacklistedUrls
Expand All @@ -115,11 +143,27 @@ const runFallbackBlocker = () => {
/**
* Main
*/
let domains = [];

// Updating domain for synchronous checking in onBeforeRequest
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
domains[tabId] = getDomain(tab.url);

// Set back to normal when navigating
if (changeInfo === 'loading') {
if (config.toggle) {
chrome.browserAction.setIcon({
path: 'img/logo_enabled.png',
tabId,
});
}

detected[details.tabId] = false;

chrome.browserAction.setBadgeText({
text: '',
tabId,
});
}
});

chrome.tabs.onRemoved.addListener((tabId) => {
Expand All @@ -135,17 +179,17 @@ if (!config.toggle) {
const blacklist = 'https://raw.githubusercontent.com/keraf/NoCoin/master/src/blacklist.txt';
fetch(blacklist)
.then(resp => {
if (resp.status === 200) {
resp.text().then((text) => {
if (text === '') {
runFallbackBlocker();
} else {
runBlocker(text);
}
});
} else {
runFallbackBlocker();
if (resp.status !== 200) {
throw 'HTTP Error';
}

resp.text().then((text) => {
if (text === '') {
throw 'Empty response';
}

runBlocker(text);
});
})
.catch(err => {
runFallbackBlocker();
Expand All @@ -156,7 +200,10 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch (message.type) {
case 'GET_STATE':
sendResponse({
version: chrome.runtime.getManifest().version,
whitelisted: isDomainWhitelisted(domains[message.tabId]),
domain: domains[message.tabId],
detected: detected[message.tabId] || false,
toggle: config.toggle,
});
break;
Expand Down
Loading

1 comment on commit ee536b3

@arthurgeron
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool new features 👍

Please sign in to comment.