FelisCatus / SwitchyOmega

Manage and switch between multiple proxies quickly & easily.
GNU General Public License v3.0
21.37k stars 3.21k forks source link

Bulk Proxy Import #235

Open ghost opened 9 years ago

ghost commented 9 years ago

Is there bulk proxy import, either by way of magic snippets as in the below thread from proxyswitchy sharp or by a normal bulk import feature? I don't know if I should upgrade to the new one or not as I use the bulk import feature a lot.

https://code.google.com/p/switchysharp/issues/detail?id=887

Thanks!

FelisCatus commented 9 years ago

I'm going to provide the following magic snippet as a temporary solution.

var changes = {};
window.prompt().split(';').forEach(function (proxy, i) {
  var profile = OmegaPac.Profiles.create({
    name: "Proxy" + (i + 1),
    color: "#99ccee",
    profileType: "FixedProfile",
    fallbackProxy: OmegaPac.Profiles.parseHostPort(proxy.trim(), 'http'),
  });
  OmegaPac.Profiles.updateRevision(profile);
  changes[OmegaPac.Profiles.nameAsKey(profile)] = profile;
});
chrome.storage.local.set(changes, location.reload.bind(location));

As usual, to run this snippet, please press F12 (Cmd + Opt + I on Mac) on the options page. Then select the "Console" tab and paste the above snippet there. After you press enter, a little prompt window will popup. Please enter all your proxies there seperated by semi-colon (like 127.0.0.1:1234;127.0.0.1:5678 and so on). You may want to copy & paste since it would be a very long string. Press enter and your proxies would be there.

FelisCatus commented 9 years ago

Another way to do that would be importing a crafted backup file, as suggested by henderpa in the linked issue of the old version.

The backup file is in JSON format, and it won't be too hard to edit using text editors, provided that you have beautified the JSON.

Of course, JSON files are better to be edited and generated using programming languages. For example, the fragment containing your profiles can be printed by replacing the last line of the snippet with the following statement:

console.log(JSON.stringify(changes, null, 4));

The fragment can then be merged with an existing backup file. (By merging, I mean removing the out-most surrounding curly braces {} of both files, join them with comma , , and finally surround the result again with curly braces {}. Basically {AAAAA} + {BBBBB} => {AAAAA, BBBBB}.)

zamen40 commented 9 years ago

Ive been trying around to change the proxy list i can download to get into that format but i cant find how. The proxy list i download goes as follows: 0.0.0.0:port 0.0.0.0:port 0.0.0.0:port and so on. How can i change that to 0.0.0.0:port;0.0.0.0:port;0.0.0.0:port?

FelisCatus commented 9 years ago

@zamen40 Just use your text editor to replace the line breaks with semicolon. For example you can use vim to insert ";" at the end of each line :%s/$/;, and then join them together ggvGJ.

myrorym commented 9 years ago

nevermind, accessing JavaScript console different on Mac it seems

myrorym commented 9 years ago

Should this work for proxies with User/Pass authentication?

My format is IP:port:user:pass;

It's importing, but the formats are incorrect.

it's inputting the IP:port:user into the Server and nothing into the Authentication boxes.

FelisCatus commented 9 years ago

@myrorym Comment above edited to show the right shortcut for Dev Console on Mac, which should be Cmd + Opt + I by Google.

It is technically possible to add user/pass authentication, but it would take some time for me to enhance the magic snippet above. Stay tuned.

myrorym commented 9 years ago

computer-beagle_zpsd13aee58 Thanks, I'm tuned in.

FelisCatus commented 9 years ago

The following script should work for the host:port:user:pass format. Note: This won't work for IPv6 literals as host.

var changes = {};
window.prompt().split(';').forEach(function (proxy, i) {
  var parts = proxy.trim().split(':');
  if (parts.length < 2) return;
  var profile = OmegaPac.Profiles.create({
    name: "Proxy" + (i + 1),
    color: "#99ccee",
    profileType: "FixedProfile",
    fallbackProxy: OmegaPac.Profiles.parseHostPort(parts[0] + ':' + parts[1], 'http'),
    auth: parts[2] && {fallbackProxy: {
      username: parts[2],
      password: parts[3],
    }}
  });
  OmegaPac.Profiles.updateRevision(profile);
  changes[OmegaPac.Profiles.nameAsKey(profile)] = profile;
});
chrome.storage.local.set(changes, location.reload.bind(location));
ghost commented 9 years ago

Thanks!!!

One other issue, when i import a list of proxy ips in a particular order, when they get imported it automatically puts them in numerical order and takes them out of the order that I wanted them to make it easy for me to scroll through.

Is there a way to import them and preserve the order they were put into instead of always having them sorted numerically?

Thanks!!!

FelisCatus commented 9 years ago

@stlpro Really? I believe they are always ordered by their name, which should be "Proxy 1", "Proxy 2", ...etc. And the number should be based on the exact order that you input. Am I wrong?

ghost commented 9 years ago

Hmm, maybe I have to have a default profile set up first? They are just named by their ips, so they get ordered by number. How would I import them with names? On Mar 26, 2015 1:26 AM, "FelisCatus" notifications@github.com wrote:

@stlpro https://github.com/stlpro Really? I believe they are always ordered by their name, which should be "Proxy 1", "Proxy 2", ...etc. And the number should be based on the exact order that you input. Am I wrong?

— Reply to this email directly or view it on GitHub https://github.com/FelisCatus/SwitchyOmega/issues/235#issuecomment-86358895 .

FelisCatus commented 9 years ago

@stlpro Are you sure that you're using the snippet above? It doesn't require any default profile, and it creates profiles named like "Proxy 1". You can delete or reset your old, IP-named profiles and try importing again.