Skip to content

Commit

Permalink
#28, #29
Browse files Browse the repository at this point in the history
  • Loading branch information
erosman authored Sep 25, 2023
1 parent 59e6612 commit e19f4d9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/content/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<h2 id="changelog">Changelog</h2>
<dl>
<dt>8.1</dt>
<dd></dd>
<dd>Added Drag and Drop sorting of proxies (#29)</dd>
<dd>Fixed a pattern conversion issue (#28)</dd>



Expand Down Expand Up @@ -74,4 +75,4 @@ <h2 id="credits">Credits</h2>
<img src="../image/logo.svg" style="width: 5em;" alt="">
</article>
</body>
</html>
</html>
41 changes: 34 additions & 7 deletions src/content/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ export class Migrate {
5: 'direct' // PROXY_TYPE_NONE
};

const patternSet = {
1: 'wildcard',
2: 'regex'
};

// new database format
let mode = pref.mode || 'disable';
pref.mode === 'disabled' && (pref.mode = 'disable'); // rename disabled -> disable
Expand Down Expand Up @@ -177,6 +172,8 @@ export class Migrate {
pac: '' // add PAC option
};

pxy.cc === 'UK' && (pxy.cc = 'GB'); // convert UK to ISO 3166-1 GB

// --- type 'direct'
pxy.type === 'direct' && (pxy.hostname = 'DIRECT');

Expand All @@ -189,10 +186,18 @@ export class Migrate {
// "protocols": 1,
},
*/

const patternSet = {
1: 'wildcard',
2: 'regex'
};
// process include/exclude
[...pxy.include, ...pxy.exclude].forEach(item => {
item.type = patternSet[item.type]; // convert to actual type: wildcard | regex
item.pattern = this.convertPattern(item.pattern, item.protocols); // convert all | http | https to v3 patterns

// convert wildcard all | http | https to v3 patterns
item.pattern = item.type === 'wildcard' ?
this.convertWildcard(item.pattern, item.protocols) : this.convertRegEx(item.pattern, item.protocols);
delete item.protocols; // no longer needed

// Validate RegExp, deactivate on error
Expand All @@ -210,7 +215,7 @@ export class Migrate {
*.bbc.co.uk exact domain and all subdomains
**.bbc.co.uk subdomains only (not bbc.co.uk)
*/
static convertPattern(pat, protocol) {
static convertWildcard(pat, protocol) {
const protocolSet = {
1: '*://', // all
2: 'http://', // http
Expand All @@ -219,4 +224,26 @@ export class Migrate {

return protocolSet[protocol] + (pat[0] === '.' ? '*' : '') + pat + '/';
}

static convertRegEx(pat, protocol) {
const protocolSet = {
1: '.*://', // all
2: 'http://', // http
4: 'https://' // https
};

// move the start marker
let p = protocolSet[protocol]
if (pat[0] === '^') {
p = '^' + p;
pat = pat.subSting(1);

This comment has been minimized.

Copy link
@ericjung

ericjung Sep 25, 2023

Contributor

This should be subString not subSting. Did you test this before pushing the commit?

This comment has been minimized.

Copy link
@erosman

erosman Sep 25, 2023

Author Collaborator

Already noticed and fixed the typo.

}

// remove end marker
if (pat.endsWith('$')) {
pat = pat.slice(0, -1);
}

return p + pat + '/';
}
}
4 changes: 2 additions & 2 deletions src/content/on-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class OnRequest {
const isIP = /^[\d.:]+$/.test(host);

switch (true) {
case host === '::1':
case isIP && host.startsWith('::1:'): // with port
case host === '[::1]':
case host.startsWith('[::1:'): // with port
case host === '127.0.0.1':
case isIP && host.startsWith('127.'): // 127.0.0.1 up to 127.255.255.254
case !isIP && !host.includes('.'): // not IP & plain hostname (no dots)
Expand Down
2 changes: 1 addition & 1 deletion src/content/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

<!-- template -->
<template>
<details class="proxy">
<details class="proxy" draggable="true">
<summary>
<span>🌎</span>
<span></span>
Expand Down
29 changes: 29 additions & 0 deletions src/content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,35 @@ class Proxies {
}
// ---------- /Proxies -------------------------------------

// ---------- Drag and Drop --------------------------------
class Drag {

static {
this.proxyDiv = document.querySelector('div.proxyDiv');
this.x = 0;
this.elem = null;

this.proxyDiv.addEventListener('dragstart', e => this.dragstart(e));
this.proxyDiv.addEventListener('dragleave', e => this.dragleave(e));
}

static dragstart(e) {
this.x = e.x; // cache x value
this.elem = e.target.closest('details');
}

static dragleave(e) {
if (!e.x) { return; }

const target = e.target.closest('details');
if (!target) { return; }

e.x > this.x ? target.before(this.elem) : target.after(this.elem);
this.x = e.x;
}
}
// ---------- /Drag and Drop -------------------------------

// ---------- Import FP Account ----------------------------
class ImportFoxyProxyAccount {

Expand Down

1 comment on commit e19f4d9

@TriMoon
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning

It completely broke "Import from older versions"...
When i do it does nothing at all...

Please sign in to comment.