Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root=true

[*]
end_of_line = LF
indent_size = 4
indent_style = space
insert_final_newline = true
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ Additional contributors (in alphabetical order):
## License

[CC-BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/legalcode).
See [LICENSE.txt](LICENSE.txt) or the
See [LICENSE.txt](LICENSE.txt) or the
[summary](https://creativecommons.org/licenses/by-sa/3.0/).

## Developing

We welcome issues and pull requests! The main files are
`src/background.js` and `src/content.js`. Before committing changes, please
run `./beautify.sh` to pretty-print the source. This reduces the number
of whitespace changes and makes it easier to focus on the substance of PRs.
9 changes: 9 additions & 0 deletions beautify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -o errexit
set -o pipefail
shopt -s nullglob

for f in src/*.js src/*.css src/*.htm* ; do
echo "$f"
npx js-beautify --editorconfig -r "$f"
done
236 changes: 236 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "chrome-dont-add-custom-search-engines",
"version": "0.0.6",
"description": "Google Chrome extension that stops sites from adding custom search engines",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gregsadetsky/chrome-dont-add-custom-search-engines.git"
},
"author": "",
"license": "CC-BY-SA-3.0",
"bugs": {
"url": "https://github.com/gregsadetsky/chrome-dont-add-custom-search-engines/issues"
},
"homepage": "https://github.com/gregsadetsky/chrome-dont-add-custom-search-engines#readme",
"devDependencies": {
"js-beautify": "^1.10.2"
}
}
93 changes: 93 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use strict";

var defSitesWMut = {
'www.nytimes.com': ['.css-10488qs'],
'www.brico.be': ['.mxd-search-initial', 'pN', 'pN']
};
var sitesWMut = {};

var expire = 90000;

// parse stored data (string) and populate array
// "text" is used when called from the options page (regenerates string version of data with valid syntax, and keeps comments)
function toAr(v, text) {
var r = {},
t = {},
n, RE = /^\s*(\S+)\s*(.*)$/,
RE2 = /^(?:"([^"]*?)"|(.+?))(?:\s+(\S.*))?\s*$/,
REcmt = /^(\s*\/\/.*|)$/;

v = v.split('\n');
for (let i = 0; i < v.length; i++) {
if (text) {
n = 'cmt' + i;
r[n] = {
txt: v[i].replace(/^\s+/, '')
};
}

if (REcmt.test(v[i])) {
if (text) r[n].cmt = 1;
continue;
}
if (!RE.test(v[i])) continue;

var k = RegExp.$1;

if (text && r[k]) {
r[r[k].n].cmt = 1;
}

if (text) {
r[k] = {
n
};
r[n].k = k;
} else r[k] = {};

if (RegExp.$2 == 'null') {
if (text) r[k].null = 1;
else r[k] = 0;
continue;
}
var a = [],
j = 20,
s = RegExp.$2;
while (j-- && RE2.test(s)) {
s = RegExp.$3;
a.push(RegExp.$1 || RegExp.$2);
}
if (a[0] == '!') {
r[k].fb = 1;
a.shift();
}
r[k].length = a.length;
Object.assign(r[k], a);
if (text) {
Object.assign(r[n], a);
r[n].length = a.length;
}
}
return r;
}

function getStor() {
var s = toAr(localStorage.sitesWMut || '');
sitesWMut = JSON.parse(JSON.stringify(defSitesWMut));
for (var k in s) {
sitesWMut[k] = s[k];
}
}

getStor();

// receive messages from contentscript
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (sender.id != chrome.runtime.id) return; // not from this extension
if (request.host) {
let s, r = {};
if (s = sitesWMut[request.host]) r.siteMut = s;
sendResponse(r);
}
});
10 changes: 0 additions & 10 deletions src/bg.js

This file was deleted.

Loading