Skip to content

Commit

Permalink
Fixed #103 and remove parse-path
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Oct 28, 2018
1 parent 071b11f commit 70040cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"dateformat": "^3.0.3",
"fast-deep-equal": "^2.0.1",
"merge": "^1.2.0",
"parse-path": "^3.0.4",
"vue": "^2.5.17",
"vue-material": "^1.0.0-beta-10.2",
"webextension-polyfill": "^0.3.1"
Expand Down
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function modifyHeaders(headers, rule, details) {
}
if (hasFunction) {
const detail = {
"id": e.requestId,
"id": details.requestId,
"url": details.url,
"method": details.method,
"isFrame": details.frameId === 0,
Expand Down
3 changes: 1 addition & 2 deletions src/core/rules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import utils from './utils';
import storage from './storage';
import merge from 'merge';
import parsePath from 'parse-path';

const cache = {};
utils.TABLE_NAMES.forEach(t => cache[t] = null);
Expand Down Expand Up @@ -94,7 +93,7 @@ function filter(rules, options) {
result = url.indexOf(rule.pattern) === 0;
break;
case 'domain':
result = parsePath(url).resource === rule.pattern;
result = utils.getDomain(url) === rule.pattern;
break;
case 'url':
result = url === rule.pattern;
Expand Down
7 changes: 7 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,12 @@ export default {
t(key, params) {
const s = browser.i18n.getMessage(key, params)
return s || key;
},
getDomain(url) {
if (url.indexOf("file:") == 0) {
return '';
}
var d = /.*?:\/*([^\/:]+)/.exec(url)[1];
return d;
}
}
18 changes: 14 additions & 4 deletions src/options/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@
<script>
import browser from 'webextension-polyfill';
import merge from 'merge';
import parsePath from 'parse-path';
import utils from '../core/utils';
import rules from '../core/rules';
import file from '../core/file';
Expand Down Expand Up @@ -439,7 +438,7 @@ export default {
isMatch = data.test.indexOf(data.matchRule) === 0 ? 1 : 0;
break;
case 'domain':
isMatch = parsePath(data.test).resource === data.matchRule ? 1 : 0;
isMatch = utils.getDomain(data.test) === data.matchRule ? 1 : 0;
break;
case 'url':
isMatch = data.test === data.matchRule ? 1 : 0;
Expand Down Expand Up @@ -1124,14 +1123,25 @@ export default {
}, { deep: true });
});
// init anti-hot-link
const query = parsePath(location.href).query;
const query = (() => {
const params = {};
const urlParts = location.href.split("?", 2);
if (urlParts.length == 1) {
return params;
}
urlParts[1].split("&").forEach(keyValue => {
const splitKeyValue = keyValue.split("=", 2);
params[decodeURIComponent(splitKeyValue[0])] = decodeURIComponent(splitKeyValue[1]);
});
return params;
})();
if (query.action && query.action === "add-anti-hot-link") {
this.edit.id = -1;
this.edit.name = "";
this.edit.ruleType = 'modifySendHeader';
this.edit.ruleTypeEditable = true;
this.edit.matchType = 'domain';
this.edit.matchRule = parsePath(query.url).resource;
this.edit.matchRule = utils.getDomain(query.url);
this.edit.headerName = "referer";
this.edit.headerValue = "";
this.edit.execType = 0;
Expand Down
20 changes: 0 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3459,13 +3459,6 @@ is-retry-allowed@^1.0.0:
resolved "http://registry.npm.taobao.org/is-retry-allowed/download/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34"
integrity sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=

is-ssh@^1.3.0:
version "1.3.0"
resolved "http://registry.npm.taobao.org/is-ssh/download/is-ssh-1.3.0.tgz#ebea1169a2614da392a63740366c3ce049d8dff6"
integrity sha1-6+oRaaJhTaOSpjdANmw84EnY3/Y=
dependencies:
protocols "^1.1.0"

is-stream@^1.0.0, is-stream@^1.1.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/is-stream/download/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
Expand Down Expand Up @@ -4607,14 +4600,6 @@ parse-json@^2.2.0:
dependencies:
error-ex "^1.2.0"

parse-path@^3.0.4:
version "3.0.4"
resolved "http://registry.npm.taobao.org/parse-path/download/parse-path-3.0.4.tgz#a48b7b529da41f34d9d1428602a39b29fc7180e4"
integrity sha1-pIt7Up2kHzTZ0UKGAqObKfxxgOQ=
dependencies:
is-ssh "^1.3.0"
protocols "^1.4.0"

pascalcase@^0.1.1:
version "0.1.1"
resolved "http://registry.npm.taobao.org/pascalcase/download/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
Expand Down Expand Up @@ -5103,11 +5088,6 @@ promise-inflight@^1.0.1:
resolved "http://registry.npm.taobao.org/promise-inflight/download/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM=

protocols@^1.1.0, protocols@^1.4.0:
version "1.4.6"
resolved "http://registry.npm.taobao.org/protocols/download/protocols-1.4.6.tgz#f8bb263ea1b5fd7a7604d26b8be39bd77678bf8a"
integrity sha1-+LsmPqG1/Xp2BNJri+Ob13Z4v4o=

prr@~1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/prr/download/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
Expand Down

0 comments on commit 70040cd

Please sign in to comment.