From 0e99ab3f502b4f1d70563fbf2eeea8bf93328b45 Mon Sep 17 00:00:00 2001 From: Marc Boucher <40043075+Procyon-b@users.noreply.github.com> Date: Fri, 27 Sep 2019 21:38:09 +0200 Subject: [PATCH 1/8] background.js : store/retrieve dyn-sites settings --- src/background.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/background.js diff --git a/src/background.js b/src/background.js new file mode 100644 index 0000000..de52277 --- /dev/null +++ b/src/background.js @@ -0,0 +1,82 @@ +"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 Date: Fri, 27 Sep 2019 21:38:54 +0200 Subject: [PATCH 2/8] Create options.html --- src/options.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/options.html diff --git a/src/options.html b/src/options.html new file mode 100644 index 0000000..2eb967b --- /dev/null +++ b/src/options.html @@ -0,0 +1,44 @@ + + + + + +

Sites fixed with mutations observers

+One hostname per line. The format is:
+
  hostname [!] ["selector(s)"] [parentNode/nextElementSibling/previousElementSibling] [another:pN/nES/pES]
+ +
+
+
+ + + + From 5099eba8e7e643de51863a5c2f9ac24d198cec87 Mon Sep 17 00:00:00 2001 From: Marc Boucher <40043075+Procyon-b@users.noreply.github.com> Date: Fri, 27 Sep 2019 21:39:23 +0200 Subject: [PATCH 3/8] Create options.js --- src/options.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/options.js diff --git a/src/options.js b/src/options.js new file mode 100644 index 0000000..1f952e2 --- /dev/null +++ b/src/options.js @@ -0,0 +1,38 @@ +"use strict"; + +var TA=document.getElementById('list'), b=document.getElementById('b'), def=document.getElementById('def'), bg=chrome.extension.getBackgroundPage(); + +var LS=localStorage.sitesWMut; + +TA.value=LS; +def.value+=toStr(bg.defSitesWMut,1); +def.style.height=def.scrollHeight+4+'px'; + +// Convert array of values back to string. Including comments +function toStr(a,raw) { + var r='', h; + for (let k in a) { + if (!raw && a[k].txt === undefined) continue; + if (a[k].cmt) { + r+=a[k].txt+'\n'; + continue; + } + h=a[k].k || k; + r+=h; + if (a[h].null) r+=' null'; + else for (let e,i=0; e=a[h][i]; i++) { + if (i==0) e=(a[h].fb?'! ':'')+'"'+e+'"'; + r+=' '+e; + } + r+='\n' + } + return r; +} + +// Validate current config using the background page function - save - and reload data +b.onclick=function(){ + var s=toStr( bg.toAr(TA.value, 1) ).replace(/\n+$/,'\n'); + TA.value=s; + localStorage.setItem('sitesWMut', s); + bg.getStor(); + }; From e1f0f23bfa11b16151b11eedc1b3759fdb1e6895 Mon Sep 17 00:00:00 2001 From: Marc Boucher <40043075+Procyon-b@users.noreply.github.com> Date: Fri, 27 Sep 2019 21:49:58 +0200 Subject: [PATCH 4/8] implementing dyn-sites handling - content.js Retrieves settings from the background page If site matches, Search for element and attach a mutation observer. The observer reapplies the fix when it detects addition of a
element. --- src/content.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/content.js b/src/content.js index f9f2881..2357673 100644 --- a/src/content.js +++ b/src/content.js @@ -2,6 +2,8 @@ const DEBUG=false; let numseen=0, numspoiled=0; let unspoiled=[]; +var sitesWMut={}; + // called when the user clicks an element of the form (any field or button). // The parameter passed is the event object. function clickApply(e) { @@ -61,7 +63,61 @@ function spoilFormGet(elem) { } } //spoilFormGet -var debugAutoDetect=0; +var debugAutoDetect=0, mutInst=false; + +function parseMut(mutL) { + if(DEBUG) console.info('mutations...',mutL); + for (var mut of mutL) { + if (mut.type == 'childList' && mut.addedNodes.length) { + let e,i; + for (i=0; e=mut.addedNodes[i]; i++) { + if (e.nodeType==1 && e.querySelector('form')) { + if(DEBUG) console.info('form added'); + autoDetect(true,'Mutation'); + return; + } + } + } + } +} + +function addMut() { + if (mutInst) return; + mutInst=true; + var isMut=sitesWMut[location.host]; + if (!isMut) return; + + const obs = new MutationObserver(parseMut); + var a=[], config={ attributes: false, childList: true, subtree: true, characterData: false }; + if (isMut[0]) { + try{ + a=document.querySelectorAll(isMut[0]); + } + catch(e){ + if(DEBUG) console.info('observer not attached - error: %c%s','color:red;',e.message); + return; + } + } + if (a.length) { + for (let e,i=0; e=a[i]; i++) { + if(DEBUG) console.info('observer looked for ', {e},e ); + for (let j=1,s; s=isMut[j]; j++) { + if (s=='parentNode' || s=='pN') e=e.parentNode; + else if (s=='nextElementSibling' || s=='nES') e=e.nextElementSibling || e; + else if (s=='previousElementSibling' || s=='pES') e=e.previousElementSibling || e; + } + if(DEBUG) console.info('observer attached on ', {e},e ); + obs.observe(e, config ); + } + } + else if (isMut.fb || !isMut.length) { + if(DEBUG) console.info('observer on body'); + obs.observe(document.body, config ); + } + else if(DEBUG) console.info('observer not attached'); +} + + // move this part of the code here, since it's called multiple times function autoDetect(now, when_called) { @@ -72,6 +128,8 @@ function autoDetect(now, when_called) { if (unspoiled.length) console.log(unspoiled); } + if (now && !mutInst) addMut(); + // we reset spoil vars for next call numseen=0; numspoiled=0; @@ -125,6 +183,13 @@ function onDOMContentLoaded() { } //onDOMContentLoaded +chrome.runtime.sendMessage({host: location.host}, function(response) { + if(DEBUG) console.info('site config', response); + if (response.siteMut) { + sitesWMut[location.host]=response.siteMut; + } +}); + document.addEventListener('DOMContentLoaded', onDOMContentLoaded); // vi: set ts=4 sts=4 sw=4 et ai: // From d14375e2d8484d321f6e4284523d352d8dd5e9f3 Mon Sep 17 00:00:00 2001 From: Marc Boucher <40043075+Procyon-b@users.noreply.github.com> Date: Fri, 27 Sep 2019 21:53:21 +0200 Subject: [PATCH 5/8] Add bg and options pages add background.js, removing reference to bg.js add options page bump minor version number. --- src/manifest.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 44142cc..7c9bd68 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,11 +2,12 @@ "author": "Greg Sadetsky et al.", "manifest_version": 2, "name": "Don't add custom search engines", - "version": "0.0.6", + "version": "0.0.6.1", "description": "Prevent Google Chrome from auto-adding custom search engines", "homepage_url": "https://github.com/gregsadetsky/chrome-dont-add-custom-search-engines", "minimum_chrome_version": "49.0.0.0", "offline_enabled": true, + "options_page": "options.html", "content_scripts": [ { "matches": [""], @@ -15,7 +16,7 @@ } ], "background": { - "scripts": ["bg.js"] + "scripts": ["background.js"] }, "icons": { "64": "icon-64.png", From db96ef07b69318bf1271c167b467344ab8d782f3 Mon Sep 17 00:00:00 2001 From: Chris White Date: Sat, 23 Nov 2019 19:33:24 -0500 Subject: [PATCH 6/8] Added package.json; removed dead bg.js - Added package.json so we can use NPM tools during development. This project does not run under Node or require any NPM modules to function. - Removed bg.js, no longer referenced --- package-lock.json | 236 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 22 +++++ src/bg.js | 10 -- 3 files changed, 258 insertions(+), 10 deletions(-) create mode 100755 package-lock.json create mode 100755 package.json delete mode 100644 src/bg.js diff --git a/package-lock.json b/package-lock.json new file mode 100755 index 0000000..cd577cd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,236 @@ +{ + "name": "chrome-dont-add-custom-search-engines", + "version": "0.0.6", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "config-chain": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", + "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", + "dev": true, + "requires": { + "ini": "^1.3.4", + "proto-list": "~1.2.1" + } + }, + "editorconfig": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", + "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", + "dev": true, + "requires": { + "commander": "^2.19.0", + "lru-cache": "^4.1.5", + "semver": "^5.6.0", + "sigmund": "^1.0.1" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "ini": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "dev": true + }, + "js-beautify": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.10.2.tgz", + "integrity": "sha512-ZtBYyNUYJIsBWERnQP0rPN9KjkrDfJcMjuVGcvXOUJrD1zmOGwhRwQ4msG+HJ+Ni/FA7+sRQEMYVzdTQDvnzvQ==", + "dev": true, + "requires": { + "config-chain": "^1.1.12", + "editorconfig": "^0.15.3", + "glob": "^7.1.3", + "mkdirp": "~0.5.1", + "nopt": "~4.0.1" + } + }, + "lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "nopt": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", + "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "dev": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "dev": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "proto-list": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", + "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=", + "dev": true + }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100755 index 0000000..11673bb --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/bg.js b/src/bg.js deleted file mode 100644 index 3835ef5..0000000 --- a/src/bg.js +++ /dev/null @@ -1,10 +0,0 @@ -chrome.runtime.onMessage.addListener( - function(request, sender, sendResponse) { - if(request !== "opensearch-block") { - return; - } - chrome.browserAction.setBadgeText({ - text: '1', - tabId: sender.tab.id - }); -}); From 818ea8d8896808b5208d249cc05f756d3b14899c Mon Sep 17 00:00:00 2001 From: Chris White Date: Sat, 23 Nov 2019 19:54:59 -0500 Subject: [PATCH 7/8] Added beautification script Added js-beautify for consistent JS, HTML, and CSS formatting. Also, added .editorconfig file to maintain consistency in supported editors. --- .editorconfig | 7 +++++++ README.md | 9 ++++++++- beautify.sh | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 .editorconfig create mode 100755 beautify.sh diff --git a/.editorconfig b/.editorconfig new file mode 100755 index 0000000..2e9bbba --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root=true + +[*] +end_of_line = LF +indent_size = 4 +indent_style = space +insert_final_newline = true diff --git a/README.md b/README.md index afad90f..a678c37 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/beautify.sh b/beautify.sh new file mode 100755 index 0000000..b20ddaf --- /dev/null +++ b/beautify.sh @@ -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 From 60ed9fa2ac46ff87654c6a8837ffaa7e181f3744 Mon Sep 17 00:00:00 2001 From: Chris White Date: Sat, 23 Nov 2019 19:56:11 -0500 Subject: [PATCH 8/8] Beautify - whitespace changes only No functional changes. Just ran everything through beautify.sh. --- src/background.js | 129 ++++++++++++++++++++----------------- src/content.js | 161 ++++++++++++++++++++++++++-------------------- src/manifest.json | 2 +- src/options.html | 71 +++++++++++--------- src/options.js | 61 ++++++++++-------- 5 files changed, 235 insertions(+), 189 deletions(-) diff --git a/src/background.js b/src/background.js index de52277..fd69c98 100644 --- a/src/background.js +++ b/src/background.js @@ -1,70 +1,81 @@ "use strict"; -var defSitesWMut={ - 'www.nytimes.com': ['.css-10488qs'], - 'www.brico.be': ['.mxd-search-initial', 'pN', 'pN'] - }; -var sitesWMut={}; +var defSitesWMut = { + 'www.nytimes.com': ['.css-10488qs'], + 'www.brico.be': ['.mxd-search-initial', 'pN', 'pN'] +}; +var sitesWMut = {}; -var expire=90000; +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*\/\/.*|)$/; +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 element function applyFix(elem) { - var newelem = document.createElement('textarea'); - newelem.name = ''; - newelem.style.display='none'; - elem.appendChild(newelem); + var newelem = document.createElement('textarea'); + newelem.name = ''; + newelem.style.display = 'none'; + elem.appendChild(newelem); } //applyFix // Add an extra child input to any form that only has one function spoilFormGet(elem) { - if(DEBUG) { + if (DEBUG) { ++numseen; unspoiled.push(elem); } @@ -32,16 +35,16 @@ function spoilFormGet(elem) { // A missing or relative action will be resolved against the page URL // so it must have the same URI scheme which is all we care about var action = elem.getAttribute('action'); - if(!(action && action.indexOf('://') >= 0)) action = location.href; - if(!/^https?:\/\//i.test(action)) return; + if (!(action && action.indexOf('://') >= 0)) action = location.href; + if (!/^https?:\/\//i.test(action)) return; // Autodetection requires exactly one input of type text or search // If the type attribute is missing, it defaults to `text` // Readonly inputs do not count against this total - if(elem.querySelectorAll(':scope input:-webkit-any([type="text" i],[type="search" i],[type*="search" i],[type=""],:not([type])):not([readonly])[name]:not([name=""])').length !== 1) return; + if (elem.querySelectorAll(':scope input:-webkit-any([type="text" i],[type="search" i],[type*="search" i],[type=""],:not([type])):not([readonly])[name]:not([name=""])').length !== 1) return; // Autodetection also requires no password, file, or textarea elements - if(elem.querySelector(':scope :-webkit-any(input[type="password" i],input[type="file" i],textarea)')) return; + if (elem.querySelector(':scope :-webkit-any(input[type="password" i],input[type="file" i],textarea)')) return; // Add a
-
- - +
+ + + diff --git a/src/options.js b/src/options.js index 1f952e2..9de2b77 100644 --- a/src/options.js +++ b/src/options.js @@ -1,38 +1,43 @@ "use strict"; -var TA=document.getElementById('list'), b=document.getElementById('b'), def=document.getElementById('def'), bg=chrome.extension.getBackgroundPage(); +var TA = document.getElementById('list'), + b = document.getElementById('b'), + def = document.getElementById('def'), + bg = chrome.extension.getBackgroundPage(); -var LS=localStorage.sitesWMut; +var LS = localStorage.sitesWMut; -TA.value=LS; -def.value+=toStr(bg.defSitesWMut,1); -def.style.height=def.scrollHeight+4+'px'; +TA.value = LS; +def.value += toStr(bg.defSitesWMut, 1); +def.style.height = def.scrollHeight + 4 + 'px'; // Convert array of values back to string. Including comments -function toStr(a,raw) { - var r='', h; - for (let k in a) { - if (!raw && a[k].txt === undefined) continue; - if (a[k].cmt) { - r+=a[k].txt+'\n'; - continue; - } - h=a[k].k || k; - r+=h; - if (a[h].null) r+=' null'; - else for (let e,i=0; e=a[h][i]; i++) { - if (i==0) e=(a[h].fb?'! ':'')+'"'+e+'"'; - r+=' '+e; - } - r+='\n' +function toStr(a, raw) { + var r = '', + h; + for (let k in a) { + if (!raw && a[k].txt === undefined) continue; + if (a[k].cmt) { + r += a[k].txt + '\n'; + continue; + } + h = a[k].k || k; + r += h; + if (a[h].null) r += ' null'; + else + for (let e, i = 0; e = a[h][i]; i++) { + if (i == 0) e = (a[h].fb ? '! ' : '') + '"' + e + '"'; + r += ' ' + e; + } + r += '\n' } - return r; + return r; } // Validate current config using the background page function - save - and reload data -b.onclick=function(){ - var s=toStr( bg.toAr(TA.value, 1) ).replace(/\n+$/,'\n'); - TA.value=s; - localStorage.setItem('sitesWMut', s); - bg.getStor(); - }; +b.onclick = function() { + var s = toStr(bg.toAr(TA.value, 1)).replace(/\n+$/, '\n'); + TA.value = s; + localStorage.setItem('sitesWMut', s); + bg.getStor(); +};